@atomic-solutions/woocommerce-react 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.
@@ -0,0 +1,187 @@
1
+ import { Cart, WooCommerceApiError, CartItem, Checkout, StoreApiOrder, ProductParams } from '@atomic-solutions/woocommerce-utils';
2
+
3
+ type WooCommerceEventType = 'cart:item_added' | 'cart:item_removed' | 'cart:item_updated' | 'cart:coupon_applied' | 'cart:coupon_removed' | 'cart:customer_updated' | 'cart:shipping_selected' | 'checkout:processed' | 'order:fetched';
4
+ interface BaseSuccessEvent<T extends WooCommerceEventType, D> {
5
+ type: T;
6
+ status: 'success';
7
+ data: D;
8
+ }
9
+ interface BaseErrorEvent<T extends WooCommerceEventType> {
10
+ type: T;
11
+ status: 'error';
12
+ error: WooCommerceApiError;
13
+ }
14
+ type CartItemAddedEvent = BaseSuccessEvent<'cart:item_added', {
15
+ item: CartItem;
16
+ cart: Cart;
17
+ }> | BaseErrorEvent<'cart:item_added'>;
18
+ type CartItemRemovedEvent = BaseSuccessEvent<'cart:item_removed', {
19
+ itemKey: string;
20
+ cart: Cart;
21
+ }> | BaseErrorEvent<'cart:item_removed'>;
22
+ type CartItemUpdatedEvent = BaseSuccessEvent<'cart:item_updated', {
23
+ item: CartItem;
24
+ cart: Cart;
25
+ }> | BaseErrorEvent<'cart:item_updated'>;
26
+ type CartCouponAppliedEvent = BaseSuccessEvent<'cart:coupon_applied', {
27
+ code: string;
28
+ cart: Cart;
29
+ }> | BaseErrorEvent<'cart:coupon_applied'>;
30
+ type CartCouponRemovedEvent = BaseSuccessEvent<'cart:coupon_removed', {
31
+ code: string;
32
+ cart: Cart;
33
+ }> | BaseErrorEvent<'cart:coupon_removed'>;
34
+ type CartCustomerUpdatedEvent = BaseSuccessEvent<'cart:customer_updated', {
35
+ cart: Cart;
36
+ }> | BaseErrorEvent<'cart:customer_updated'>;
37
+ type CartShippingSelectedEvent = BaseSuccessEvent<'cart:shipping_selected', {
38
+ cart: Cart;
39
+ }> | BaseErrorEvent<'cart:shipping_selected'>;
40
+ type CheckoutProcessedEvent = BaseSuccessEvent<'checkout:processed', {
41
+ checkout: Checkout;
42
+ }> | BaseErrorEvent<'checkout:processed'>;
43
+ type OrderFetchedEvent = BaseSuccessEvent<'order:fetched', {
44
+ order: StoreApiOrder;
45
+ }> | BaseErrorEvent<'order:fetched'>;
46
+ type WooCommerceEvent = CartItemAddedEvent | CartItemRemovedEvent | CartItemUpdatedEvent | CartCouponAppliedEvent | CartCouponRemovedEvent | CartCustomerUpdatedEvent | CartShippingSelectedEvent | CheckoutProcessedEvent | OrderFetchedEvent;
47
+ type WooCommerceEventHandler = (event: WooCommerceEvent) => void;
48
+
49
+ declare const createQueryKeys: (prefix?: string[]) => {
50
+ all: readonly string[];
51
+ products: {
52
+ all: readonly [...string[], "products"];
53
+ lists: () => readonly [...string[], "products", "list"];
54
+ list: (params?: ProductParams) => readonly [...string[], "products", "list", {
55
+ page: number;
56
+ per_page: number;
57
+ type?: "simple" | "grouped" | "external" | "variable" | "variation" | undefined;
58
+ status?: "pending" | "any" | "draft" | "private" | "publish" | undefined;
59
+ search?: string | undefined;
60
+ exclude?: number[] | undefined;
61
+ include?: number[] | undefined;
62
+ slug?: string | undefined;
63
+ rating?: number[] | undefined;
64
+ order?: "asc" | "desc" | undefined;
65
+ orderby?: "include" | "date" | "id" | "title" | "slug" | "popularity" | "rating" | "menu_order" | "price" | "date_modified" | undefined;
66
+ featured?: boolean | undefined;
67
+ category?: string | undefined;
68
+ tag?: string | undefined;
69
+ stock_status?: ("instock" | "outofstock" | "onbackorder")[] | undefined;
70
+ on_sale?: boolean | undefined;
71
+ min_price?: string | undefined;
72
+ max_price?: string | undefined;
73
+ after?: string | undefined;
74
+ before?: string | undefined;
75
+ modified_after?: string | undefined;
76
+ modified_before?: string | undefined;
77
+ catalog_visibility?: "search" | "any" | "visible" | "catalog" | "hidden" | undefined;
78
+ attributes?: {
79
+ attribute: string;
80
+ slug?: string[] | undefined;
81
+ term_id?: number[] | undefined;
82
+ operator?: "in" | "not_in" | "and" | undefined;
83
+ }[] | undefined;
84
+ parent?: number[] | undefined;
85
+ parent_exclude?: number[] | undefined;
86
+ category_operator?: "in" | "not_in" | "and" | undefined;
87
+ tag_operator?: "in" | "not_in" | "and" | undefined;
88
+ attribute_relation?: "in" | "and" | undefined;
89
+ } | undefined];
90
+ details: () => readonly [...string[], "products", "detail"];
91
+ detail: (id: number) => readonly [...string[], "products", "detail", number];
92
+ categories: () => readonly [...string[], "products", "categories"];
93
+ };
94
+ cart: {
95
+ all: readonly [...string[], "cart"];
96
+ details: () => readonly [...string[], "cart", "details"];
97
+ mutations: {
98
+ addItem: () => readonly [...string[], "cart", "mutation", "addItem"];
99
+ updateItem: () => readonly [...string[], "cart", "mutation", "updateItem"];
100
+ removeItem: () => readonly [...string[], "cart", "mutation", "removeItem"];
101
+ applyCoupon: () => readonly [...string[], "cart", "mutation", "applyCoupon"];
102
+ removeCoupon: () => readonly [...string[], "cart", "mutation", "removeCoupon"];
103
+ updateCustomer: () => readonly [...string[], "cart", "mutation", "updateCustomer"];
104
+ selectShippingRate: () => readonly [...string[], "cart", "mutation", "selectShippingRate"];
105
+ };
106
+ };
107
+ checkout: {
108
+ all: readonly [...string[], "checkout"];
109
+ details: () => readonly [...string[], "checkout", "details"];
110
+ mutations: {
111
+ process: () => readonly [...string[], "checkout", "mutation", "process"];
112
+ };
113
+ };
114
+ orders: {
115
+ all: readonly [...string[], "orders"];
116
+ lists: () => readonly [...string[], "orders", "list"];
117
+ list: (params?: Record<string, unknown>) => readonly [...string[], "orders", "list", Record<string, unknown> | undefined];
118
+ details: () => readonly [...string[], "orders", "detail"];
119
+ detail: (id: number, billing_email?: string, key?: string) => readonly (string | number)[];
120
+ };
121
+ };
122
+ type QueryKeys = ReturnType<typeof createQueryKeys>;
123
+
124
+ interface StoreFeatures {
125
+ auth?: boolean;
126
+ wishlist?: boolean;
127
+ reviews?: boolean;
128
+ search?: boolean;
129
+ categories?: boolean;
130
+ }
131
+ interface StoreTheme {
132
+ primary?: string;
133
+ secondary?: string;
134
+ mode?: 'light' | 'dark' | 'auto';
135
+ fonts?: {
136
+ heading?: string;
137
+ body?: string;
138
+ };
139
+ }
140
+ interface StoreLocale {
141
+ localeTag?: string;
142
+ currency?: string;
143
+ currencyPosition?: 'before' | 'after';
144
+ thousandsSeparator?: string;
145
+ decimalSeparator?: string;
146
+ decimals?: number;
147
+ }
148
+ type ImageUrlTransformer = (url: string, size: 'thumbnail' | 'medium' | 'large' | 'full') => string;
149
+ interface RateLimitConfig {
150
+ requestsPerMinute?: number;
151
+ requestsPerSecond?: number;
152
+ burstLimit?: number;
153
+ }
154
+ interface StoreGuardrails {
155
+ validateStore?: boolean;
156
+ rateLimit?: RateLimitConfig;
157
+ licenseKey?: string;
158
+ }
159
+ interface StoreValidationResult {
160
+ valid: boolean;
161
+ storeName?: string;
162
+ storeUrl?: string;
163
+ wcVersion?: string;
164
+ error?: string;
165
+ }
166
+ interface StoreConfig {
167
+ storeUrl: string;
168
+ features?: StoreFeatures;
169
+ theme?: StoreTheme;
170
+ locale?: StoreLocale;
171
+ guardrails?: StoreGuardrails;
172
+ onEvent?: WooCommerceEventHandler;
173
+ debug?: boolean;
174
+ imageUrlTransformer?: ImageUrlTransformer;
175
+ fallbackImageUrl?: string;
176
+ }
177
+ interface StoreContextValue {
178
+ config: StoreConfig;
179
+ isValidated: boolean;
180
+ isValidating: boolean;
181
+ validationError?: string;
182
+ validationResult?: StoreValidationResult;
183
+ revalidate: () => Promise<void>;
184
+ }
185
+ declare const DEFAULT_STORE_CONFIG: Required<Pick<StoreConfig, 'features' | 'locale' | 'guardrails' | 'debug'>>;
186
+
187
+ export { type CartCouponAppliedEvent as C, DEFAULT_STORE_CONFIG as D, type ImageUrlTransformer as I, type OrderFetchedEvent as O, type QueryKeys as Q, type RateLimitConfig as R, type StoreLocale as S, type WooCommerceEventHandler as W, type StoreValidationResult as a, type CartCouponRemovedEvent as b, type CartCustomerUpdatedEvent as c, type CartItemAddedEvent as d, type CartItemRemovedEvent as e, type CartItemUpdatedEvent as f, type CartShippingSelectedEvent as g, type CheckoutProcessedEvent as h, type StoreConfig as i, type StoreContextValue as j, type StoreFeatures as k, type StoreGuardrails as l, type StoreTheme as m, type WooCommerceEvent as n, type WooCommerceEventType as o, createQueryKeys as p };
@@ -0,0 +1,187 @@
1
+ import { Cart, WooCommerceApiError, CartItem, Checkout, StoreApiOrder, ProductParams } from '@atomic-solutions/woocommerce-utils';
2
+
3
+ type WooCommerceEventType = 'cart:item_added' | 'cart:item_removed' | 'cart:item_updated' | 'cart:coupon_applied' | 'cart:coupon_removed' | 'cart:customer_updated' | 'cart:shipping_selected' | 'checkout:processed' | 'order:fetched';
4
+ interface BaseSuccessEvent<T extends WooCommerceEventType, D> {
5
+ type: T;
6
+ status: 'success';
7
+ data: D;
8
+ }
9
+ interface BaseErrorEvent<T extends WooCommerceEventType> {
10
+ type: T;
11
+ status: 'error';
12
+ error: WooCommerceApiError;
13
+ }
14
+ type CartItemAddedEvent = BaseSuccessEvent<'cart:item_added', {
15
+ item: CartItem;
16
+ cart: Cart;
17
+ }> | BaseErrorEvent<'cart:item_added'>;
18
+ type CartItemRemovedEvent = BaseSuccessEvent<'cart:item_removed', {
19
+ itemKey: string;
20
+ cart: Cart;
21
+ }> | BaseErrorEvent<'cart:item_removed'>;
22
+ type CartItemUpdatedEvent = BaseSuccessEvent<'cart:item_updated', {
23
+ item: CartItem;
24
+ cart: Cart;
25
+ }> | BaseErrorEvent<'cart:item_updated'>;
26
+ type CartCouponAppliedEvent = BaseSuccessEvent<'cart:coupon_applied', {
27
+ code: string;
28
+ cart: Cart;
29
+ }> | BaseErrorEvent<'cart:coupon_applied'>;
30
+ type CartCouponRemovedEvent = BaseSuccessEvent<'cart:coupon_removed', {
31
+ code: string;
32
+ cart: Cart;
33
+ }> | BaseErrorEvent<'cart:coupon_removed'>;
34
+ type CartCustomerUpdatedEvent = BaseSuccessEvent<'cart:customer_updated', {
35
+ cart: Cart;
36
+ }> | BaseErrorEvent<'cart:customer_updated'>;
37
+ type CartShippingSelectedEvent = BaseSuccessEvent<'cart:shipping_selected', {
38
+ cart: Cart;
39
+ }> | BaseErrorEvent<'cart:shipping_selected'>;
40
+ type CheckoutProcessedEvent = BaseSuccessEvent<'checkout:processed', {
41
+ checkout: Checkout;
42
+ }> | BaseErrorEvent<'checkout:processed'>;
43
+ type OrderFetchedEvent = BaseSuccessEvent<'order:fetched', {
44
+ order: StoreApiOrder;
45
+ }> | BaseErrorEvent<'order:fetched'>;
46
+ type WooCommerceEvent = CartItemAddedEvent | CartItemRemovedEvent | CartItemUpdatedEvent | CartCouponAppliedEvent | CartCouponRemovedEvent | CartCustomerUpdatedEvent | CartShippingSelectedEvent | CheckoutProcessedEvent | OrderFetchedEvent;
47
+ type WooCommerceEventHandler = (event: WooCommerceEvent) => void;
48
+
49
+ declare const createQueryKeys: (prefix?: string[]) => {
50
+ all: readonly string[];
51
+ products: {
52
+ all: readonly [...string[], "products"];
53
+ lists: () => readonly [...string[], "products", "list"];
54
+ list: (params?: ProductParams) => readonly [...string[], "products", "list", {
55
+ page: number;
56
+ per_page: number;
57
+ type?: "simple" | "grouped" | "external" | "variable" | "variation" | undefined;
58
+ status?: "pending" | "any" | "draft" | "private" | "publish" | undefined;
59
+ search?: string | undefined;
60
+ exclude?: number[] | undefined;
61
+ include?: number[] | undefined;
62
+ slug?: string | undefined;
63
+ rating?: number[] | undefined;
64
+ order?: "asc" | "desc" | undefined;
65
+ orderby?: "include" | "date" | "id" | "title" | "slug" | "popularity" | "rating" | "menu_order" | "price" | "date_modified" | undefined;
66
+ featured?: boolean | undefined;
67
+ category?: string | undefined;
68
+ tag?: string | undefined;
69
+ stock_status?: ("instock" | "outofstock" | "onbackorder")[] | undefined;
70
+ on_sale?: boolean | undefined;
71
+ min_price?: string | undefined;
72
+ max_price?: string | undefined;
73
+ after?: string | undefined;
74
+ before?: string | undefined;
75
+ modified_after?: string | undefined;
76
+ modified_before?: string | undefined;
77
+ catalog_visibility?: "search" | "any" | "visible" | "catalog" | "hidden" | undefined;
78
+ attributes?: {
79
+ attribute: string;
80
+ slug?: string[] | undefined;
81
+ term_id?: number[] | undefined;
82
+ operator?: "in" | "not_in" | "and" | undefined;
83
+ }[] | undefined;
84
+ parent?: number[] | undefined;
85
+ parent_exclude?: number[] | undefined;
86
+ category_operator?: "in" | "not_in" | "and" | undefined;
87
+ tag_operator?: "in" | "not_in" | "and" | undefined;
88
+ attribute_relation?: "in" | "and" | undefined;
89
+ } | undefined];
90
+ details: () => readonly [...string[], "products", "detail"];
91
+ detail: (id: number) => readonly [...string[], "products", "detail", number];
92
+ categories: () => readonly [...string[], "products", "categories"];
93
+ };
94
+ cart: {
95
+ all: readonly [...string[], "cart"];
96
+ details: () => readonly [...string[], "cart", "details"];
97
+ mutations: {
98
+ addItem: () => readonly [...string[], "cart", "mutation", "addItem"];
99
+ updateItem: () => readonly [...string[], "cart", "mutation", "updateItem"];
100
+ removeItem: () => readonly [...string[], "cart", "mutation", "removeItem"];
101
+ applyCoupon: () => readonly [...string[], "cart", "mutation", "applyCoupon"];
102
+ removeCoupon: () => readonly [...string[], "cart", "mutation", "removeCoupon"];
103
+ updateCustomer: () => readonly [...string[], "cart", "mutation", "updateCustomer"];
104
+ selectShippingRate: () => readonly [...string[], "cart", "mutation", "selectShippingRate"];
105
+ };
106
+ };
107
+ checkout: {
108
+ all: readonly [...string[], "checkout"];
109
+ details: () => readonly [...string[], "checkout", "details"];
110
+ mutations: {
111
+ process: () => readonly [...string[], "checkout", "mutation", "process"];
112
+ };
113
+ };
114
+ orders: {
115
+ all: readonly [...string[], "orders"];
116
+ lists: () => readonly [...string[], "orders", "list"];
117
+ list: (params?: Record<string, unknown>) => readonly [...string[], "orders", "list", Record<string, unknown> | undefined];
118
+ details: () => readonly [...string[], "orders", "detail"];
119
+ detail: (id: number, billing_email?: string, key?: string) => readonly (string | number)[];
120
+ };
121
+ };
122
+ type QueryKeys = ReturnType<typeof createQueryKeys>;
123
+
124
+ interface StoreFeatures {
125
+ auth?: boolean;
126
+ wishlist?: boolean;
127
+ reviews?: boolean;
128
+ search?: boolean;
129
+ categories?: boolean;
130
+ }
131
+ interface StoreTheme {
132
+ primary?: string;
133
+ secondary?: string;
134
+ mode?: 'light' | 'dark' | 'auto';
135
+ fonts?: {
136
+ heading?: string;
137
+ body?: string;
138
+ };
139
+ }
140
+ interface StoreLocale {
141
+ localeTag?: string;
142
+ currency?: string;
143
+ currencyPosition?: 'before' | 'after';
144
+ thousandsSeparator?: string;
145
+ decimalSeparator?: string;
146
+ decimals?: number;
147
+ }
148
+ type ImageUrlTransformer = (url: string, size: 'thumbnail' | 'medium' | 'large' | 'full') => string;
149
+ interface RateLimitConfig {
150
+ requestsPerMinute?: number;
151
+ requestsPerSecond?: number;
152
+ burstLimit?: number;
153
+ }
154
+ interface StoreGuardrails {
155
+ validateStore?: boolean;
156
+ rateLimit?: RateLimitConfig;
157
+ licenseKey?: string;
158
+ }
159
+ interface StoreValidationResult {
160
+ valid: boolean;
161
+ storeName?: string;
162
+ storeUrl?: string;
163
+ wcVersion?: string;
164
+ error?: string;
165
+ }
166
+ interface StoreConfig {
167
+ storeUrl: string;
168
+ features?: StoreFeatures;
169
+ theme?: StoreTheme;
170
+ locale?: StoreLocale;
171
+ guardrails?: StoreGuardrails;
172
+ onEvent?: WooCommerceEventHandler;
173
+ debug?: boolean;
174
+ imageUrlTransformer?: ImageUrlTransformer;
175
+ fallbackImageUrl?: string;
176
+ }
177
+ interface StoreContextValue {
178
+ config: StoreConfig;
179
+ isValidated: boolean;
180
+ isValidating: boolean;
181
+ validationError?: string;
182
+ validationResult?: StoreValidationResult;
183
+ revalidate: () => Promise<void>;
184
+ }
185
+ declare const DEFAULT_STORE_CONFIG: Required<Pick<StoreConfig, 'features' | 'locale' | 'guardrails' | 'debug'>>;
186
+
187
+ export { type CartCouponAppliedEvent as C, DEFAULT_STORE_CONFIG as D, type ImageUrlTransformer as I, type OrderFetchedEvent as O, type QueryKeys as Q, type RateLimitConfig as R, type StoreLocale as S, type WooCommerceEventHandler as W, type StoreValidationResult as a, type CartCouponRemovedEvent as b, type CartCustomerUpdatedEvent as c, type CartItemAddedEvent as d, type CartItemRemovedEvent as e, type CartItemUpdatedEvent as f, type CartShippingSelectedEvent as g, type CheckoutProcessedEvent as h, type StoreConfig as i, type StoreContextValue as j, type StoreFeatures as k, type StoreGuardrails as l, type StoreTheme as m, type WooCommerceEvent as n, type WooCommerceEventType as o, createQueryKeys as p };
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@atomic-solutions/woocommerce-react",
3
+ "version": "0.1.0",
4
+ "description": "React Query hooks and provider for WooCommerce Store API",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./hooks": {
15
+ "types": "./dist/hooks/index.d.ts",
16
+ "import": "./dist/hooks/index.js",
17
+ "require": "./dist/hooks/index.cjs"
18
+ },
19
+ "./provider": {
20
+ "types": "./dist/provider/index.d.ts",
21
+ "import": "./dist/provider/index.js",
22
+ "require": "./dist/provider/index.cjs"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "README.md",
29
+ "LICENSE"
30
+ ],
31
+ "keywords": [
32
+ "woocommerce",
33
+ "react",
34
+ "react-query",
35
+ "hooks",
36
+ "typescript"
37
+ ],
38
+ "author": "Atomic Solutions",
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/atomic-solutions/wordpress-woocommerce-monorepo",
43
+ "directory": "packages/react-woocommerce"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "dependencies": {
49
+ "@atomic-solutions/woocommerce-api-client": "0.1.0"
50
+ },
51
+ "peerDependencies": {
52
+ "@tanstack/react-query": ">=5.0.0",
53
+ "react": ">=18.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "@ianvs/prettier-plugin-sort-imports": "^4.7.0",
57
+ "@tanstack/react-query": "^5.59.19",
58
+ "@testing-library/react": "^14.0.0",
59
+ "@types/node": "^24.10.1",
60
+ "@types/react": "^18.0.0",
61
+ "@types/react-dom": "^18.0.0",
62
+ "@typescript-eslint/eslint-plugin": "^8.56.1",
63
+ "@typescript-eslint/parser": "^8.56.1",
64
+ "@vitest/coverage-v8": "^2.0.0",
65
+ "eslint": "^9.35.0",
66
+ "eslint-config-prettier": "^10.1.8",
67
+ "eslint-plugin-jsx-a11y": "^6.10.2",
68
+ "eslint-plugin-prettier": "^5.5.4",
69
+ "eslint-plugin-react": "^7.37.5",
70
+ "eslint-plugin-react-hooks": "^5.2.0",
71
+ "happy-dom": "^20.0.10",
72
+ "jsdom": "^27.2.0",
73
+ "prettier": "^3.0.0",
74
+ "react": "^18.0.0",
75
+ "react-dom": "^18.0.0",
76
+ "release-it": "^19.0.6",
77
+ "tsup": "^8.0.0",
78
+ "typescript": "^5.9.0",
79
+ "vitest": "^2.0.0"
80
+ },
81
+ "sideEffects": false,
82
+ "scripts": {
83
+ "build": "tsup",
84
+ "dev": "tsup --watch",
85
+ "typecheck": "tsc --noEmit",
86
+ "lint": "eslint src --ext .ts,.tsx",
87
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
88
+ "test": "vitest run",
89
+ "test:watch": "vitest",
90
+ "test:coverage": "vitest run --coverage",
91
+ "clean": "rm -rf dist"
92
+ }
93
+ }