@atomic-solutions/woocommerce-api-client 0.1.1 → 0.1.3
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.js +849 -15
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +835 -1
- package/dist/client/index.mjs.map +1 -1
- package/dist/index.js +1380 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1355 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -5
package/dist/client/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import axios, { isAxiosError } from 'axios';
|
|
2
|
-
import { productCategorySchema, productSchema, cartSchema, checkoutSchema, storeApiOrderSchema } from '@atomic-solutions/schemas/woocommerce/store-api';
|
|
3
2
|
import { z } from 'zod';
|
|
4
3
|
|
|
5
4
|
// src/client/createClient.ts
|
|
@@ -627,6 +626,837 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
|
|
|
627
626
|
}
|
|
628
627
|
);
|
|
629
628
|
};
|
|
629
|
+
var addressSchema = z.object({
|
|
630
|
+
/** First name */
|
|
631
|
+
first_name: z.string().min(1, "First name is required"),
|
|
632
|
+
/** Last name */
|
|
633
|
+
last_name: z.string().min(1, "Last name is required"),
|
|
634
|
+
/** Company name (optional) */
|
|
635
|
+
company: z.string(),
|
|
636
|
+
/** Address line 1 */
|
|
637
|
+
address_1: z.string().min(1, "Address is required"),
|
|
638
|
+
/** Address line 2 (optional) */
|
|
639
|
+
address_2: z.string(),
|
|
640
|
+
/** City */
|
|
641
|
+
city: z.string().min(1, "City is required"),
|
|
642
|
+
/** State/Province/Region */
|
|
643
|
+
state: z.string(),
|
|
644
|
+
/** Postal code */
|
|
645
|
+
postcode: z.string().min(1, "Postal code is required"),
|
|
646
|
+
/** Country code (ISO 3166-1 alpha-2) */
|
|
647
|
+
country: z.string(),
|
|
648
|
+
/** Phone number */
|
|
649
|
+
phone: z.string().min(1, "Phone number is required")
|
|
650
|
+
});
|
|
651
|
+
var addressSchemaNonMandatory = z.object({
|
|
652
|
+
/** First name */
|
|
653
|
+
first_name: z.string(),
|
|
654
|
+
/** Last name */
|
|
655
|
+
last_name: z.string(),
|
|
656
|
+
/** Company name (optional) */
|
|
657
|
+
company: z.string(),
|
|
658
|
+
/** Address line 1 */
|
|
659
|
+
address_1: z.string(),
|
|
660
|
+
/** Address line 2 (optional) */
|
|
661
|
+
address_2: z.string(),
|
|
662
|
+
/** City */
|
|
663
|
+
city: z.string(),
|
|
664
|
+
/** State/Province/Region */
|
|
665
|
+
state: z.string(),
|
|
666
|
+
/** Postal code */
|
|
667
|
+
postcode: z.string(),
|
|
668
|
+
/** Country code (ISO 3166-1 alpha-2) */
|
|
669
|
+
country: z.string(),
|
|
670
|
+
/** Phone number */
|
|
671
|
+
phone: z.string()
|
|
672
|
+
});
|
|
673
|
+
var billingAddressSchemaMandatory = addressSchema.extend({
|
|
674
|
+
/** Email address (required for billing) */
|
|
675
|
+
email: z.string().email("Valid email is required")
|
|
676
|
+
});
|
|
677
|
+
var billingAddressSchemaNonMandatory = addressSchemaNonMandatory.extend({
|
|
678
|
+
/** Email address (can be null for guest carts) */
|
|
679
|
+
email: z.string().nullable()
|
|
680
|
+
});
|
|
681
|
+
var moneySchema = z.object({
|
|
682
|
+
/** Currency code (e.g., 'USD', 'EUR', 'BAM') */
|
|
683
|
+
currency_code: z.string(),
|
|
684
|
+
/** Currency symbol (e.g., '$', '€', 'KM') */
|
|
685
|
+
currency_symbol: z.string(),
|
|
686
|
+
/** Number of decimal places (e.g., 2 for dollars/euros) */
|
|
687
|
+
currency_minor_unit: z.number(),
|
|
688
|
+
/** Decimal separator character (e.g., '.', ',') */
|
|
689
|
+
currency_decimal_separator: z.string(),
|
|
690
|
+
/** Thousands separator character (e.g., ',', '.') */
|
|
691
|
+
currency_thousand_separator: z.string(),
|
|
692
|
+
/** Currency symbol prefix (empty if symbol is suffix) */
|
|
693
|
+
currency_prefix: z.string(),
|
|
694
|
+
/** Currency symbol suffix (empty if symbol is prefix) */
|
|
695
|
+
currency_suffix: z.string()
|
|
696
|
+
});
|
|
697
|
+
z.object({
|
|
698
|
+
/** Current page number */
|
|
699
|
+
page: z.number().int().positive().optional(),
|
|
700
|
+
/** Items per page */
|
|
701
|
+
per_page: z.number().int().positive().max(100).optional(),
|
|
702
|
+
/** Offset for pagination */
|
|
703
|
+
offset: z.number().int().nonnegative().optional(),
|
|
704
|
+
/** Sort order */
|
|
705
|
+
order: z.enum(["asc", "desc"]).optional(),
|
|
706
|
+
/** Field to sort by */
|
|
707
|
+
orderby: z.string().optional()
|
|
708
|
+
});
|
|
709
|
+
z.object({
|
|
710
|
+
/** Total number of items */
|
|
711
|
+
total: z.number(),
|
|
712
|
+
/** Total number of pages */
|
|
713
|
+
totalPages: z.number(),
|
|
714
|
+
/** Current page */
|
|
715
|
+
currentPage: z.number(),
|
|
716
|
+
/** Items per page */
|
|
717
|
+
perPage: z.number()
|
|
718
|
+
});
|
|
719
|
+
var productImageSchema = z.object({
|
|
720
|
+
/** Alternative text for the image */
|
|
721
|
+
alt: z.string(),
|
|
722
|
+
/** Image unique identifier */
|
|
723
|
+
id: z.number(),
|
|
724
|
+
/** Image filename */
|
|
725
|
+
name: z.string(),
|
|
726
|
+
/** Available image sizes in JSON format */
|
|
727
|
+
sizes: z.string(),
|
|
728
|
+
/** Full-size image URL */
|
|
729
|
+
src: z.string().url(),
|
|
730
|
+
/** Srcset attribute for responsive images */
|
|
731
|
+
srcset: z.string(),
|
|
732
|
+
/** Thumbnail image URL */
|
|
733
|
+
thumbnail: z.string().url()
|
|
734
|
+
});
|
|
735
|
+
var cartItemImageSchema = z.object({
|
|
736
|
+
/** Image ID */
|
|
737
|
+
id: z.number(),
|
|
738
|
+
/** Full image URL */
|
|
739
|
+
src: z.string(),
|
|
740
|
+
/** Thumbnail URL */
|
|
741
|
+
thumbnail: z.string(),
|
|
742
|
+
/** Responsive image srcset */
|
|
743
|
+
srcset: z.string(),
|
|
744
|
+
/** Responsive image sizes */
|
|
745
|
+
sizes: z.string(),
|
|
746
|
+
/** Image name */
|
|
747
|
+
name: z.string(),
|
|
748
|
+
/** Image alt text */
|
|
749
|
+
alt: z.string()
|
|
750
|
+
});
|
|
751
|
+
var pricesSchema = z.object({
|
|
752
|
+
/** Current active price (sale price if on sale, otherwise regular) */
|
|
753
|
+
price: z.string(),
|
|
754
|
+
/** Regular price (before any discounts) */
|
|
755
|
+
regular_price: z.string(),
|
|
756
|
+
/** Sale price (empty string if not on sale) */
|
|
757
|
+
sale_price: z.string(),
|
|
758
|
+
/** Price range for variable products (null for simple products) */
|
|
759
|
+
price_range: z.object({
|
|
760
|
+
min_amount: z.string(),
|
|
761
|
+
max_amount: z.string()
|
|
762
|
+
}).nullable(),
|
|
763
|
+
/** Raw price data without formatting */
|
|
764
|
+
raw_prices: z.object({
|
|
765
|
+
/** Decimal precision */
|
|
766
|
+
precision: z.number(),
|
|
767
|
+
/** Raw price value */
|
|
768
|
+
price: z.string(),
|
|
769
|
+
/** Raw regular price value */
|
|
770
|
+
regular_price: z.string(),
|
|
771
|
+
/** Raw sale price value */
|
|
772
|
+
sale_price: z.string()
|
|
773
|
+
}).optional()
|
|
774
|
+
}).merge(moneySchema);
|
|
775
|
+
var itemTotalsSchema = z.object({
|
|
776
|
+
/** Subtotal before taxes */
|
|
777
|
+
line_subtotal: z.string(),
|
|
778
|
+
/** Tax amount on subtotal */
|
|
779
|
+
line_subtotal_tax: z.string(),
|
|
780
|
+
/** Total after discounts, before taxes */
|
|
781
|
+
line_total: z.string(),
|
|
782
|
+
/** Tax amount on total */
|
|
783
|
+
line_total_tax: z.string()
|
|
784
|
+
}).merge(moneySchema);
|
|
785
|
+
var cartItemSchema = z.object({
|
|
786
|
+
/** Unique cart item key (use this for update/remove operations) */
|
|
787
|
+
key: z.string(),
|
|
788
|
+
/** Product ID */
|
|
789
|
+
id: z.number(),
|
|
790
|
+
/** Quantity of this item in cart */
|
|
791
|
+
quantity: z.number(),
|
|
792
|
+
/** Quantity limits for this product */
|
|
793
|
+
quantity_limits: z.object({
|
|
794
|
+
/** Minimum quantity allowed */
|
|
795
|
+
minimum: z.number(),
|
|
796
|
+
/** Maximum quantity allowed */
|
|
797
|
+
maximum: z.number(),
|
|
798
|
+
/** Quantity must be multiple of this value */
|
|
799
|
+
multiple_of: z.number(),
|
|
800
|
+
/** Whether quantity can be changed */
|
|
801
|
+
editable: z.boolean()
|
|
802
|
+
}),
|
|
803
|
+
/** Product name */
|
|
804
|
+
name: z.string(),
|
|
805
|
+
/** Short product description */
|
|
806
|
+
short_description: z.string(),
|
|
807
|
+
/** Full product description */
|
|
808
|
+
description: z.string(),
|
|
809
|
+
/** Product SKU */
|
|
810
|
+
sku: z.string(),
|
|
811
|
+
/** Remaining stock count if low (null if not low or unlimited) */
|
|
812
|
+
low_stock_remaining: z.number().nullable(),
|
|
813
|
+
/** Whether backorders are allowed */
|
|
814
|
+
backorders_allowed: z.boolean(),
|
|
815
|
+
/** Whether to show backorder badge */
|
|
816
|
+
show_backorder_badge: z.boolean(),
|
|
817
|
+
/** Whether product can only be purchased individually */
|
|
818
|
+
sold_individually: z.boolean(),
|
|
819
|
+
/** Product permalink URL */
|
|
820
|
+
permalink: z.string(),
|
|
821
|
+
/** Product images */
|
|
822
|
+
images: z.array(cartItemImageSchema),
|
|
823
|
+
/** Variation attributes (for variable products) */
|
|
824
|
+
variation: z.array(
|
|
825
|
+
z.object({
|
|
826
|
+
/** Attribute name (e.g., 'Color', 'Size') */
|
|
827
|
+
attribute: z.string(),
|
|
828
|
+
/** Selected value (e.g., 'Red', 'Large') */
|
|
829
|
+
value: z.string()
|
|
830
|
+
})
|
|
831
|
+
),
|
|
832
|
+
/** Additional item data/metadata */
|
|
833
|
+
item_data: z.array(
|
|
834
|
+
z.object({
|
|
835
|
+
key: z.string(),
|
|
836
|
+
value: z.string()
|
|
837
|
+
})
|
|
838
|
+
),
|
|
839
|
+
/** Product pricing information */
|
|
840
|
+
prices: pricesSchema,
|
|
841
|
+
/** Line item totals */
|
|
842
|
+
totals: itemTotalsSchema,
|
|
843
|
+
/** Catalog visibility setting */
|
|
844
|
+
catalog_visibility: z.string(),
|
|
845
|
+
/** Product type */
|
|
846
|
+
type: z.enum(["simple", "variable", "grouped", "external"]),
|
|
847
|
+
/** Extension data from plugins */
|
|
848
|
+
extensions: z.record(z.string(), z.unknown())
|
|
849
|
+
});
|
|
850
|
+
var cartTotalsSchema = z.object({
|
|
851
|
+
/** Total of all cart items (before discounts and taxes) */
|
|
852
|
+
total_items: z.string(),
|
|
853
|
+
/** Tax on cart items */
|
|
854
|
+
total_items_tax: z.string(),
|
|
855
|
+
/** Total fees */
|
|
856
|
+
total_fees: z.string(),
|
|
857
|
+
/** Tax on fees */
|
|
858
|
+
total_fees_tax: z.string(),
|
|
859
|
+
/** Total discount amount from coupons */
|
|
860
|
+
total_discount: z.string(),
|
|
861
|
+
/** Tax on discounts */
|
|
862
|
+
total_discount_tax: z.string(),
|
|
863
|
+
/** Shipping cost (null if not calculated yet) */
|
|
864
|
+
total_shipping: z.string().nullable(),
|
|
865
|
+
/** Shipping tax (null if not calculated yet) */
|
|
866
|
+
total_shipping_tax: z.string().nullable(),
|
|
867
|
+
/** Final total price (includes all taxes and fees) */
|
|
868
|
+
total_price: z.string(),
|
|
869
|
+
/** Total tax amount */
|
|
870
|
+
total_tax: z.string(),
|
|
871
|
+
/** Tax breakdown by rate */
|
|
872
|
+
tax_lines: z.array(
|
|
873
|
+
z.object({
|
|
874
|
+
/** Tax rate name */
|
|
875
|
+
name: z.string(),
|
|
876
|
+
/** Tax amount */
|
|
877
|
+
price: z.string(),
|
|
878
|
+
/** Tax rate percentage */
|
|
879
|
+
rate: z.string()
|
|
880
|
+
})
|
|
881
|
+
)
|
|
882
|
+
}).merge(moneySchema);
|
|
883
|
+
var cartCouponSchema = z.object({
|
|
884
|
+
/** Coupon code */
|
|
885
|
+
code: z.string(),
|
|
886
|
+
/** Discount totals for this coupon */
|
|
887
|
+
totals: z.object({
|
|
888
|
+
/** Total discount amount (before tax) */
|
|
889
|
+
total_discount: z.string(),
|
|
890
|
+
/** Tax amount on discount */
|
|
891
|
+
total_discount_tax: z.string()
|
|
892
|
+
}).merge(moneySchema)
|
|
893
|
+
});
|
|
894
|
+
var shippingRateSchema = z.object({
|
|
895
|
+
/** Unique rate identifier (format: instance_id:method_id) */
|
|
896
|
+
rate_id: z.string(),
|
|
897
|
+
/** Shipping method name */
|
|
898
|
+
name: z.string(),
|
|
899
|
+
/** Shipping method description */
|
|
900
|
+
description: z.string(),
|
|
901
|
+
/** Estimated delivery time */
|
|
902
|
+
delivery_time: z.string(),
|
|
903
|
+
/** Shipping cost */
|
|
904
|
+
price: z.string(),
|
|
905
|
+
/** Shipping instance ID */
|
|
906
|
+
instance_id: z.number(),
|
|
907
|
+
/** Shipping method ID */
|
|
908
|
+
method_id: z.string(),
|
|
909
|
+
/** Additional metadata for this shipping method */
|
|
910
|
+
meta_data: z.array(
|
|
911
|
+
z.object({
|
|
912
|
+
key: z.string(),
|
|
913
|
+
value: z.string()
|
|
914
|
+
})
|
|
915
|
+
),
|
|
916
|
+
/** Whether this rate is currently selected */
|
|
917
|
+
selected: z.boolean(),
|
|
918
|
+
/** Currency code for the price */
|
|
919
|
+
currency_code: z.string(),
|
|
920
|
+
/** Currency symbol for the price */
|
|
921
|
+
currency_symbol: z.string()
|
|
922
|
+
});
|
|
923
|
+
var shippingPackageSchema = z.object({
|
|
924
|
+
/** Package identifier (0-indexed) */
|
|
925
|
+
package_id: z.number(),
|
|
926
|
+
/** Package name/label */
|
|
927
|
+
name: z.string(),
|
|
928
|
+
/** Shipping destination address */
|
|
929
|
+
destination: z.object({
|
|
930
|
+
address_1: z.string(),
|
|
931
|
+
address_2: z.string().optional(),
|
|
932
|
+
city: z.string(),
|
|
933
|
+
state: z.string(),
|
|
934
|
+
postcode: z.string(),
|
|
935
|
+
country: z.string()
|
|
936
|
+
}),
|
|
937
|
+
/** Items included in this package */
|
|
938
|
+
items: z.array(
|
|
939
|
+
z.object({
|
|
940
|
+
/** Cart item key */
|
|
941
|
+
key: z.string(),
|
|
942
|
+
/** Product name */
|
|
943
|
+
name: z.string(),
|
|
944
|
+
/** Quantity in package */
|
|
945
|
+
quantity: z.number()
|
|
946
|
+
})
|
|
947
|
+
),
|
|
948
|
+
/** Available shipping rates for this package */
|
|
949
|
+
shipping_rates: z.array(shippingRateSchema)
|
|
950
|
+
});
|
|
951
|
+
var cartSchema = z.object({
|
|
952
|
+
items: z.array(cartItemSchema),
|
|
953
|
+
items_count: z.number(),
|
|
954
|
+
items_weight: z.number(),
|
|
955
|
+
needs_payment: z.boolean(),
|
|
956
|
+
needs_shipping: z.boolean(),
|
|
957
|
+
payment_methods: z.array(z.enum(["cod", "monri"])),
|
|
958
|
+
payment_requirements: z.array(z.string()),
|
|
959
|
+
has_calculated_shipping: z.boolean(),
|
|
960
|
+
shipping_address: addressSchemaNonMandatory,
|
|
961
|
+
billing_address: billingAddressSchemaNonMandatory,
|
|
962
|
+
shipping_rates: z.array(shippingPackageSchema),
|
|
963
|
+
coupons: z.array(cartCouponSchema),
|
|
964
|
+
totals: cartTotalsSchema,
|
|
965
|
+
errors: z.array(
|
|
966
|
+
z.object({
|
|
967
|
+
code: z.string(),
|
|
968
|
+
message: z.string()
|
|
969
|
+
})
|
|
970
|
+
),
|
|
971
|
+
extensions: z.record(z.string(), z.unknown()).optional(),
|
|
972
|
+
cross_sells: z.array(z.unknown()),
|
|
973
|
+
fees: z.array(z.unknown())
|
|
974
|
+
});
|
|
975
|
+
z.object({
|
|
976
|
+
id: z.number(),
|
|
977
|
+
quantity: z.number().int().positive(),
|
|
978
|
+
variation: z.array(
|
|
979
|
+
z.object({
|
|
980
|
+
attribute: z.string(),
|
|
981
|
+
value: z.string()
|
|
982
|
+
})
|
|
983
|
+
).optional()
|
|
984
|
+
});
|
|
985
|
+
z.object({
|
|
986
|
+
key: z.string(),
|
|
987
|
+
quantity: z.number().int().positive()
|
|
988
|
+
});
|
|
989
|
+
z.object({
|
|
990
|
+
key: z.string()
|
|
991
|
+
});
|
|
992
|
+
z.object({
|
|
993
|
+
code: z.string().min(1)
|
|
994
|
+
});
|
|
995
|
+
z.object({
|
|
996
|
+
billing_address: billingAddressSchemaMandatory.partial(),
|
|
997
|
+
shipping_address: addressSchema.partial()
|
|
998
|
+
}).partial();
|
|
999
|
+
z.object({
|
|
1000
|
+
package_id: z.union([z.number(), z.string()]).default(0),
|
|
1001
|
+
rate_id: z.string()
|
|
1002
|
+
});
|
|
1003
|
+
var orderItemImageSchema = z.object({
|
|
1004
|
+
/** Image ID */
|
|
1005
|
+
id: z.number(),
|
|
1006
|
+
/** Full image URL */
|
|
1007
|
+
src: z.string().url(),
|
|
1008
|
+
/** Thumbnail URL */
|
|
1009
|
+
thumbnail: z.string().url(),
|
|
1010
|
+
/** Responsive image srcset */
|
|
1011
|
+
srcset: z.string(),
|
|
1012
|
+
/** Responsive image sizes attribute */
|
|
1013
|
+
sizes: z.string(),
|
|
1014
|
+
/** Image name */
|
|
1015
|
+
name: z.string(),
|
|
1016
|
+
/** Image alt text */
|
|
1017
|
+
alt: z.string()
|
|
1018
|
+
});
|
|
1019
|
+
var orderItemPricesSchema = z.object({
|
|
1020
|
+
/** Formatted price (current price) */
|
|
1021
|
+
price: z.string(),
|
|
1022
|
+
/** Formatted regular price */
|
|
1023
|
+
regular_price: z.string(),
|
|
1024
|
+
/** Formatted sale price */
|
|
1025
|
+
sale_price: z.string(),
|
|
1026
|
+
/** Price range (null for simple products) */
|
|
1027
|
+
price_range: z.null(),
|
|
1028
|
+
/** Currency code (e.g., 'USD', 'EUR') */
|
|
1029
|
+
currency_code: z.string(),
|
|
1030
|
+
/** Currency symbol (e.g., '$', '€') */
|
|
1031
|
+
currency_symbol: z.string(),
|
|
1032
|
+
/** Number of decimal places for currency */
|
|
1033
|
+
currency_minor_unit: z.number(),
|
|
1034
|
+
/** Decimal separator (e.g., '.', ',') */
|
|
1035
|
+
currency_decimal_separator: z.string(),
|
|
1036
|
+
/** Thousand separator (e.g., ',', '.') */
|
|
1037
|
+
currency_thousand_separator: z.string(),
|
|
1038
|
+
/** Currency prefix (e.g., '$') */
|
|
1039
|
+
currency_prefix: z.string(),
|
|
1040
|
+
/** Currency suffix (e.g., 'USD') */
|
|
1041
|
+
currency_suffix: z.string(),
|
|
1042
|
+
/** Raw price values for calculations */
|
|
1043
|
+
raw_prices: z.object({
|
|
1044
|
+
/** Precision for price calculations */
|
|
1045
|
+
precision: z.number(),
|
|
1046
|
+
/** Raw price (in minor units) */
|
|
1047
|
+
price: z.string(),
|
|
1048
|
+
/** Raw regular price (in minor units) */
|
|
1049
|
+
regular_price: z.string(),
|
|
1050
|
+
/** Raw sale price (in minor units) */
|
|
1051
|
+
sale_price: z.string()
|
|
1052
|
+
})
|
|
1053
|
+
});
|
|
1054
|
+
var orderItemTotalsSchema = z.object({
|
|
1055
|
+
/** Line subtotal (before discounts) */
|
|
1056
|
+
line_subtotal: z.string(),
|
|
1057
|
+
/** Line subtotal tax */
|
|
1058
|
+
line_subtotal_tax: z.string(),
|
|
1059
|
+
/** Line total (after discounts) */
|
|
1060
|
+
line_total: z.string(),
|
|
1061
|
+
/** Line total tax */
|
|
1062
|
+
line_total_tax: z.string(),
|
|
1063
|
+
/** Currency code */
|
|
1064
|
+
currency_code: z.string(),
|
|
1065
|
+
/** Currency symbol */
|
|
1066
|
+
currency_symbol: z.string(),
|
|
1067
|
+
/** Currency minor unit */
|
|
1068
|
+
currency_minor_unit: z.number(),
|
|
1069
|
+
/** Decimal separator */
|
|
1070
|
+
currency_decimal_separator: z.string(),
|
|
1071
|
+
/** Thousand separator */
|
|
1072
|
+
currency_thousand_separator: z.string(),
|
|
1073
|
+
/** Currency prefix */
|
|
1074
|
+
currency_prefix: z.string(),
|
|
1075
|
+
/** Currency suffix */
|
|
1076
|
+
currency_suffix: z.string()
|
|
1077
|
+
});
|
|
1078
|
+
var quantityLimitsSchema = z.object({
|
|
1079
|
+
/** Minimum quantity allowed */
|
|
1080
|
+
minimum: z.number(),
|
|
1081
|
+
/** Maximum quantity allowed */
|
|
1082
|
+
maximum: z.number(),
|
|
1083
|
+
/** Quantity must be multiple of this value */
|
|
1084
|
+
multiple_of: z.number(),
|
|
1085
|
+
/** Whether quantity is editable */
|
|
1086
|
+
editable: z.boolean()
|
|
1087
|
+
});
|
|
1088
|
+
var orderItemSchema = z.object({
|
|
1089
|
+
/** Unique cart/order item key */
|
|
1090
|
+
key: z.string(),
|
|
1091
|
+
/** Product ID */
|
|
1092
|
+
id: z.number(),
|
|
1093
|
+
/** Quantity ordered */
|
|
1094
|
+
quantity: z.number(),
|
|
1095
|
+
/** Quantity limits for this product */
|
|
1096
|
+
quantity_limits: quantityLimitsSchema,
|
|
1097
|
+
/** Product name */
|
|
1098
|
+
name: z.string(),
|
|
1099
|
+
/** Short description */
|
|
1100
|
+
short_description: z.string(),
|
|
1101
|
+
/** Full description */
|
|
1102
|
+
description: z.string(),
|
|
1103
|
+
/** Product SKU */
|
|
1104
|
+
sku: z.string(),
|
|
1105
|
+
/** Low stock warning (null if not low) */
|
|
1106
|
+
low_stock_remaining: z.null(),
|
|
1107
|
+
/** Whether backorders are allowed */
|
|
1108
|
+
backorders_allowed: z.boolean(),
|
|
1109
|
+
/** Whether to show backorder badge */
|
|
1110
|
+
show_backorder_badge: z.boolean(),
|
|
1111
|
+
/** Whether product can only be purchased individually */
|
|
1112
|
+
sold_individually: z.boolean(),
|
|
1113
|
+
/** Product permalink URL */
|
|
1114
|
+
permalink: z.string().url(),
|
|
1115
|
+
/** Product images */
|
|
1116
|
+
images: z.array(orderItemImageSchema),
|
|
1117
|
+
/** Variation attributes (empty for simple products) */
|
|
1118
|
+
variation: z.array(z.unknown()),
|
|
1119
|
+
/** Custom item data/metadata */
|
|
1120
|
+
item_data: z.array(z.unknown()),
|
|
1121
|
+
/** Price information */
|
|
1122
|
+
prices: orderItemPricesSchema,
|
|
1123
|
+
/** Totals for this line item */
|
|
1124
|
+
totals: orderItemTotalsSchema,
|
|
1125
|
+
/** Catalog visibility setting */
|
|
1126
|
+
catalog_visibility: z.string()
|
|
1127
|
+
});
|
|
1128
|
+
var orderTotalsSchema = z.object({
|
|
1129
|
+
/** Subtotal (before discounts and fees) */
|
|
1130
|
+
subtotal: z.string(),
|
|
1131
|
+
/** Total discount amount */
|
|
1132
|
+
total_discount: z.string(),
|
|
1133
|
+
/** Total shipping cost */
|
|
1134
|
+
total_shipping: z.string(),
|
|
1135
|
+
/** Total fees */
|
|
1136
|
+
total_fees: z.string(),
|
|
1137
|
+
/** Total tax */
|
|
1138
|
+
total_tax: z.string(),
|
|
1139
|
+
/** Total refund amount */
|
|
1140
|
+
total_refund: z.string(),
|
|
1141
|
+
/** Final total price */
|
|
1142
|
+
total_price: z.string(),
|
|
1143
|
+
/** Total items cost (subtotal after item-level discounts) */
|
|
1144
|
+
total_items: z.string(),
|
|
1145
|
+
/** Tax on items */
|
|
1146
|
+
total_items_tax: z.string(),
|
|
1147
|
+
/** Tax on fees */
|
|
1148
|
+
total_fees_tax: z.string(),
|
|
1149
|
+
/** Tax on discounts */
|
|
1150
|
+
total_discount_tax: z.string(),
|
|
1151
|
+
/** Tax on shipping */
|
|
1152
|
+
total_shipping_tax: z.string(),
|
|
1153
|
+
/** Tax line items breakdown */
|
|
1154
|
+
tax_lines: z.array(z.unknown()),
|
|
1155
|
+
/** Currency code (e.g., 'USD', 'EUR', 'BAM') */
|
|
1156
|
+
currency_code: z.string(),
|
|
1157
|
+
/** Currency symbol (e.g., '$', '€', 'KM') */
|
|
1158
|
+
currency_symbol: z.string(),
|
|
1159
|
+
/** Number of decimal places for currency */
|
|
1160
|
+
currency_minor_unit: z.number(),
|
|
1161
|
+
/** Decimal separator (e.g., '.', ',') */
|
|
1162
|
+
currency_decimal_separator: z.string(),
|
|
1163
|
+
/** Thousand separator (e.g., ',', '.') */
|
|
1164
|
+
currency_thousand_separator: z.string(),
|
|
1165
|
+
/** Currency prefix (e.g., '$') */
|
|
1166
|
+
currency_prefix: z.string(),
|
|
1167
|
+
/** Currency suffix (e.g., 'USD') */
|
|
1168
|
+
currency_suffix: z.string()
|
|
1169
|
+
});
|
|
1170
|
+
var orderStatusEnum = z.enum([
|
|
1171
|
+
"pending",
|
|
1172
|
+
// Order received, awaiting payment
|
|
1173
|
+
"processing",
|
|
1174
|
+
// Payment received, order is being processed
|
|
1175
|
+
"on-hold",
|
|
1176
|
+
// Order on hold, awaiting confirmation
|
|
1177
|
+
"completed",
|
|
1178
|
+
// Order fulfilled and complete
|
|
1179
|
+
"cancelled",
|
|
1180
|
+
// Order cancelled by customer or admin
|
|
1181
|
+
"refunded",
|
|
1182
|
+
// Order refunded
|
|
1183
|
+
"failed"
|
|
1184
|
+
// Payment failed or order declined
|
|
1185
|
+
]);
|
|
1186
|
+
var storeApiOrderSchema = z.object({
|
|
1187
|
+
/** Order ID */
|
|
1188
|
+
id: z.number(),
|
|
1189
|
+
/** Order status */
|
|
1190
|
+
status: orderStatusEnum,
|
|
1191
|
+
/** Order line items (products purchased) */
|
|
1192
|
+
items: z.array(orderItemSchema),
|
|
1193
|
+
/** Applied coupons */
|
|
1194
|
+
coupons: z.array(z.unknown()),
|
|
1195
|
+
/** Order fees */
|
|
1196
|
+
fees: z.array(z.unknown()),
|
|
1197
|
+
/** Order totals breakdown */
|
|
1198
|
+
totals: orderTotalsSchema,
|
|
1199
|
+
/** Shipping address */
|
|
1200
|
+
shipping_address: addressSchema,
|
|
1201
|
+
/** Billing address (includes email) */
|
|
1202
|
+
billing_address: billingAddressSchemaMandatory,
|
|
1203
|
+
/** Whether order still needs payment */
|
|
1204
|
+
needs_payment: z.boolean(),
|
|
1205
|
+
/** Whether order needs shipping */
|
|
1206
|
+
needs_shipping: z.boolean(),
|
|
1207
|
+
/** Payment method requirements */
|
|
1208
|
+
payment_requirements: z.array(z.string()),
|
|
1209
|
+
/** Order errors (if any) */
|
|
1210
|
+
errors: z.array(z.unknown()),
|
|
1211
|
+
/** Payment method (optional - returned from checkout) */
|
|
1212
|
+
payment_method: z.string().optional(),
|
|
1213
|
+
/** Payment method title (optional - returned from checkout) */
|
|
1214
|
+
payment_method_title: z.string().optional()
|
|
1215
|
+
});
|
|
1216
|
+
z.object({
|
|
1217
|
+
id: z.number(),
|
|
1218
|
+
status: z.string(),
|
|
1219
|
+
order_key: z.string(),
|
|
1220
|
+
number: z.string(),
|
|
1221
|
+
currency: z.string(),
|
|
1222
|
+
total: z.string(),
|
|
1223
|
+
date_created: z.string(),
|
|
1224
|
+
customer_note: z.string(),
|
|
1225
|
+
billing: z.record(z.string(), z.unknown()),
|
|
1226
|
+
shipping: z.record(z.string(), z.unknown()),
|
|
1227
|
+
payment_method: z.string(),
|
|
1228
|
+
payment_method_title: z.string(),
|
|
1229
|
+
line_items: z.array(z.unknown())
|
|
1230
|
+
});
|
|
1231
|
+
var checkoutSchema = z.object({
|
|
1232
|
+
order_id: z.number(),
|
|
1233
|
+
status: z.string(),
|
|
1234
|
+
order_key: z.string(),
|
|
1235
|
+
customer_note: z.string(),
|
|
1236
|
+
customer_id: z.number(),
|
|
1237
|
+
billing_address: billingAddressSchemaNonMandatory,
|
|
1238
|
+
shipping_address: addressSchemaNonMandatory,
|
|
1239
|
+
payment_method: z.string(),
|
|
1240
|
+
payment_result: z.object({
|
|
1241
|
+
payment_status: z.string(),
|
|
1242
|
+
payment_details: z.array(z.unknown()),
|
|
1243
|
+
redirect_url: z.string()
|
|
1244
|
+
})
|
|
1245
|
+
});
|
|
1246
|
+
z.object({
|
|
1247
|
+
payment_method: z.string(),
|
|
1248
|
+
payment_data: z.array(
|
|
1249
|
+
z.object({
|
|
1250
|
+
key: z.string(),
|
|
1251
|
+
value: z.union([z.string(), z.boolean()])
|
|
1252
|
+
})
|
|
1253
|
+
).optional(),
|
|
1254
|
+
billing_address: billingAddressSchemaMandatory.optional(),
|
|
1255
|
+
shipping_address: addressSchema.optional(),
|
|
1256
|
+
customer_note: z.string().optional(),
|
|
1257
|
+
create_account: z.boolean().optional(),
|
|
1258
|
+
extensions: z.record(z.string(), z.unknown()).optional()
|
|
1259
|
+
});
|
|
1260
|
+
var addToCartSchema = z.object({
|
|
1261
|
+
/** Description for add to cart action */
|
|
1262
|
+
description: z.string(),
|
|
1263
|
+
/** Maximum quantity that can be added */
|
|
1264
|
+
maximum: z.number(),
|
|
1265
|
+
/** Minimum quantity that can be added */
|
|
1266
|
+
minimum: z.number(),
|
|
1267
|
+
/** Quantity must be a multiple of this number */
|
|
1268
|
+
multiple_of: z.number(),
|
|
1269
|
+
/** Text for add to cart button */
|
|
1270
|
+
text: z.string(),
|
|
1271
|
+
/** URL for add to cart action */
|
|
1272
|
+
url: z.string()
|
|
1273
|
+
});
|
|
1274
|
+
var embeddedCategorySchema = z.object({
|
|
1275
|
+
/** Category unique identifier */
|
|
1276
|
+
id: z.number(),
|
|
1277
|
+
/** Category display name */
|
|
1278
|
+
name: z.string(),
|
|
1279
|
+
/** URL-friendly category identifier */
|
|
1280
|
+
slug: z.string(),
|
|
1281
|
+
/** Link to category page */
|
|
1282
|
+
link: z.string(),
|
|
1283
|
+
/** Parent category ID (0 for root categories) - optional in embedded */
|
|
1284
|
+
parent: z.number().optional(),
|
|
1285
|
+
/** Category description - optional in embedded */
|
|
1286
|
+
description: z.string().optional(),
|
|
1287
|
+
/** Display type - optional in embedded */
|
|
1288
|
+
display: z.string().optional(),
|
|
1289
|
+
/** Category image - optional in embedded */
|
|
1290
|
+
image: productImageSchema.nullable().optional(),
|
|
1291
|
+
/** Menu order for sorting - optional in embedded */
|
|
1292
|
+
menu_order: z.number().optional(),
|
|
1293
|
+
/** Number of products in this category - optional in embedded */
|
|
1294
|
+
count: z.number().optional()
|
|
1295
|
+
});
|
|
1296
|
+
var productCategorySchema = z.object({
|
|
1297
|
+
/** Category unique identifier */
|
|
1298
|
+
id: z.number(),
|
|
1299
|
+
/** Category display name */
|
|
1300
|
+
name: z.string(),
|
|
1301
|
+
/** URL-friendly category identifier */
|
|
1302
|
+
slug: z.string(),
|
|
1303
|
+
/** Parent category ID (0 for root categories) */
|
|
1304
|
+
parent: z.number(),
|
|
1305
|
+
/** Category description */
|
|
1306
|
+
description: z.string(),
|
|
1307
|
+
/** Category image */
|
|
1308
|
+
image: productImageSchema.nullable(),
|
|
1309
|
+
/** Menu order for sorting */
|
|
1310
|
+
menu_order: z.number().optional(),
|
|
1311
|
+
/** Number of products in this category */
|
|
1312
|
+
count: z.number()
|
|
1313
|
+
});
|
|
1314
|
+
z.object({
|
|
1315
|
+
// Pagination
|
|
1316
|
+
/** Current page number */
|
|
1317
|
+
page: z.number(),
|
|
1318
|
+
/** Number of products per page (1-100) */
|
|
1319
|
+
per_page: z.number().min(1).max(100).default(10),
|
|
1320
|
+
// Ordering
|
|
1321
|
+
/** Field to order results by */
|
|
1322
|
+
orderby: z.enum([
|
|
1323
|
+
"date",
|
|
1324
|
+
"id",
|
|
1325
|
+
"include",
|
|
1326
|
+
"title",
|
|
1327
|
+
"slug",
|
|
1328
|
+
"price",
|
|
1329
|
+
"popularity",
|
|
1330
|
+
"rating",
|
|
1331
|
+
"menu_order",
|
|
1332
|
+
"date_modified"
|
|
1333
|
+
]).optional(),
|
|
1334
|
+
/** Sort order (ascending or descending) */
|
|
1335
|
+
order: z.enum(["asc", "desc"]).optional(),
|
|
1336
|
+
// Filtering
|
|
1337
|
+
/** Search query string */
|
|
1338
|
+
search: z.string().optional(),
|
|
1339
|
+
/** Exact slug match */
|
|
1340
|
+
slug: z.string().optional(),
|
|
1341
|
+
// Date filtering
|
|
1342
|
+
/** Filter products published after this date */
|
|
1343
|
+
after: z.string().datetime().optional(),
|
|
1344
|
+
/** Filter products published before this date */
|
|
1345
|
+
before: z.string().datetime().optional(),
|
|
1346
|
+
/** Filter products modified after this date */
|
|
1347
|
+
modified_after: z.string().datetime().optional(),
|
|
1348
|
+
/** Filter products modified before this date */
|
|
1349
|
+
modified_before: z.string().datetime().optional(),
|
|
1350
|
+
// ID filtering
|
|
1351
|
+
/** Include specific product IDs */
|
|
1352
|
+
include: z.array(z.number()).optional(),
|
|
1353
|
+
/** Exclude specific product IDs */
|
|
1354
|
+
exclude: z.array(z.number()).optional(),
|
|
1355
|
+
// Parent/Child
|
|
1356
|
+
/** Filter by parent product IDs */
|
|
1357
|
+
parent: z.array(z.number()).optional(),
|
|
1358
|
+
/** Exclude products with these parent IDs */
|
|
1359
|
+
parent_exclude: z.array(z.number()).optional(),
|
|
1360
|
+
// Type & Status
|
|
1361
|
+
/** Filter by product type */
|
|
1362
|
+
type: z.enum(["simple", "grouped", "external", "variable", "variation"]).optional(),
|
|
1363
|
+
/** Filter by product status */
|
|
1364
|
+
status: z.enum(["any", "draft", "pending", "private", "publish"]).optional(),
|
|
1365
|
+
// Featured
|
|
1366
|
+
/** Filter featured products */
|
|
1367
|
+
featured: z.boolean().optional(),
|
|
1368
|
+
// Visibility
|
|
1369
|
+
/** Filter by catalog visibility */
|
|
1370
|
+
catalog_visibility: z.enum(["any", "visible", "catalog", "search", "hidden"]).optional(),
|
|
1371
|
+
// Stock
|
|
1372
|
+
/** Filter by stock status */
|
|
1373
|
+
stock_status: z.array(z.enum(["instock", "outofstock", "onbackorder"])).optional(),
|
|
1374
|
+
// Category & Tag filtering
|
|
1375
|
+
/** Filter by category slug or ID */
|
|
1376
|
+
category: z.string().optional(),
|
|
1377
|
+
/** Category filter operator */
|
|
1378
|
+
category_operator: z.enum(["in", "not_in", "and"]).optional(),
|
|
1379
|
+
/** Filter by tag slug or ID */
|
|
1380
|
+
tag: z.string().optional(),
|
|
1381
|
+
/** Tag filter operator */
|
|
1382
|
+
tag_operator: z.enum(["in", "not_in", "and"]).optional(),
|
|
1383
|
+
// Attribute filtering
|
|
1384
|
+
/** Filter by product attributes */
|
|
1385
|
+
attributes: z.array(
|
|
1386
|
+
z.object({
|
|
1387
|
+
/** Attribute name */
|
|
1388
|
+
attribute: z.string(),
|
|
1389
|
+
/** Filter by attribute term IDs */
|
|
1390
|
+
term_id: z.array(z.number()).optional(),
|
|
1391
|
+
/** Filter by attribute term slugs */
|
|
1392
|
+
slug: z.array(z.string()).optional(),
|
|
1393
|
+
/** Attribute filter operator */
|
|
1394
|
+
operator: z.enum(["in", "not_in", "and"]).optional()
|
|
1395
|
+
})
|
|
1396
|
+
).optional(),
|
|
1397
|
+
/** Relationship between attribute filters */
|
|
1398
|
+
attribute_relation: z.enum(["in", "and"]).optional(),
|
|
1399
|
+
// Price filtering
|
|
1400
|
+
/** Minimum price filter */
|
|
1401
|
+
min_price: z.string().optional(),
|
|
1402
|
+
/** Maximum price filter */
|
|
1403
|
+
max_price: z.string().optional(),
|
|
1404
|
+
// Sale status
|
|
1405
|
+
/** Filter products on sale */
|
|
1406
|
+
on_sale: z.boolean().optional(),
|
|
1407
|
+
// Rating filter
|
|
1408
|
+
/** Filter by product rating (1-5 stars) */
|
|
1409
|
+
rating: z.array(z.number().min(1).max(5)).optional()
|
|
1410
|
+
});
|
|
1411
|
+
var productSchema = z.object({
|
|
1412
|
+
id: z.number(),
|
|
1413
|
+
name: z.string(),
|
|
1414
|
+
slug: z.string(),
|
|
1415
|
+
type: z.string(),
|
|
1416
|
+
variation: z.string(),
|
|
1417
|
+
permalink: z.string().url(),
|
|
1418
|
+
sku: z.string(),
|
|
1419
|
+
short_description: z.string(),
|
|
1420
|
+
description: z.string(),
|
|
1421
|
+
is_purchasable: z.boolean(),
|
|
1422
|
+
is_in_stock: z.boolean(),
|
|
1423
|
+
is_on_backorder: z.boolean(),
|
|
1424
|
+
low_stock_remaining: z.number().nullable(),
|
|
1425
|
+
sold_individually: z.boolean(),
|
|
1426
|
+
add_to_cart: addToCartSchema,
|
|
1427
|
+
has_options: z.boolean(),
|
|
1428
|
+
on_sale: z.boolean(),
|
|
1429
|
+
parent: z.number(),
|
|
1430
|
+
attributes: z.array(z.unknown()),
|
|
1431
|
+
categories: z.array(embeddedCategorySchema),
|
|
1432
|
+
tags: z.array(z.unknown()),
|
|
1433
|
+
images: z.array(productImageSchema),
|
|
1434
|
+
variations: z.array(z.unknown()),
|
|
1435
|
+
price_html: z.string(),
|
|
1436
|
+
prices: pricesSchema,
|
|
1437
|
+
average_rating: z.string(),
|
|
1438
|
+
review_count: z.number(),
|
|
1439
|
+
extensions: z.record(z.string(), z.unknown())
|
|
1440
|
+
});
|
|
1441
|
+
var paymentDataItemSchema = z.object({
|
|
1442
|
+
/** Key identifier for the payment data field */
|
|
1443
|
+
key: z.string(),
|
|
1444
|
+
/** Value can be string or boolean depending on the field */
|
|
1445
|
+
value: z.union([z.string(), z.boolean()])
|
|
1446
|
+
});
|
|
1447
|
+
z.object({
|
|
1448
|
+
/** Payment method ID (e.g., "cod", "stripe", "bacs") */
|
|
1449
|
+
payment_method: z.string().min(1, "Payment method is required"),
|
|
1450
|
+
/**
|
|
1451
|
+
* Optional payment gateway-specific data
|
|
1452
|
+
*
|
|
1453
|
+
* Array of key-value pairs that will be passed to the payment gateway
|
|
1454
|
+
* Example: [{ key: "stripe_token", value: "tok_xyz" }]
|
|
1455
|
+
*/
|
|
1456
|
+
payment_data: z.array(paymentDataItemSchema).optional()
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1459
|
+
// src/api/cart.ts
|
|
630
1460
|
var createCartAPI = (client, endpoints, options) => ({
|
|
631
1461
|
get: async () => {
|
|
632
1462
|
const response = await client.get(endpoints.cart);
|
|
@@ -661,6 +1491,8 @@ var createCartAPI = (client, endpoints, options) => ({
|
|
|
661
1491
|
return handleApiResponse(response, cartSchema, options);
|
|
662
1492
|
}
|
|
663
1493
|
});
|
|
1494
|
+
|
|
1495
|
+
// src/api/checkout.ts
|
|
664
1496
|
var createCheckoutAPI = (client, endpoints, options) => ({
|
|
665
1497
|
get: async () => {
|
|
666
1498
|
const response = await client.get(endpoints.checkout);
|
|
@@ -671,6 +1503,8 @@ var createCheckoutAPI = (client, endpoints, options) => ({
|
|
|
671
1503
|
return handleApiResponse(response, checkoutSchema, options);
|
|
672
1504
|
}
|
|
673
1505
|
});
|
|
1506
|
+
|
|
1507
|
+
// src/api/orders.ts
|
|
674
1508
|
var createOrdersAPI = (client, endpoints, options) => ({
|
|
675
1509
|
/**
|
|
676
1510
|
* Get a single order by ID
|