@atomic-solutions/woocommerce-api-client 0.1.0 → 0.1.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.
Files changed (45) hide show
  1. package/dist/client/index.d.mts +3 -3
  2. package/dist/client/index.d.ts +3 -3
  3. package/dist/client/index.js +19 -709
  4. package/dist/client/index.js.map +1 -1
  5. package/dist/client/index.mjs +5 -695
  6. package/dist/client/index.mjs.map +1 -1
  7. package/dist/http/index.d.mts +3 -3
  8. package/dist/http/index.d.ts +3 -3
  9. package/dist/http/index.js +4 -3
  10. package/dist/http/index.js.map +1 -1
  11. package/dist/http/index.mjs +4 -3
  12. package/dist/http/index.mjs.map +1 -1
  13. package/dist/index.d.mts +5 -5
  14. package/dist/index.d.ts +5 -5
  15. package/dist/index.js +148 -1370
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +8 -1346
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/{types-qKWtrw7A.d.ts → types-DuA0wOpm.d.mts} +1 -1
  20. package/dist/{types-B-zy1xrP.d.mts → types-DuA0wOpm.d.ts} +1 -1
  21. package/dist/utils/index.d.mts +3 -3
  22. package/dist/utils/index.d.ts +3 -3
  23. package/package.json +4 -19
  24. package/dist/pagination.schema-CdjWGZJr.d.mts +0 -190
  25. package/dist/pagination.schema-CdjWGZJr.d.ts +0 -190
  26. package/dist/products-Cxl54crz.d.mts +0 -3412
  27. package/dist/products-Cxl54crz.d.ts +0 -3412
  28. package/dist/schemas/admin-api/index.d.mts +0 -5340
  29. package/dist/schemas/admin-api/index.d.ts +0 -5340
  30. package/dist/schemas/admin-api/index.js +0 -584
  31. package/dist/schemas/admin-api/index.js.map +0 -1
  32. package/dist/schemas/admin-api/index.mjs +0 -545
  33. package/dist/schemas/admin-api/index.mjs.map +0 -1
  34. package/dist/schemas/index.d.mts +0 -4
  35. package/dist/schemas/index.d.ts +0 -4
  36. package/dist/schemas/index.js +0 -887
  37. package/dist/schemas/index.js.map +0 -1
  38. package/dist/schemas/index.mjs +0 -844
  39. package/dist/schemas/index.mjs.map +0 -1
  40. package/dist/schemas/store-api/index.d.mts +0 -1076
  41. package/dist/schemas/store-api/index.d.ts +0 -1076
  42. package/dist/schemas/store-api/index.js +0 -887
  43. package/dist/schemas/store-api/index.js.map +0 -1
  44. package/dist/schemas/store-api/index.mjs +0 -844
  45. package/dist/schemas/store-api/index.mjs.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import axios, { isAxiosError } from 'axios';
2
+ import { productCategorySchema, productSchema, cartSchema, checkoutSchema, storeApiOrderSchema } from '@atomic-solutions/schemas/woocommerce/store-api';
2
3
  import { z } from 'zod';
3
4
 
4
5
  // src/client/createClient.ts
@@ -443,9 +444,9 @@ var setupRequestInterceptor = (axiosInstance, config, client) => {
443
444
  axiosInstance.interceptors.request.use(
444
445
  async (requestConfig) => {
445
446
  const url = requestConfig.url;
446
- if (requiresAuth(url) && config.jwtToken) {
447
+ if (config.jwtToken) {
447
448
  const token = await config.jwtToken.get();
448
- if (token) {
449
+ if (token && (requiresAuth(url) || requiresCartAuth(url))) {
449
450
  requestConfig.headers.Authorization = `Bearer ${token}`;
450
451
  if (config.debug) {
451
452
  debug("Injected JWT token for", url);
@@ -454,10 +455,11 @@ var setupRequestInterceptor = (axiosInstance, config, client) => {
454
455
  }
455
456
  if (requiresCartAuth(url)) {
456
457
  const headers = await config.cartHeaders.get();
458
+ const isAuthenticated = !!await config.jwtToken?.get();
457
459
  if (headers.nonce) {
458
460
  requestConfig.headers.Nonce = headers.nonce;
459
461
  }
460
- if (headers.cartToken) {
462
+ if (headers.cartToken && !isAuthenticated) {
461
463
  requestConfig.headers["Cart-Token"] = headers.cartToken;
462
464
  }
463
465
  requestConfig.headers["Cache-Control"] = "no-cache, no-store, must-revalidate";
@@ -625,694 +627,6 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
625
627
  }
626
628
  );
627
629
  };
628
- var addressSchema = z.object({
629
- /** First name */
630
- first_name: z.string().min(1, "First name is required"),
631
- /** Last name */
632
- last_name: z.string().min(1, "Last name is required"),
633
- /** Company name (optional) */
634
- company: z.string(),
635
- /** Address line 1 */
636
- address_1: z.string().min(1, "Address is required"),
637
- /** Address line 2 (optional) */
638
- address_2: z.string(),
639
- /** City */
640
- city: z.string().min(1, "City is required"),
641
- /** State/Province/Region */
642
- state: z.string(),
643
- /** Postal code */
644
- postcode: z.string().min(1, "Postal code is required"),
645
- /** Country code (ISO 3166-1 alpha-2) */
646
- country: z.string(),
647
- /** Phone number */
648
- phone: z.string().min(1, "Phone number is required")
649
- });
650
- var addressSchemaNonMandatory = z.object({
651
- /** First name */
652
- first_name: z.string(),
653
- /** Last name */
654
- last_name: z.string(),
655
- /** Company name (optional) */
656
- company: z.string(),
657
- /** Address line 1 */
658
- address_1: z.string(),
659
- /** Address line 2 (optional) */
660
- address_2: z.string(),
661
- /** City */
662
- city: z.string(),
663
- /** State/Province/Region */
664
- state: z.string(),
665
- /** Postal code */
666
- postcode: z.string(),
667
- /** Country code (ISO 3166-1 alpha-2) */
668
- country: z.string(),
669
- /** Phone number */
670
- phone: z.string()
671
- });
672
- var billingAddressSchemaMandatory = addressSchema.extend({
673
- /** Email address (required for billing) */
674
- email: z.string().email("Valid email is required")
675
- });
676
- var billingAddressSchemaNonMandatory = addressSchemaNonMandatory.extend({
677
- /** Email address (can be null for guest carts) */
678
- email: z.string().nullable()
679
- });
680
- var moneySchema = z.object({
681
- /** Currency code (e.g., 'USD', 'EUR', 'BAM') */
682
- currency_code: z.string(),
683
- /** Currency symbol (e.g., '$', '€', 'KM') */
684
- currency_symbol: z.string(),
685
- /** Number of decimal places (e.g., 2 for dollars/euros) */
686
- currency_minor_unit: z.number(),
687
- /** Decimal separator character (e.g., '.', ',') */
688
- currency_decimal_separator: z.string(),
689
- /** Thousands separator character (e.g., ',', '.') */
690
- currency_thousand_separator: z.string(),
691
- /** Currency symbol prefix (empty if symbol is suffix) */
692
- currency_prefix: z.string(),
693
- /** Currency symbol suffix (empty if symbol is prefix) */
694
- currency_suffix: z.string()
695
- });
696
- var productImageSchema = z.object({
697
- /** Alternative text for the image */
698
- alt: z.string(),
699
- /** Image unique identifier */
700
- id: z.number(),
701
- /** Image filename */
702
- name: z.string(),
703
- /** Available image sizes in JSON format */
704
- sizes: z.string(),
705
- /** Full-size image URL */
706
- src: z.string().url(),
707
- /** Srcset attribute for responsive images */
708
- srcset: z.string(),
709
- /** Thumbnail image URL */
710
- thumbnail: z.string().url()
711
- });
712
- var cartItemImageSchema = z.object({
713
- /** Image ID */
714
- id: z.number(),
715
- /** Full image URL */
716
- src: z.string(),
717
- /** Thumbnail URL */
718
- thumbnail: z.string(),
719
- /** Responsive image srcset */
720
- srcset: z.string(),
721
- /** Responsive image sizes */
722
- sizes: z.string(),
723
- /** Image name */
724
- name: z.string(),
725
- /** Image alt text */
726
- alt: z.string()
727
- });
728
- var pricesSchema = z.object({
729
- /** Current active price (sale price if on sale, otherwise regular) */
730
- price: z.string(),
731
- /** Regular price (before any discounts) */
732
- regular_price: z.string(),
733
- /** Sale price (empty string if not on sale) */
734
- sale_price: z.string(),
735
- /** Price range for variable products (null for simple products) */
736
- price_range: z.object({
737
- min_amount: z.string(),
738
- max_amount: z.string()
739
- }).nullable(),
740
- /** Raw price data without formatting */
741
- raw_prices: z.object({
742
- /** Decimal precision */
743
- precision: z.number(),
744
- /** Raw price value */
745
- price: z.string(),
746
- /** Raw regular price value */
747
- regular_price: z.string(),
748
- /** Raw sale price value */
749
- sale_price: z.string()
750
- }).optional()
751
- }).merge(moneySchema);
752
-
753
- // src/schemas/store-api/cart-item.schema.ts
754
- var itemTotalsSchema = z.object({
755
- /** Subtotal before taxes */
756
- line_subtotal: z.string(),
757
- /** Tax amount on subtotal */
758
- line_subtotal_tax: z.string(),
759
- /** Total after discounts, before taxes */
760
- line_total: z.string(),
761
- /** Tax amount on total */
762
- line_total_tax: z.string()
763
- }).merge(moneySchema);
764
- var cartItemSchema = z.object({
765
- /** Unique cart item key (use this for update/remove operations) */
766
- key: z.string(),
767
- /** Product ID */
768
- id: z.number(),
769
- /** Quantity of this item in cart */
770
- quantity: z.number(),
771
- /** Quantity limits for this product */
772
- quantity_limits: z.object({
773
- /** Minimum quantity allowed */
774
- minimum: z.number(),
775
- /** Maximum quantity allowed */
776
- maximum: z.number(),
777
- /** Quantity must be multiple of this value */
778
- multiple_of: z.number(),
779
- /** Whether quantity can be changed */
780
- editable: z.boolean()
781
- }),
782
- /** Product name */
783
- name: z.string(),
784
- /** Short product description */
785
- short_description: z.string(),
786
- /** Full product description */
787
- description: z.string(),
788
- /** Product SKU */
789
- sku: z.string(),
790
- /** Remaining stock count if low (null if not low or unlimited) */
791
- low_stock_remaining: z.number().nullable(),
792
- /** Whether backorders are allowed */
793
- backorders_allowed: z.boolean(),
794
- /** Whether to show backorder badge */
795
- show_backorder_badge: z.boolean(),
796
- /** Whether product can only be purchased individually */
797
- sold_individually: z.boolean(),
798
- /** Product permalink URL */
799
- permalink: z.string(),
800
- /** Product images */
801
- images: z.array(cartItemImageSchema),
802
- /** Variation attributes (for variable products) */
803
- variation: z.array(
804
- z.object({
805
- /** Attribute name (e.g., 'Color', 'Size') */
806
- attribute: z.string(),
807
- /** Selected value (e.g., 'Red', 'Large') */
808
- value: z.string()
809
- })
810
- ),
811
- /** Additional item data/metadata */
812
- item_data: z.array(
813
- z.object({
814
- key: z.string(),
815
- value: z.string()
816
- })
817
- ),
818
- /** Product pricing information */
819
- prices: pricesSchema,
820
- /** Line item totals */
821
- totals: itemTotalsSchema,
822
- /** Catalog visibility setting */
823
- catalog_visibility: z.string(),
824
- /** Product type */
825
- type: z.enum(["simple", "variable", "grouped", "external"]),
826
- /** Extension data from plugins */
827
- extensions: z.record(z.string(), z.unknown())
828
- });
829
- var cartTotalsSchema = z.object({
830
- /** Total of all cart items (before discounts and taxes) */
831
- total_items: z.string(),
832
- /** Tax on cart items */
833
- total_items_tax: z.string(),
834
- /** Total fees */
835
- total_fees: z.string(),
836
- /** Tax on fees */
837
- total_fees_tax: z.string(),
838
- /** Total discount amount from coupons */
839
- total_discount: z.string(),
840
- /** Tax on discounts */
841
- total_discount_tax: z.string(),
842
- /** Shipping cost (null if not calculated yet) */
843
- total_shipping: z.string().nullable(),
844
- /** Shipping tax (null if not calculated yet) */
845
- total_shipping_tax: z.string().nullable(),
846
- /** Final total price (includes all taxes and fees) */
847
- total_price: z.string(),
848
- /** Total tax amount */
849
- total_tax: z.string(),
850
- /** Tax breakdown by rate */
851
- tax_lines: z.array(
852
- z.object({
853
- /** Tax rate name */
854
- name: z.string(),
855
- /** Tax amount */
856
- price: z.string(),
857
- /** Tax rate percentage */
858
- rate: z.string()
859
- })
860
- )
861
- }).merge(moneySchema);
862
- var cartCouponSchema = z.object({
863
- /** Coupon code */
864
- code: z.string(),
865
- /** Discount totals for this coupon */
866
- totals: z.object({
867
- /** Total discount amount (before tax) */
868
- total_discount: z.string(),
869
- /** Tax amount on discount */
870
- total_discount_tax: z.string()
871
- }).merge(moneySchema)
872
- });
873
- var shippingRateSchema = z.object({
874
- /** Unique rate identifier (format: instance_id:method_id) */
875
- rate_id: z.string(),
876
- /** Shipping method name */
877
- name: z.string(),
878
- /** Shipping method description */
879
- description: z.string(),
880
- /** Estimated delivery time */
881
- delivery_time: z.string(),
882
- /** Shipping cost */
883
- price: z.string(),
884
- /** Shipping instance ID */
885
- instance_id: z.number(),
886
- /** Shipping method ID */
887
- method_id: z.string(),
888
- /** Additional metadata for this shipping method */
889
- meta_data: z.array(
890
- z.object({
891
- key: z.string(),
892
- value: z.string()
893
- })
894
- ),
895
- /** Whether this rate is currently selected */
896
- selected: z.boolean(),
897
- /** Currency code for the price */
898
- currency_code: z.string(),
899
- /** Currency symbol for the price */
900
- currency_symbol: z.string()
901
- });
902
- var shippingPackageSchema = z.object({
903
- /** Package identifier (0-indexed) */
904
- package_id: z.number(),
905
- /** Package name/label */
906
- name: z.string(),
907
- /** Shipping destination address */
908
- destination: z.object({
909
- address_1: z.string(),
910
- address_2: z.string().optional(),
911
- city: z.string(),
912
- state: z.string(),
913
- postcode: z.string(),
914
- country: z.string()
915
- }),
916
- /** Items included in this package */
917
- items: z.array(
918
- z.object({
919
- /** Cart item key */
920
- key: z.string(),
921
- /** Product name */
922
- name: z.string(),
923
- /** Quantity in package */
924
- quantity: z.number()
925
- })
926
- ),
927
- /** Available shipping rates for this package */
928
- shipping_rates: z.array(shippingRateSchema)
929
- });
930
-
931
- // src/schemas/store-api/cart.ts
932
- var cartSchema = z.object({
933
- items: z.array(cartItemSchema),
934
- items_count: z.number(),
935
- items_weight: z.number(),
936
- needs_payment: z.boolean(),
937
- needs_shipping: z.boolean(),
938
- payment_methods: z.array(z.enum(["cod", "monri"])),
939
- payment_requirements: z.array(z.string()),
940
- has_calculated_shipping: z.boolean(),
941
- shipping_address: addressSchemaNonMandatory,
942
- billing_address: billingAddressSchemaNonMandatory,
943
- shipping_rates: z.array(shippingPackageSchema),
944
- coupons: z.array(cartCouponSchema),
945
- totals: cartTotalsSchema,
946
- errors: z.array(
947
- z.object({
948
- code: z.string(),
949
- message: z.string()
950
- })
951
- ),
952
- extensions: z.record(z.string(), z.unknown()).optional(),
953
- cross_sells: z.array(z.unknown()),
954
- fees: z.array(z.unknown())
955
- });
956
- z.object({
957
- id: z.number(),
958
- quantity: z.number().int().positive(),
959
- variation: z.array(
960
- z.object({
961
- attribute: z.string(),
962
- value: z.string()
963
- })
964
- ).optional()
965
- });
966
- z.object({
967
- key: z.string(),
968
- quantity: z.number().int().positive()
969
- });
970
- z.object({
971
- key: z.string()
972
- });
973
- z.object({
974
- code: z.string().min(1)
975
- });
976
- z.object({
977
- billing_address: billingAddressSchemaMandatory.partial(),
978
- shipping_address: addressSchema.partial()
979
- }).partial();
980
- z.object({
981
- package_id: z.union([z.number(), z.string()]).default(0),
982
- rate_id: z.string()
983
- });
984
- var orderItemImageSchema = z.object({
985
- /** Image ID */
986
- id: z.number(),
987
- /** Full image URL */
988
- src: z.string().url(),
989
- /** Thumbnail URL */
990
- thumbnail: z.string().url(),
991
- /** Responsive image srcset */
992
- srcset: z.string(),
993
- /** Responsive image sizes attribute */
994
- sizes: z.string(),
995
- /** Image name */
996
- name: z.string(),
997
- /** Image alt text */
998
- alt: z.string()
999
- });
1000
- var orderItemPricesSchema = z.object({
1001
- /** Formatted price (current price) */
1002
- price: z.string(),
1003
- /** Formatted regular price */
1004
- regular_price: z.string(),
1005
- /** Formatted sale price */
1006
- sale_price: z.string(),
1007
- /** Price range (null for simple products) */
1008
- price_range: z.null(),
1009
- /** Currency code (e.g., 'USD', 'EUR') */
1010
- currency_code: z.string(),
1011
- /** Currency symbol (e.g., '$', '€') */
1012
- currency_symbol: z.string(),
1013
- /** Number of decimal places for currency */
1014
- currency_minor_unit: z.number(),
1015
- /** Decimal separator (e.g., '.', ',') */
1016
- currency_decimal_separator: z.string(),
1017
- /** Thousand separator (e.g., ',', '.') */
1018
- currency_thousand_separator: z.string(),
1019
- /** Currency prefix (e.g., '$') */
1020
- currency_prefix: z.string(),
1021
- /** Currency suffix (e.g., 'USD') */
1022
- currency_suffix: z.string(),
1023
- /** Raw price values for calculations */
1024
- raw_prices: z.object({
1025
- /** Precision for price calculations */
1026
- precision: z.number(),
1027
- /** Raw price (in minor units) */
1028
- price: z.string(),
1029
- /** Raw regular price (in minor units) */
1030
- regular_price: z.string(),
1031
- /** Raw sale price (in minor units) */
1032
- sale_price: z.string()
1033
- })
1034
- });
1035
- var orderItemTotalsSchema = z.object({
1036
- /** Line subtotal (before discounts) */
1037
- line_subtotal: z.string(),
1038
- /** Line subtotal tax */
1039
- line_subtotal_tax: z.string(),
1040
- /** Line total (after discounts) */
1041
- line_total: z.string(),
1042
- /** Line total tax */
1043
- line_total_tax: z.string(),
1044
- /** Currency code */
1045
- currency_code: z.string(),
1046
- /** Currency symbol */
1047
- currency_symbol: z.string(),
1048
- /** Currency minor unit */
1049
- currency_minor_unit: z.number(),
1050
- /** Decimal separator */
1051
- currency_decimal_separator: z.string(),
1052
- /** Thousand separator */
1053
- currency_thousand_separator: z.string(),
1054
- /** Currency prefix */
1055
- currency_prefix: z.string(),
1056
- /** Currency suffix */
1057
- currency_suffix: z.string()
1058
- });
1059
- var quantityLimitsSchema = z.object({
1060
- /** Minimum quantity allowed */
1061
- minimum: z.number(),
1062
- /** Maximum quantity allowed */
1063
- maximum: z.number(),
1064
- /** Quantity must be multiple of this value */
1065
- multiple_of: z.number(),
1066
- /** Whether quantity is editable */
1067
- editable: z.boolean()
1068
- });
1069
- var orderItemSchema = z.object({
1070
- /** Unique cart/order item key */
1071
- key: z.string(),
1072
- /** Product ID */
1073
- id: z.number(),
1074
- /** Quantity ordered */
1075
- quantity: z.number(),
1076
- /** Quantity limits for this product */
1077
- quantity_limits: quantityLimitsSchema,
1078
- /** Product name */
1079
- name: z.string(),
1080
- /** Short description */
1081
- short_description: z.string(),
1082
- /** Full description */
1083
- description: z.string(),
1084
- /** Product SKU */
1085
- sku: z.string(),
1086
- /** Low stock warning (null if not low) */
1087
- low_stock_remaining: z.null(),
1088
- /** Whether backorders are allowed */
1089
- backorders_allowed: z.boolean(),
1090
- /** Whether to show backorder badge */
1091
- show_backorder_badge: z.boolean(),
1092
- /** Whether product can only be purchased individually */
1093
- sold_individually: z.boolean(),
1094
- /** Product permalink URL */
1095
- permalink: z.string().url(),
1096
- /** Product images */
1097
- images: z.array(orderItemImageSchema),
1098
- /** Variation attributes (empty for simple products) */
1099
- variation: z.array(z.unknown()),
1100
- /** Custom item data/metadata */
1101
- item_data: z.array(z.unknown()),
1102
- /** Price information */
1103
- prices: orderItemPricesSchema,
1104
- /** Totals for this line item */
1105
- totals: orderItemTotalsSchema,
1106
- /** Catalog visibility setting */
1107
- catalog_visibility: z.string()
1108
- });
1109
- var orderTotalsSchema = z.object({
1110
- /** Subtotal (before discounts and fees) */
1111
- subtotal: z.string(),
1112
- /** Total discount amount */
1113
- total_discount: z.string(),
1114
- /** Total shipping cost */
1115
- total_shipping: z.string(),
1116
- /** Total fees */
1117
- total_fees: z.string(),
1118
- /** Total tax */
1119
- total_tax: z.string(),
1120
- /** Total refund amount */
1121
- total_refund: z.string(),
1122
- /** Final total price */
1123
- total_price: z.string(),
1124
- /** Total items cost (subtotal after item-level discounts) */
1125
- total_items: z.string(),
1126
- /** Tax on items */
1127
- total_items_tax: z.string(),
1128
- /** Tax on fees */
1129
- total_fees_tax: z.string(),
1130
- /** Tax on discounts */
1131
- total_discount_tax: z.string(),
1132
- /** Tax on shipping */
1133
- total_shipping_tax: z.string(),
1134
- /** Tax line items breakdown */
1135
- tax_lines: z.array(z.unknown()),
1136
- /** Currency code (e.g., 'USD', 'EUR', 'BAM') */
1137
- currency_code: z.string(),
1138
- /** Currency symbol (e.g., '$', '€', 'KM') */
1139
- currency_symbol: z.string(),
1140
- /** Number of decimal places for currency */
1141
- currency_minor_unit: z.number(),
1142
- /** Decimal separator (e.g., '.', ',') */
1143
- currency_decimal_separator: z.string(),
1144
- /** Thousand separator (e.g., ',', '.') */
1145
- currency_thousand_separator: z.string(),
1146
- /** Currency prefix (e.g., '$') */
1147
- currency_prefix: z.string(),
1148
- /** Currency suffix (e.g., 'USD') */
1149
- currency_suffix: z.string()
1150
- });
1151
-
1152
- // src/schemas/store-api/order.schema.ts
1153
- var orderStatusEnum = z.enum([
1154
- "pending",
1155
- // Order received, awaiting payment
1156
- "processing",
1157
- // Payment received, order is being processed
1158
- "on-hold",
1159
- // Order on hold, awaiting confirmation
1160
- "completed",
1161
- // Order fulfilled and complete
1162
- "cancelled",
1163
- // Order cancelled by customer or admin
1164
- "refunded",
1165
- // Order refunded
1166
- "failed"
1167
- // Payment failed or order declined
1168
- ]);
1169
- var storeApiOrderSchema = z.object({
1170
- /** Order ID */
1171
- id: z.number(),
1172
- /** Order status */
1173
- status: orderStatusEnum,
1174
- /** Order line items (products purchased) */
1175
- items: z.array(orderItemSchema),
1176
- /** Applied coupons */
1177
- coupons: z.array(z.unknown()),
1178
- /** Order fees */
1179
- fees: z.array(z.unknown()),
1180
- /** Order totals breakdown */
1181
- totals: orderTotalsSchema,
1182
- /** Shipping address */
1183
- shipping_address: addressSchema,
1184
- /** Billing address (includes email) */
1185
- billing_address: billingAddressSchemaMandatory,
1186
- /** Whether order still needs payment */
1187
- needs_payment: z.boolean(),
1188
- /** Whether order needs shipping */
1189
- needs_shipping: z.boolean(),
1190
- /** Payment method requirements */
1191
- payment_requirements: z.array(z.string()),
1192
- /** Order errors (if any) */
1193
- errors: z.array(z.unknown()),
1194
- /** Payment method (optional - returned from checkout) */
1195
- payment_method: z.string().optional(),
1196
- /** Payment method title (optional - returned from checkout) */
1197
- payment_method_title: z.string().optional()
1198
- });
1199
- var checkoutSchema = z.object({
1200
- order_id: z.number(),
1201
- status: z.string(),
1202
- order_key: z.string(),
1203
- customer_note: z.string(),
1204
- customer_id: z.number(),
1205
- billing_address: billingAddressSchemaNonMandatory,
1206
- shipping_address: addressSchemaNonMandatory,
1207
- payment_method: z.string(),
1208
- payment_result: z.object({
1209
- payment_status: z.string(),
1210
- payment_details: z.array(z.unknown()),
1211
- redirect_url: z.string()
1212
- })
1213
- });
1214
- z.object({
1215
- payment_method: z.string(),
1216
- payment_data: z.array(
1217
- z.object({
1218
- key: z.string(),
1219
- value: z.union([z.string(), z.boolean()])
1220
- })
1221
- ).optional(),
1222
- billing_address: billingAddressSchemaMandatory.optional(),
1223
- shipping_address: addressSchema.optional(),
1224
- customer_note: z.string().optional(),
1225
- create_account: z.boolean().optional(),
1226
- extensions: z.record(z.string(), z.unknown()).optional()
1227
- });
1228
- var addToCartSchema = z.object({
1229
- /** Description for add to cart action */
1230
- description: z.string(),
1231
- /** Maximum quantity that can be added */
1232
- maximum: z.number(),
1233
- /** Minimum quantity that can be added */
1234
- minimum: z.number(),
1235
- /** Quantity must be a multiple of this number */
1236
- multiple_of: z.number(),
1237
- /** Text for add to cart button */
1238
- text: z.string(),
1239
- /** URL for add to cart action */
1240
- url: z.string()
1241
- });
1242
- var embeddedCategorySchema = z.object({
1243
- /** Category unique identifier */
1244
- id: z.number(),
1245
- /** Category display name */
1246
- name: z.string(),
1247
- /** URL-friendly category identifier */
1248
- slug: z.string(),
1249
- /** Link to category page */
1250
- link: z.string(),
1251
- /** Parent category ID (0 for root categories) - optional in embedded */
1252
- parent: z.number().optional(),
1253
- /** Category description - optional in embedded */
1254
- description: z.string().optional(),
1255
- /** Display type - optional in embedded */
1256
- display: z.string().optional(),
1257
- /** Category image - optional in embedded */
1258
- image: productImageSchema.nullable().optional(),
1259
- /** Menu order for sorting - optional in embedded */
1260
- menu_order: z.number().optional(),
1261
- /** Number of products in this category - optional in embedded */
1262
- count: z.number().optional()
1263
- });
1264
- var productCategorySchema = z.object({
1265
- /** Category unique identifier */
1266
- id: z.number(),
1267
- /** Category display name */
1268
- name: z.string(),
1269
- /** URL-friendly category identifier */
1270
- slug: z.string(),
1271
- /** Parent category ID (0 for root categories) */
1272
- parent: z.number(),
1273
- /** Category description */
1274
- description: z.string(),
1275
- /** Category image */
1276
- image: productImageSchema.nullable(),
1277
- /** Menu order for sorting */
1278
- menu_order: z.number().optional(),
1279
- /** Number of products in this category */
1280
- count: z.number()
1281
- });
1282
-
1283
- // src/schemas/store-api/products.ts
1284
- var productSchema = z.object({
1285
- id: z.number(),
1286
- name: z.string(),
1287
- slug: z.string(),
1288
- type: z.string(),
1289
- variation: z.string(),
1290
- permalink: z.string().url(),
1291
- sku: z.string(),
1292
- short_description: z.string(),
1293
- description: z.string(),
1294
- is_purchasable: z.boolean(),
1295
- is_in_stock: z.boolean(),
1296
- is_on_backorder: z.boolean(),
1297
- low_stock_remaining: z.number().nullable(),
1298
- sold_individually: z.boolean(),
1299
- add_to_cart: addToCartSchema,
1300
- has_options: z.boolean(),
1301
- on_sale: z.boolean(),
1302
- parent: z.number(),
1303
- attributes: z.array(z.unknown()),
1304
- categories: z.array(embeddedCategorySchema),
1305
- tags: z.array(z.unknown()),
1306
- images: z.array(productImageSchema),
1307
- variations: z.array(z.unknown()),
1308
- price_html: z.string(),
1309
- prices: pricesSchema,
1310
- average_rating: z.string(),
1311
- review_count: z.number(),
1312
- extensions: z.record(z.string(), z.unknown())
1313
- });
1314
-
1315
- // src/api/cart.ts
1316
630
  var createCartAPI = (client, endpoints, options) => ({
1317
631
  get: async () => {
1318
632
  const response = await client.get(endpoints.cart);
@@ -1347,8 +661,6 @@ var createCartAPI = (client, endpoints, options) => ({
1347
661
  return handleApiResponse(response, cartSchema, options);
1348
662
  }
1349
663
  });
1350
-
1351
- // src/api/checkout.ts
1352
664
  var createCheckoutAPI = (client, endpoints, options) => ({
1353
665
  get: async () => {
1354
666
  const response = await client.get(endpoints.checkout);
@@ -1359,8 +671,6 @@ var createCheckoutAPI = (client, endpoints, options) => ({
1359
671
  return handleApiResponse(response, checkoutSchema, options);
1360
672
  }
1361
673
  });
1362
-
1363
- // src/api/orders.ts
1364
674
  var createOrdersAPI = (client, endpoints, options) => ({
1365
675
  /**
1366
676
  * Get a single order by ID