@atomic-solutions/woocommerce-api-client 0.4.0 → 0.5.1
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/client/index.d.mts +3 -2
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.js +156 -50
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +157 -51
- package/dist/client/index.mjs.map +1 -1
- package/dist/http/index.d.mts +3 -2
- package/dist/http/index.d.ts +3 -2
- package/dist/http/index.js +88 -48
- package/dist/http/index.js.map +1 -1
- package/dist/http/index.mjs +89 -50
- package/dist/http/index.mjs.map +1 -1
- package/dist/index.d.mts +23 -13
- package/dist/index.d.ts +23 -13
- package/dist/index.js +163 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +162 -51
- package/dist/index.mjs.map +1 -1
- package/dist/testing/index.d.mts +2 -1
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.js +156 -50
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/index.mjs +157 -51
- package/dist/testing/index.mjs.map +1 -1
- package/dist/{types-BF4_UUqp.d.mts → types-9I6oS_83.d.mts} +105 -23
- package/dist/{types-BF4_UUqp.d.ts → types-9I6oS_83.d.ts} +105 -23
- package/dist/utils/index.d.mts +3 -2
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +11 -10
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +11 -10
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +3 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AxiosResponse, AxiosInstance, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { BaseError } from '@atomic-solutions/errors';
|
|
2
3
|
import { ZodError, ZodSchema, z } from 'zod';
|
|
3
4
|
|
|
4
5
|
type WooCommerceApiErrorCode = 'cart_empty' | 'invalid_coupon' | 'missing_nonce' | 'invalid_nonce' | 'invalid_params' | 'product_not_found' | 'out_of_stock' | 'insufficient_stock' | 'invalid_payment_method' | 'checkout_error' | 'network_error' | 'unknown_error';
|
|
@@ -18,7 +19,7 @@ interface BaseReportableData {
|
|
|
18
19
|
retryable?: boolean;
|
|
19
20
|
}
|
|
20
21
|
interface HttpErrorFields {
|
|
21
|
-
statusCode
|
|
22
|
+
statusCode?: number;
|
|
22
23
|
url: string;
|
|
23
24
|
method: string;
|
|
24
25
|
requestBody?: unknown;
|
|
@@ -29,13 +30,6 @@ interface WooCommerceApiErrorOptions extends BaseErrorOptions, HttpErrorFields {
|
|
|
29
30
|
originalCode: string;
|
|
30
31
|
data?: Record<string, unknown>;
|
|
31
32
|
}
|
|
32
|
-
interface ApiReportableData extends BaseReportableData {
|
|
33
|
-
statusCode: number;
|
|
34
|
-
url: string;
|
|
35
|
-
method: string;
|
|
36
|
-
wooCode: WooCommerceApiErrorCode;
|
|
37
|
-
originalCode: string;
|
|
38
|
-
}
|
|
39
33
|
interface WooCommerceDataValidationErrorOptions extends Omit<BaseErrorOptions, 'code' | 'retryable'> {
|
|
40
34
|
url?: string;
|
|
41
35
|
zodError?: ZodError;
|
|
@@ -46,24 +40,18 @@ interface ValidationReportableData extends BaseReportableData {
|
|
|
46
40
|
url?: string;
|
|
47
41
|
}
|
|
48
42
|
|
|
49
|
-
declare class
|
|
50
|
-
|
|
51
|
-
constructor(options: TOptions);
|
|
52
|
-
getReportableData(): TReportable;
|
|
53
|
-
toJSON(): Record<string, unknown>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
declare class WooCommerceApiError extends BaseError<WooCommerceApiErrorOptions, ApiReportableData> {
|
|
43
|
+
declare class WooCommerceApiError extends BaseError {
|
|
44
|
+
#private;
|
|
57
45
|
constructor(options: WooCommerceApiErrorOptions);
|
|
46
|
+
get options(): WooCommerceApiErrorOptions;
|
|
58
47
|
get wooCode(): WooCommerceApiErrorCode;
|
|
59
48
|
get originalCode(): string;
|
|
60
|
-
get statusCode(): number;
|
|
49
|
+
get statusCode(): number | undefined;
|
|
61
50
|
get url(): string;
|
|
62
51
|
get method(): string;
|
|
63
52
|
get requestBody(): unknown | undefined;
|
|
64
53
|
get responseBody(): unknown | undefined;
|
|
65
54
|
get data(): Record<string, unknown> | undefined;
|
|
66
|
-
getReportableData(): ApiReportableData;
|
|
67
55
|
}
|
|
68
56
|
|
|
69
57
|
type ValidationMode = 'strict' | 'warn';
|
|
@@ -72,6 +60,7 @@ interface ResponseOptions {
|
|
|
72
60
|
errorReporter?: (error: Error) => void;
|
|
73
61
|
onValidationError?: (error: Error) => void;
|
|
74
62
|
}
|
|
63
|
+
declare const handleApiData: <T>(data: unknown, schema: ZodSchema<T>, options?: ResponseOptions, url?: string) => T;
|
|
75
64
|
declare const handleApiResponse: <T>(response: AxiosResponse, schema: ZodSchema<T>, options?: ResponseOptions) => T;
|
|
76
65
|
declare const isZodError: (error: unknown) => error is ZodError;
|
|
77
66
|
|
|
@@ -1641,6 +1630,81 @@ declare const addToCartInputSchema: z.ZodObject<{
|
|
|
1641
1630
|
attribute: string;
|
|
1642
1631
|
}[] | undefined;
|
|
1643
1632
|
}>;
|
|
1633
|
+
declare const addItemsInputSchema: z.ZodObject<{
|
|
1634
|
+
items: z.ZodArray<z.ZodObject<{
|
|
1635
|
+
id: z.ZodNumber;
|
|
1636
|
+
quantity: z.ZodNumber;
|
|
1637
|
+
variation: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1638
|
+
attribute: z.ZodString;
|
|
1639
|
+
value: z.ZodString;
|
|
1640
|
+
}, "strip", z.ZodTypeAny, {
|
|
1641
|
+
value: string;
|
|
1642
|
+
attribute: string;
|
|
1643
|
+
}, {
|
|
1644
|
+
value: string;
|
|
1645
|
+
attribute: string;
|
|
1646
|
+
}>, "many">>;
|
|
1647
|
+
}, "strip", z.ZodTypeAny, {
|
|
1648
|
+
id: number;
|
|
1649
|
+
quantity: number;
|
|
1650
|
+
variation?: {
|
|
1651
|
+
value: string;
|
|
1652
|
+
attribute: string;
|
|
1653
|
+
}[] | undefined;
|
|
1654
|
+
}, {
|
|
1655
|
+
id: number;
|
|
1656
|
+
quantity: number;
|
|
1657
|
+
variation?: {
|
|
1658
|
+
value: string;
|
|
1659
|
+
attribute: string;
|
|
1660
|
+
}[] | undefined;
|
|
1661
|
+
}>, "many">;
|
|
1662
|
+
}, "strip", z.ZodTypeAny, {
|
|
1663
|
+
items: {
|
|
1664
|
+
id: number;
|
|
1665
|
+
quantity: number;
|
|
1666
|
+
variation?: {
|
|
1667
|
+
value: string;
|
|
1668
|
+
attribute: string;
|
|
1669
|
+
}[] | undefined;
|
|
1670
|
+
}[];
|
|
1671
|
+
}, {
|
|
1672
|
+
items: {
|
|
1673
|
+
id: number;
|
|
1674
|
+
quantity: number;
|
|
1675
|
+
variation?: {
|
|
1676
|
+
value: string;
|
|
1677
|
+
attribute: string;
|
|
1678
|
+
}[] | undefined;
|
|
1679
|
+
}[];
|
|
1680
|
+
}>;
|
|
1681
|
+
declare const batchResponseSchema: z.ZodObject<{
|
|
1682
|
+
responses: z.ZodArray<z.ZodObject<{
|
|
1683
|
+
status: z.ZodNumber;
|
|
1684
|
+
body: z.ZodUnknown;
|
|
1685
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1686
|
+
}, "strip", z.ZodTypeAny, {
|
|
1687
|
+
status: number;
|
|
1688
|
+
headers?: Record<string, unknown> | undefined;
|
|
1689
|
+
body?: unknown;
|
|
1690
|
+
}, {
|
|
1691
|
+
status: number;
|
|
1692
|
+
headers?: Record<string, unknown> | undefined;
|
|
1693
|
+
body?: unknown;
|
|
1694
|
+
}>, "many">;
|
|
1695
|
+
}, "strip", z.ZodTypeAny, {
|
|
1696
|
+
responses: {
|
|
1697
|
+
status: number;
|
|
1698
|
+
headers?: Record<string, unknown> | undefined;
|
|
1699
|
+
body?: unknown;
|
|
1700
|
+
}[];
|
|
1701
|
+
}, {
|
|
1702
|
+
responses: {
|
|
1703
|
+
status: number;
|
|
1704
|
+
headers?: Record<string, unknown> | undefined;
|
|
1705
|
+
body?: unknown;
|
|
1706
|
+
}[];
|
|
1707
|
+
}>;
|
|
1644
1708
|
declare const updateCartItemInputSchema: z.ZodObject<{
|
|
1645
1709
|
key: z.ZodString;
|
|
1646
1710
|
quantity: z.ZodNumber;
|
|
@@ -1803,6 +1867,8 @@ declare const selectShippingRateInputSchema: z.ZodObject<{
|
|
|
1803
1867
|
type Cart = z.infer<typeof cartSchema>;
|
|
1804
1868
|
type CartItem = z.infer<typeof cartItemSchema>;
|
|
1805
1869
|
type AddToCartInput = z.infer<typeof addToCartInputSchema>;
|
|
1870
|
+
type AddItemsInput = z.infer<typeof addItemsInputSchema>;
|
|
1871
|
+
type BatchResponse = z.infer<typeof batchResponseSchema>;
|
|
1806
1872
|
type UpdateCartItemInput = z.infer<typeof updateCartItemInputSchema>;
|
|
1807
1873
|
type RemoveCartItemInput = z.infer<typeof removeCartItemInputSchema>;
|
|
1808
1874
|
type CouponInput = z.infer<typeof couponInputSchema>;
|
|
@@ -2893,12 +2959,14 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2893
2959
|
order: z.ZodOptional<z.ZodEnum<["asc", "desc"]>>;
|
|
2894
2960
|
search: z.ZodOptional<z.ZodString>;
|
|
2895
2961
|
slug: z.ZodOptional<z.ZodString>;
|
|
2962
|
+
sku: z.ZodOptional<z.ZodString>;
|
|
2896
2963
|
after: z.ZodOptional<z.ZodString>;
|
|
2897
2964
|
before: z.ZodOptional<z.ZodString>;
|
|
2898
2965
|
modified_after: z.ZodOptional<z.ZodString>;
|
|
2899
2966
|
modified_before: z.ZodOptional<z.ZodString>;
|
|
2900
2967
|
include: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
2901
2968
|
exclude: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
2969
|
+
related: z.ZodOptional<z.ZodNumber>;
|
|
2902
2970
|
parent: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
2903
2971
|
parent_exclude: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
2904
2972
|
type: z.ZodOptional<z.ZodEnum<["simple", "grouped", "external", "variable", "variation"]>>;
|
|
@@ -2938,6 +3006,7 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2938
3006
|
status?: "pending" | "any" | "draft" | "private" | "publish" | undefined;
|
|
2939
3007
|
order?: "asc" | "desc" | undefined;
|
|
2940
3008
|
orderby?: "id" | "price" | "date" | "slug" | "menu_order" | "include" | "title" | "popularity" | "rating" | "date_modified" | undefined;
|
|
3009
|
+
sku?: string | undefined;
|
|
2941
3010
|
catalog_visibility?: "search" | "any" | "visible" | "catalog" | "hidden" | undefined;
|
|
2942
3011
|
slug?: string | undefined;
|
|
2943
3012
|
parent?: number[] | undefined;
|
|
@@ -2949,6 +3018,7 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2949
3018
|
modified_after?: string | undefined;
|
|
2950
3019
|
modified_before?: string | undefined;
|
|
2951
3020
|
exclude?: number[] | undefined;
|
|
3021
|
+
related?: number | undefined;
|
|
2952
3022
|
parent_exclude?: number[] | undefined;
|
|
2953
3023
|
featured?: boolean | undefined;
|
|
2954
3024
|
stock_status?: ("instock" | "outofstock" | "onbackorder")[] | undefined;
|
|
@@ -2973,6 +3043,7 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2973
3043
|
per_page?: number | undefined;
|
|
2974
3044
|
order?: "asc" | "desc" | undefined;
|
|
2975
3045
|
orderby?: "id" | "price" | "date" | "slug" | "menu_order" | "include" | "title" | "popularity" | "rating" | "date_modified" | undefined;
|
|
3046
|
+
sku?: string | undefined;
|
|
2976
3047
|
catalog_visibility?: "search" | "any" | "visible" | "catalog" | "hidden" | undefined;
|
|
2977
3048
|
slug?: string | undefined;
|
|
2978
3049
|
parent?: number[] | undefined;
|
|
@@ -2984,6 +3055,7 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2984
3055
|
modified_after?: string | undefined;
|
|
2985
3056
|
modified_before?: string | undefined;
|
|
2986
3057
|
exclude?: number[] | undefined;
|
|
3058
|
+
related?: number | undefined;
|
|
2987
3059
|
parent_exclude?: number[] | undefined;
|
|
2988
3060
|
featured?: boolean | undefined;
|
|
2989
3061
|
stock_status?: ("instock" | "outofstock" | "onbackorder")[] | undefined;
|
|
@@ -3026,16 +3098,16 @@ declare const productSchema: z.ZodObject<{
|
|
|
3026
3098
|
text: z.ZodString;
|
|
3027
3099
|
url: z.ZodString;
|
|
3028
3100
|
}, "strip", z.ZodTypeAny, {
|
|
3029
|
-
text: string;
|
|
3030
3101
|
minimum: number;
|
|
3031
3102
|
maximum: number;
|
|
3103
|
+
text: string;
|
|
3032
3104
|
multiple_of: number;
|
|
3033
3105
|
description: string;
|
|
3034
3106
|
url: string;
|
|
3035
3107
|
}, {
|
|
3036
|
-
text: string;
|
|
3037
3108
|
minimum: number;
|
|
3038
3109
|
maximum: number;
|
|
3110
|
+
text: string;
|
|
3039
3111
|
multiple_of: number;
|
|
3040
3112
|
description: string;
|
|
3041
3113
|
url: string;
|
|
@@ -3232,9 +3304,9 @@ declare const productSchema: z.ZodObject<{
|
|
|
3232
3304
|
extensions: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
3233
3305
|
}, "strip", z.ZodTypeAny, {
|
|
3234
3306
|
add_to_cart: {
|
|
3235
|
-
text: string;
|
|
3236
3307
|
minimum: number;
|
|
3237
3308
|
maximum: number;
|
|
3309
|
+
text: string;
|
|
3238
3310
|
multiple_of: number;
|
|
3239
3311
|
description: string;
|
|
3240
3312
|
url: string;
|
|
@@ -3316,9 +3388,9 @@ declare const productSchema: z.ZodObject<{
|
|
|
3316
3388
|
review_count: number;
|
|
3317
3389
|
}, {
|
|
3318
3390
|
add_to_cart: {
|
|
3319
|
-
text: string;
|
|
3320
3391
|
minimum: number;
|
|
3321
3392
|
maximum: number;
|
|
3393
|
+
text: string;
|
|
3322
3394
|
multiple_of: number;
|
|
3323
3395
|
description: string;
|
|
3324
3396
|
url: string;
|
|
@@ -3459,9 +3531,19 @@ interface ProductsAPI {
|
|
|
3459
3531
|
get: (id: number) => Promise<Product>;
|
|
3460
3532
|
categories: () => Promise<ProductCategory[]>;
|
|
3461
3533
|
}
|
|
3534
|
+
interface AddItemsResult {
|
|
3535
|
+
cart: Cart;
|
|
3536
|
+
results: {
|
|
3537
|
+
item: AddToCartInput;
|
|
3538
|
+
status: number;
|
|
3539
|
+
code?: string;
|
|
3540
|
+
message?: string;
|
|
3541
|
+
}[];
|
|
3542
|
+
}
|
|
3462
3543
|
interface CartAPI {
|
|
3463
3544
|
get: () => Promise<Cart>;
|
|
3464
3545
|
addItem: (input: AddToCartInput) => Promise<Cart>;
|
|
3546
|
+
addItems: (input: AddItemsInput) => Promise<AddItemsResult>;
|
|
3465
3547
|
updateItem: (input: UpdateCartItemInput) => Promise<Cart>;
|
|
3466
3548
|
removeItem: (input: RemoveCartItemInput) => Promise<Cart>;
|
|
3467
3549
|
applyCoupon: (input: CouponInput) => Promise<Cart>;
|
|
@@ -3490,4 +3572,4 @@ interface WooCommerceClient {
|
|
|
3490
3572
|
orders: OrdersAPI;
|
|
3491
3573
|
}
|
|
3492
3574
|
|
|
3493
|
-
export {
|
|
3575
|
+
export { checkoutSchema as $, type AddItemsInput as A, type BaseErrorOptions as B, type CartHeadersAdapter as C, type ProductImage as D, type ProductParams as E, type ProductsAPI as F, type GetOrderInput as G, type RemoveCartItemInput as H, type SelectShippingRateInput as I, type JwtTokenAdapter as J, type StoreApiOrder as K, type UpdateCustomerInput as L, WooCommerceApiError as M, type WooCommerceApiErrorOptions as N, type OrderStatus as O, type PaginatedResponse as P, addItemsInputSchema as Q, type ResponseOptions as R, type StoreApiVersion as S, addToCartInputSchema as T, type UpdateCartItemInput as U, type ValidationMode as V, type WooCommerceConfig as W, batchResponseSchema as X, cartItemImageSchema as Y, cartSchema as Z, checkoutInputSchema as _, type WooCommerceClient as a, couponInputSchema as a0, productCategorySchema as a1, productImageSchema as a2, productSchema as a3, removeCartItemInputSchema as a4, storeProductsSearchParamsSchema as a5, selectShippingRateInputSchema as a6, storeApiOrderSchema as a7, updateCartItemInputSchema as a8, updateCustomerInputSchema as a9, handleApiResponse as b, handlePaginatedApiResponse as c, type Pagination as d, calculatePagination as e, type WooCommerceApiErrorCode as f, type BaseReportableData as g, handleApiData as h, isZodError as i, type ValidationReportableData as j, type WooCommerceDataValidationErrorOptions as k, type AddItemsResult as l, type AddToCartInput as m, type BatchResponse as n, type Cart as o, type CartAPI as p, type CartItem as q, type CartItemImage as r, setupErrorInterceptor as s, type Checkout as t, type CheckoutAPI as u, type CheckoutInput as v, type CouponInput as w, type OrdersAPI as x, type Product as y, type ProductCategory as z };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AxiosResponse, AxiosInstance, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { BaseError } from '@atomic-solutions/errors';
|
|
2
3
|
import { ZodError, ZodSchema, z } from 'zod';
|
|
3
4
|
|
|
4
5
|
type WooCommerceApiErrorCode = 'cart_empty' | 'invalid_coupon' | 'missing_nonce' | 'invalid_nonce' | 'invalid_params' | 'product_not_found' | 'out_of_stock' | 'insufficient_stock' | 'invalid_payment_method' | 'checkout_error' | 'network_error' | 'unknown_error';
|
|
@@ -18,7 +19,7 @@ interface BaseReportableData {
|
|
|
18
19
|
retryable?: boolean;
|
|
19
20
|
}
|
|
20
21
|
interface HttpErrorFields {
|
|
21
|
-
statusCode
|
|
22
|
+
statusCode?: number;
|
|
22
23
|
url: string;
|
|
23
24
|
method: string;
|
|
24
25
|
requestBody?: unknown;
|
|
@@ -29,13 +30,6 @@ interface WooCommerceApiErrorOptions extends BaseErrorOptions, HttpErrorFields {
|
|
|
29
30
|
originalCode: string;
|
|
30
31
|
data?: Record<string, unknown>;
|
|
31
32
|
}
|
|
32
|
-
interface ApiReportableData extends BaseReportableData {
|
|
33
|
-
statusCode: number;
|
|
34
|
-
url: string;
|
|
35
|
-
method: string;
|
|
36
|
-
wooCode: WooCommerceApiErrorCode;
|
|
37
|
-
originalCode: string;
|
|
38
|
-
}
|
|
39
33
|
interface WooCommerceDataValidationErrorOptions extends Omit<BaseErrorOptions, 'code' | 'retryable'> {
|
|
40
34
|
url?: string;
|
|
41
35
|
zodError?: ZodError;
|
|
@@ -46,24 +40,18 @@ interface ValidationReportableData extends BaseReportableData {
|
|
|
46
40
|
url?: string;
|
|
47
41
|
}
|
|
48
42
|
|
|
49
|
-
declare class
|
|
50
|
-
|
|
51
|
-
constructor(options: TOptions);
|
|
52
|
-
getReportableData(): TReportable;
|
|
53
|
-
toJSON(): Record<string, unknown>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
declare class WooCommerceApiError extends BaseError<WooCommerceApiErrorOptions, ApiReportableData> {
|
|
43
|
+
declare class WooCommerceApiError extends BaseError {
|
|
44
|
+
#private;
|
|
57
45
|
constructor(options: WooCommerceApiErrorOptions);
|
|
46
|
+
get options(): WooCommerceApiErrorOptions;
|
|
58
47
|
get wooCode(): WooCommerceApiErrorCode;
|
|
59
48
|
get originalCode(): string;
|
|
60
|
-
get statusCode(): number;
|
|
49
|
+
get statusCode(): number | undefined;
|
|
61
50
|
get url(): string;
|
|
62
51
|
get method(): string;
|
|
63
52
|
get requestBody(): unknown | undefined;
|
|
64
53
|
get responseBody(): unknown | undefined;
|
|
65
54
|
get data(): Record<string, unknown> | undefined;
|
|
66
|
-
getReportableData(): ApiReportableData;
|
|
67
55
|
}
|
|
68
56
|
|
|
69
57
|
type ValidationMode = 'strict' | 'warn';
|
|
@@ -72,6 +60,7 @@ interface ResponseOptions {
|
|
|
72
60
|
errorReporter?: (error: Error) => void;
|
|
73
61
|
onValidationError?: (error: Error) => void;
|
|
74
62
|
}
|
|
63
|
+
declare const handleApiData: <T>(data: unknown, schema: ZodSchema<T>, options?: ResponseOptions, url?: string) => T;
|
|
75
64
|
declare const handleApiResponse: <T>(response: AxiosResponse, schema: ZodSchema<T>, options?: ResponseOptions) => T;
|
|
76
65
|
declare const isZodError: (error: unknown) => error is ZodError;
|
|
77
66
|
|
|
@@ -1641,6 +1630,81 @@ declare const addToCartInputSchema: z.ZodObject<{
|
|
|
1641
1630
|
attribute: string;
|
|
1642
1631
|
}[] | undefined;
|
|
1643
1632
|
}>;
|
|
1633
|
+
declare const addItemsInputSchema: z.ZodObject<{
|
|
1634
|
+
items: z.ZodArray<z.ZodObject<{
|
|
1635
|
+
id: z.ZodNumber;
|
|
1636
|
+
quantity: z.ZodNumber;
|
|
1637
|
+
variation: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1638
|
+
attribute: z.ZodString;
|
|
1639
|
+
value: z.ZodString;
|
|
1640
|
+
}, "strip", z.ZodTypeAny, {
|
|
1641
|
+
value: string;
|
|
1642
|
+
attribute: string;
|
|
1643
|
+
}, {
|
|
1644
|
+
value: string;
|
|
1645
|
+
attribute: string;
|
|
1646
|
+
}>, "many">>;
|
|
1647
|
+
}, "strip", z.ZodTypeAny, {
|
|
1648
|
+
id: number;
|
|
1649
|
+
quantity: number;
|
|
1650
|
+
variation?: {
|
|
1651
|
+
value: string;
|
|
1652
|
+
attribute: string;
|
|
1653
|
+
}[] | undefined;
|
|
1654
|
+
}, {
|
|
1655
|
+
id: number;
|
|
1656
|
+
quantity: number;
|
|
1657
|
+
variation?: {
|
|
1658
|
+
value: string;
|
|
1659
|
+
attribute: string;
|
|
1660
|
+
}[] | undefined;
|
|
1661
|
+
}>, "many">;
|
|
1662
|
+
}, "strip", z.ZodTypeAny, {
|
|
1663
|
+
items: {
|
|
1664
|
+
id: number;
|
|
1665
|
+
quantity: number;
|
|
1666
|
+
variation?: {
|
|
1667
|
+
value: string;
|
|
1668
|
+
attribute: string;
|
|
1669
|
+
}[] | undefined;
|
|
1670
|
+
}[];
|
|
1671
|
+
}, {
|
|
1672
|
+
items: {
|
|
1673
|
+
id: number;
|
|
1674
|
+
quantity: number;
|
|
1675
|
+
variation?: {
|
|
1676
|
+
value: string;
|
|
1677
|
+
attribute: string;
|
|
1678
|
+
}[] | undefined;
|
|
1679
|
+
}[];
|
|
1680
|
+
}>;
|
|
1681
|
+
declare const batchResponseSchema: z.ZodObject<{
|
|
1682
|
+
responses: z.ZodArray<z.ZodObject<{
|
|
1683
|
+
status: z.ZodNumber;
|
|
1684
|
+
body: z.ZodUnknown;
|
|
1685
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1686
|
+
}, "strip", z.ZodTypeAny, {
|
|
1687
|
+
status: number;
|
|
1688
|
+
headers?: Record<string, unknown> | undefined;
|
|
1689
|
+
body?: unknown;
|
|
1690
|
+
}, {
|
|
1691
|
+
status: number;
|
|
1692
|
+
headers?: Record<string, unknown> | undefined;
|
|
1693
|
+
body?: unknown;
|
|
1694
|
+
}>, "many">;
|
|
1695
|
+
}, "strip", z.ZodTypeAny, {
|
|
1696
|
+
responses: {
|
|
1697
|
+
status: number;
|
|
1698
|
+
headers?: Record<string, unknown> | undefined;
|
|
1699
|
+
body?: unknown;
|
|
1700
|
+
}[];
|
|
1701
|
+
}, {
|
|
1702
|
+
responses: {
|
|
1703
|
+
status: number;
|
|
1704
|
+
headers?: Record<string, unknown> | undefined;
|
|
1705
|
+
body?: unknown;
|
|
1706
|
+
}[];
|
|
1707
|
+
}>;
|
|
1644
1708
|
declare const updateCartItemInputSchema: z.ZodObject<{
|
|
1645
1709
|
key: z.ZodString;
|
|
1646
1710
|
quantity: z.ZodNumber;
|
|
@@ -1803,6 +1867,8 @@ declare const selectShippingRateInputSchema: z.ZodObject<{
|
|
|
1803
1867
|
type Cart = z.infer<typeof cartSchema>;
|
|
1804
1868
|
type CartItem = z.infer<typeof cartItemSchema>;
|
|
1805
1869
|
type AddToCartInput = z.infer<typeof addToCartInputSchema>;
|
|
1870
|
+
type AddItemsInput = z.infer<typeof addItemsInputSchema>;
|
|
1871
|
+
type BatchResponse = z.infer<typeof batchResponseSchema>;
|
|
1806
1872
|
type UpdateCartItemInput = z.infer<typeof updateCartItemInputSchema>;
|
|
1807
1873
|
type RemoveCartItemInput = z.infer<typeof removeCartItemInputSchema>;
|
|
1808
1874
|
type CouponInput = z.infer<typeof couponInputSchema>;
|
|
@@ -2893,12 +2959,14 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2893
2959
|
order: z.ZodOptional<z.ZodEnum<["asc", "desc"]>>;
|
|
2894
2960
|
search: z.ZodOptional<z.ZodString>;
|
|
2895
2961
|
slug: z.ZodOptional<z.ZodString>;
|
|
2962
|
+
sku: z.ZodOptional<z.ZodString>;
|
|
2896
2963
|
after: z.ZodOptional<z.ZodString>;
|
|
2897
2964
|
before: z.ZodOptional<z.ZodString>;
|
|
2898
2965
|
modified_after: z.ZodOptional<z.ZodString>;
|
|
2899
2966
|
modified_before: z.ZodOptional<z.ZodString>;
|
|
2900
2967
|
include: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
2901
2968
|
exclude: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
2969
|
+
related: z.ZodOptional<z.ZodNumber>;
|
|
2902
2970
|
parent: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
2903
2971
|
parent_exclude: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
2904
2972
|
type: z.ZodOptional<z.ZodEnum<["simple", "grouped", "external", "variable", "variation"]>>;
|
|
@@ -2938,6 +3006,7 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2938
3006
|
status?: "pending" | "any" | "draft" | "private" | "publish" | undefined;
|
|
2939
3007
|
order?: "asc" | "desc" | undefined;
|
|
2940
3008
|
orderby?: "id" | "price" | "date" | "slug" | "menu_order" | "include" | "title" | "popularity" | "rating" | "date_modified" | undefined;
|
|
3009
|
+
sku?: string | undefined;
|
|
2941
3010
|
catalog_visibility?: "search" | "any" | "visible" | "catalog" | "hidden" | undefined;
|
|
2942
3011
|
slug?: string | undefined;
|
|
2943
3012
|
parent?: number[] | undefined;
|
|
@@ -2949,6 +3018,7 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2949
3018
|
modified_after?: string | undefined;
|
|
2950
3019
|
modified_before?: string | undefined;
|
|
2951
3020
|
exclude?: number[] | undefined;
|
|
3021
|
+
related?: number | undefined;
|
|
2952
3022
|
parent_exclude?: number[] | undefined;
|
|
2953
3023
|
featured?: boolean | undefined;
|
|
2954
3024
|
stock_status?: ("instock" | "outofstock" | "onbackorder")[] | undefined;
|
|
@@ -2973,6 +3043,7 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2973
3043
|
per_page?: number | undefined;
|
|
2974
3044
|
order?: "asc" | "desc" | undefined;
|
|
2975
3045
|
orderby?: "id" | "price" | "date" | "slug" | "menu_order" | "include" | "title" | "popularity" | "rating" | "date_modified" | undefined;
|
|
3046
|
+
sku?: string | undefined;
|
|
2976
3047
|
catalog_visibility?: "search" | "any" | "visible" | "catalog" | "hidden" | undefined;
|
|
2977
3048
|
slug?: string | undefined;
|
|
2978
3049
|
parent?: number[] | undefined;
|
|
@@ -2984,6 +3055,7 @@ declare const storeProductsSearchParamsSchema: z.ZodObject<{
|
|
|
2984
3055
|
modified_after?: string | undefined;
|
|
2985
3056
|
modified_before?: string | undefined;
|
|
2986
3057
|
exclude?: number[] | undefined;
|
|
3058
|
+
related?: number | undefined;
|
|
2987
3059
|
parent_exclude?: number[] | undefined;
|
|
2988
3060
|
featured?: boolean | undefined;
|
|
2989
3061
|
stock_status?: ("instock" | "outofstock" | "onbackorder")[] | undefined;
|
|
@@ -3026,16 +3098,16 @@ declare const productSchema: z.ZodObject<{
|
|
|
3026
3098
|
text: z.ZodString;
|
|
3027
3099
|
url: z.ZodString;
|
|
3028
3100
|
}, "strip", z.ZodTypeAny, {
|
|
3029
|
-
text: string;
|
|
3030
3101
|
minimum: number;
|
|
3031
3102
|
maximum: number;
|
|
3103
|
+
text: string;
|
|
3032
3104
|
multiple_of: number;
|
|
3033
3105
|
description: string;
|
|
3034
3106
|
url: string;
|
|
3035
3107
|
}, {
|
|
3036
|
-
text: string;
|
|
3037
3108
|
minimum: number;
|
|
3038
3109
|
maximum: number;
|
|
3110
|
+
text: string;
|
|
3039
3111
|
multiple_of: number;
|
|
3040
3112
|
description: string;
|
|
3041
3113
|
url: string;
|
|
@@ -3232,9 +3304,9 @@ declare const productSchema: z.ZodObject<{
|
|
|
3232
3304
|
extensions: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
3233
3305
|
}, "strip", z.ZodTypeAny, {
|
|
3234
3306
|
add_to_cart: {
|
|
3235
|
-
text: string;
|
|
3236
3307
|
minimum: number;
|
|
3237
3308
|
maximum: number;
|
|
3309
|
+
text: string;
|
|
3238
3310
|
multiple_of: number;
|
|
3239
3311
|
description: string;
|
|
3240
3312
|
url: string;
|
|
@@ -3316,9 +3388,9 @@ declare const productSchema: z.ZodObject<{
|
|
|
3316
3388
|
review_count: number;
|
|
3317
3389
|
}, {
|
|
3318
3390
|
add_to_cart: {
|
|
3319
|
-
text: string;
|
|
3320
3391
|
minimum: number;
|
|
3321
3392
|
maximum: number;
|
|
3393
|
+
text: string;
|
|
3322
3394
|
multiple_of: number;
|
|
3323
3395
|
description: string;
|
|
3324
3396
|
url: string;
|
|
@@ -3459,9 +3531,19 @@ interface ProductsAPI {
|
|
|
3459
3531
|
get: (id: number) => Promise<Product>;
|
|
3460
3532
|
categories: () => Promise<ProductCategory[]>;
|
|
3461
3533
|
}
|
|
3534
|
+
interface AddItemsResult {
|
|
3535
|
+
cart: Cart;
|
|
3536
|
+
results: {
|
|
3537
|
+
item: AddToCartInput;
|
|
3538
|
+
status: number;
|
|
3539
|
+
code?: string;
|
|
3540
|
+
message?: string;
|
|
3541
|
+
}[];
|
|
3542
|
+
}
|
|
3462
3543
|
interface CartAPI {
|
|
3463
3544
|
get: () => Promise<Cart>;
|
|
3464
3545
|
addItem: (input: AddToCartInput) => Promise<Cart>;
|
|
3546
|
+
addItems: (input: AddItemsInput) => Promise<AddItemsResult>;
|
|
3465
3547
|
updateItem: (input: UpdateCartItemInput) => Promise<Cart>;
|
|
3466
3548
|
removeItem: (input: RemoveCartItemInput) => Promise<Cart>;
|
|
3467
3549
|
applyCoupon: (input: CouponInput) => Promise<Cart>;
|
|
@@ -3490,4 +3572,4 @@ interface WooCommerceClient {
|
|
|
3490
3572
|
orders: OrdersAPI;
|
|
3491
3573
|
}
|
|
3492
3574
|
|
|
3493
|
-
export {
|
|
3575
|
+
export { checkoutSchema as $, type AddItemsInput as A, type BaseErrorOptions as B, type CartHeadersAdapter as C, type ProductImage as D, type ProductParams as E, type ProductsAPI as F, type GetOrderInput as G, type RemoveCartItemInput as H, type SelectShippingRateInput as I, type JwtTokenAdapter as J, type StoreApiOrder as K, type UpdateCustomerInput as L, WooCommerceApiError as M, type WooCommerceApiErrorOptions as N, type OrderStatus as O, type PaginatedResponse as P, addItemsInputSchema as Q, type ResponseOptions as R, type StoreApiVersion as S, addToCartInputSchema as T, type UpdateCartItemInput as U, type ValidationMode as V, type WooCommerceConfig as W, batchResponseSchema as X, cartItemImageSchema as Y, cartSchema as Z, checkoutInputSchema as _, type WooCommerceClient as a, couponInputSchema as a0, productCategorySchema as a1, productImageSchema as a2, productSchema as a3, removeCartItemInputSchema as a4, storeProductsSearchParamsSchema as a5, selectShippingRateInputSchema as a6, storeApiOrderSchema as a7, updateCartItemInputSchema as a8, updateCustomerInputSchema as a9, handleApiResponse as b, handlePaginatedApiResponse as c, type Pagination as d, calculatePagination as e, type WooCommerceApiErrorCode as f, type BaseReportableData as g, handleApiData as h, isZodError as i, type ValidationReportableData as j, type WooCommerceDataValidationErrorOptions as k, type AddItemsResult as l, type AddToCartInput as m, type BatchResponse as n, type Cart as o, type CartAPI as p, type CartItem as q, type CartItemImage as r, setupErrorInterceptor as s, type Checkout as t, type CheckoutAPI as u, type CheckoutInput as v, type CouponInput as w, type OrdersAPI as x, type Product as y, type ProductCategory as z };
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { C as CartHeadersAdapter } from '../types-
|
|
2
|
-
export { P as PaginatedResponse,
|
|
1
|
+
import { C as CartHeadersAdapter } from '../types-9I6oS_83.mjs';
|
|
2
|
+
export { P as PaginatedResponse, d as Pagination, R as ResponseOptions, V as ValidationMode, e as calculatePagination, b as handleApiResponse, c as handlePaginatedApiResponse, i as isZodError } from '../types-9I6oS_83.mjs';
|
|
3
3
|
import { AxiosResponse, AxiosInstance } from 'axios';
|
|
4
|
+
import '@atomic-solutions/errors';
|
|
4
5
|
import 'zod';
|
|
5
6
|
|
|
6
7
|
interface PaginationMeta {
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { C as CartHeadersAdapter } from '../types-
|
|
2
|
-
export { P as PaginatedResponse,
|
|
1
|
+
import { C as CartHeadersAdapter } from '../types-9I6oS_83.js';
|
|
2
|
+
export { P as PaginatedResponse, d as Pagination, R as ResponseOptions, V as ValidationMode, e as calculatePagination, b as handleApiResponse, c as handlePaginatedApiResponse, i as isZodError } from '../types-9I6oS_83.js';
|
|
3
3
|
import { AxiosResponse, AxiosInstance } from 'axios';
|
|
4
|
+
import '@atomic-solutions/errors';
|
|
4
5
|
import 'zod';
|
|
5
6
|
|
|
6
7
|
interface PaginationMeta {
|
package/dist/utils/index.js
CHANGED
|
@@ -131,34 +131,34 @@ var WooCommerceDataValidationError = class _WooCommerceDataValidationError exten
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
// src/http/handleApiResponse.ts
|
|
134
|
-
var
|
|
134
|
+
var handleApiData = (data, schema, options, url) => {
|
|
135
135
|
const validationMode = options?.validationMode ?? "strict";
|
|
136
136
|
if (validationMode === "warn") {
|
|
137
|
-
const result = schema.safeParse(
|
|
137
|
+
const result = schema.safeParse(data);
|
|
138
138
|
if (!result.success) {
|
|
139
139
|
const validationError = new WooCommerceDataValidationError({
|
|
140
|
-
message: `WooCommerce API response validation failed for ${
|
|
141
|
-
url
|
|
140
|
+
message: `WooCommerce API response validation failed for ${url || "unknown endpoint"}`,
|
|
141
|
+
url,
|
|
142
142
|
zodError: result.error,
|
|
143
|
-
value:
|
|
143
|
+
value: data,
|
|
144
144
|
userMessage: "Received unexpected data from WooCommerce"
|
|
145
145
|
});
|
|
146
146
|
options?.onValidationError?.(validationError);
|
|
147
147
|
options?.errorReporter?.(validationError);
|
|
148
148
|
console.warn("[woocommerce-utils] Validation warning:", validationError.message);
|
|
149
|
-
return
|
|
149
|
+
return data;
|
|
150
150
|
}
|
|
151
151
|
return result.data;
|
|
152
152
|
}
|
|
153
153
|
try {
|
|
154
|
-
return schema.parse(
|
|
154
|
+
return schema.parse(data);
|
|
155
155
|
} catch (error) {
|
|
156
156
|
if (error && typeof error === "object" && "issues" in error) {
|
|
157
157
|
const validationError = new WooCommerceDataValidationError({
|
|
158
|
-
message: `WooCommerce API response validation failed for ${
|
|
159
|
-
url
|
|
158
|
+
message: `WooCommerce API response validation failed for ${url || "unknown endpoint"}`,
|
|
159
|
+
url,
|
|
160
160
|
zodError: error,
|
|
161
|
-
value:
|
|
161
|
+
value: data,
|
|
162
162
|
userMessage: "Received unexpected data from WooCommerce"
|
|
163
163
|
});
|
|
164
164
|
options?.onValidationError?.(validationError);
|
|
@@ -168,6 +168,7 @@ var handleApiResponse = (response, schema, options) => {
|
|
|
168
168
|
throw error;
|
|
169
169
|
}
|
|
170
170
|
};
|
|
171
|
+
var handleApiResponse = (response, schema, options) => handleApiData(response.data, schema, options, response.config.url);
|
|
171
172
|
var isZodError = (error) => {
|
|
172
173
|
return error instanceof Error && error.name === "ZodError";
|
|
173
174
|
};
|