@eetech-commerce/cart-react 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -92,6 +92,7 @@ function Shop() {
92
92
  | `useCreateCheckoutSession()` | Create a checkout session |
93
93
  | `useShippingOptions(cartSessionId)` | Fetch available shipping options |
94
94
  | `useUpdateShippingSelections()` | Update selected shipping options |
95
+ | `useShippingRegions()` | Fetch available shipping countries and states |
95
96
 
96
97
  ### Payment Hooks
97
98
 
@@ -334,6 +335,8 @@ import type {
334
335
  ShippingSelectionDto,
335
336
  CreateEmbeddedPaymentSessionDto,
336
337
  EmbeddedPaymentSessionResponseDto,
338
+ ShippingRegionsResponseDto,
339
+ ShippingRegionDto,
337
340
  } from '@eetech-commerce/cart-react';
338
341
  ```
339
342
 
package/dist/index.d.ts CHANGED
@@ -394,6 +394,22 @@ type VerificationResultDto = {
394
394
  */
395
395
  verifiedAt: string;
396
396
  };
397
+ type ShippingRegionDto = {
398
+ /**
399
+ * ISO country code
400
+ */
401
+ countryCode: string;
402
+ /**
403
+ * Available state/province codes. Empty array means all states are valid.
404
+ */
405
+ states: Array<string>;
406
+ };
407
+ type ShippingRegionsResponseDto = {
408
+ /**
409
+ * Available shipping regions grouped by country
410
+ */
411
+ shippingRegions: Array<ShippingRegionDto>;
412
+ };
397
413
  type AddressDto = {
398
414
  /**
399
415
  * Name of the recipient
@@ -897,7 +913,332 @@ declare function useUpdateCheckoutSession(): {
897
913
  isPending: boolean;
898
914
  error: Error | null;
899
915
  };
900
- declare function useShippingOptions(cartSessionId: string | null): _tanstack_react_query.UseQueryResult<ShippingOptionsResponse, Error>;
916
+ declare function useShippingOptions(cartSessionId: string | null): {
917
+ error: Error;
918
+ isError: true;
919
+ isPending: false;
920
+ isLoading: false;
921
+ isLoadingError: false;
922
+ isRefetchError: true;
923
+ isSuccess: false;
924
+ isPlaceholderData: false;
925
+ status: "error";
926
+ dataUpdatedAt: number;
927
+ errorUpdatedAt: number;
928
+ failureCount: number;
929
+ failureReason: Error | null;
930
+ errorUpdateCount: number;
931
+ isFetched: boolean;
932
+ isFetchedAfterMount: boolean;
933
+ isFetching: boolean;
934
+ isInitialLoading: boolean;
935
+ isPaused: boolean;
936
+ isRefetching: boolean;
937
+ isStale: boolean;
938
+ isEnabled: boolean;
939
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingOptionsResponse, Error>>;
940
+ fetchStatus: _tanstack_query_core.FetchStatus;
941
+ promise: Promise<ShippingOptionsResponse>;
942
+ shippingOptions: ShippingOptionsResponse | undefined;
943
+ } | {
944
+ error: null;
945
+ isError: false;
946
+ isPending: false;
947
+ isLoading: false;
948
+ isLoadingError: false;
949
+ isRefetchError: false;
950
+ isSuccess: true;
951
+ isPlaceholderData: false;
952
+ status: "success";
953
+ dataUpdatedAt: number;
954
+ errorUpdatedAt: number;
955
+ failureCount: number;
956
+ failureReason: Error | null;
957
+ errorUpdateCount: number;
958
+ isFetched: boolean;
959
+ isFetchedAfterMount: boolean;
960
+ isFetching: boolean;
961
+ isInitialLoading: boolean;
962
+ isPaused: boolean;
963
+ isRefetching: boolean;
964
+ isStale: boolean;
965
+ isEnabled: boolean;
966
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingOptionsResponse, Error>>;
967
+ fetchStatus: _tanstack_query_core.FetchStatus;
968
+ promise: Promise<ShippingOptionsResponse>;
969
+ shippingOptions: ShippingOptionsResponse | undefined;
970
+ } | {
971
+ error: Error;
972
+ isError: true;
973
+ isPending: false;
974
+ isLoading: false;
975
+ isLoadingError: true;
976
+ isRefetchError: false;
977
+ isSuccess: false;
978
+ isPlaceholderData: false;
979
+ status: "error";
980
+ dataUpdatedAt: number;
981
+ errorUpdatedAt: number;
982
+ failureCount: number;
983
+ failureReason: Error | null;
984
+ errorUpdateCount: number;
985
+ isFetched: boolean;
986
+ isFetchedAfterMount: boolean;
987
+ isFetching: boolean;
988
+ isInitialLoading: boolean;
989
+ isPaused: boolean;
990
+ isRefetching: boolean;
991
+ isStale: boolean;
992
+ isEnabled: boolean;
993
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingOptionsResponse, Error>>;
994
+ fetchStatus: _tanstack_query_core.FetchStatus;
995
+ promise: Promise<ShippingOptionsResponse>;
996
+ shippingOptions: ShippingOptionsResponse | undefined;
997
+ } | {
998
+ error: null;
999
+ isError: false;
1000
+ isPending: true;
1001
+ isLoading: true;
1002
+ isLoadingError: false;
1003
+ isRefetchError: false;
1004
+ isSuccess: false;
1005
+ isPlaceholderData: false;
1006
+ status: "pending";
1007
+ dataUpdatedAt: number;
1008
+ errorUpdatedAt: number;
1009
+ failureCount: number;
1010
+ failureReason: Error | null;
1011
+ errorUpdateCount: number;
1012
+ isFetched: boolean;
1013
+ isFetchedAfterMount: boolean;
1014
+ isFetching: boolean;
1015
+ isInitialLoading: boolean;
1016
+ isPaused: boolean;
1017
+ isRefetching: boolean;
1018
+ isStale: boolean;
1019
+ isEnabled: boolean;
1020
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingOptionsResponse, Error>>;
1021
+ fetchStatus: _tanstack_query_core.FetchStatus;
1022
+ promise: Promise<ShippingOptionsResponse>;
1023
+ shippingOptions: ShippingOptionsResponse | undefined;
1024
+ } | {
1025
+ error: null;
1026
+ isError: false;
1027
+ isPending: true;
1028
+ isLoadingError: false;
1029
+ isRefetchError: false;
1030
+ isSuccess: false;
1031
+ isPlaceholderData: false;
1032
+ status: "pending";
1033
+ dataUpdatedAt: number;
1034
+ errorUpdatedAt: number;
1035
+ failureCount: number;
1036
+ failureReason: Error | null;
1037
+ errorUpdateCount: number;
1038
+ isFetched: boolean;
1039
+ isFetchedAfterMount: boolean;
1040
+ isFetching: boolean;
1041
+ isLoading: boolean;
1042
+ isInitialLoading: boolean;
1043
+ isPaused: boolean;
1044
+ isRefetching: boolean;
1045
+ isStale: boolean;
1046
+ isEnabled: boolean;
1047
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingOptionsResponse, Error>>;
1048
+ fetchStatus: _tanstack_query_core.FetchStatus;
1049
+ promise: Promise<ShippingOptionsResponse>;
1050
+ shippingOptions: ShippingOptionsResponse | undefined;
1051
+ } | {
1052
+ isError: false;
1053
+ error: null;
1054
+ isPending: false;
1055
+ isLoading: false;
1056
+ isLoadingError: false;
1057
+ isRefetchError: false;
1058
+ isSuccess: true;
1059
+ isPlaceholderData: true;
1060
+ status: "success";
1061
+ dataUpdatedAt: number;
1062
+ errorUpdatedAt: number;
1063
+ failureCount: number;
1064
+ failureReason: Error | null;
1065
+ errorUpdateCount: number;
1066
+ isFetched: boolean;
1067
+ isFetchedAfterMount: boolean;
1068
+ isFetching: boolean;
1069
+ isInitialLoading: boolean;
1070
+ isPaused: boolean;
1071
+ isRefetching: boolean;
1072
+ isStale: boolean;
1073
+ isEnabled: boolean;
1074
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingOptionsResponse, Error>>;
1075
+ fetchStatus: _tanstack_query_core.FetchStatus;
1076
+ promise: Promise<ShippingOptionsResponse>;
1077
+ shippingOptions: ShippingOptionsResponse | undefined;
1078
+ };
1079
+ declare function useShippingRegions(): {
1080
+ error: Error;
1081
+ isError: true;
1082
+ isPending: false;
1083
+ isLoading: false;
1084
+ isLoadingError: false;
1085
+ isRefetchError: true;
1086
+ isSuccess: false;
1087
+ isPlaceholderData: false;
1088
+ status: "error";
1089
+ dataUpdatedAt: number;
1090
+ errorUpdatedAt: number;
1091
+ failureCount: number;
1092
+ failureReason: Error | null;
1093
+ errorUpdateCount: number;
1094
+ isFetched: boolean;
1095
+ isFetchedAfterMount: boolean;
1096
+ isFetching: boolean;
1097
+ isInitialLoading: boolean;
1098
+ isPaused: boolean;
1099
+ isRefetching: boolean;
1100
+ isStale: boolean;
1101
+ isEnabled: boolean;
1102
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingRegionsResponseDto, Error>>;
1103
+ fetchStatus: _tanstack_query_core.FetchStatus;
1104
+ promise: Promise<ShippingRegionsResponseDto>;
1105
+ shippingRegions: ShippingRegionsResponseDto | undefined;
1106
+ } | {
1107
+ error: null;
1108
+ isError: false;
1109
+ isPending: false;
1110
+ isLoading: false;
1111
+ isLoadingError: false;
1112
+ isRefetchError: false;
1113
+ isSuccess: true;
1114
+ isPlaceholderData: false;
1115
+ status: "success";
1116
+ dataUpdatedAt: number;
1117
+ errorUpdatedAt: number;
1118
+ failureCount: number;
1119
+ failureReason: Error | null;
1120
+ errorUpdateCount: number;
1121
+ isFetched: boolean;
1122
+ isFetchedAfterMount: boolean;
1123
+ isFetching: boolean;
1124
+ isInitialLoading: boolean;
1125
+ isPaused: boolean;
1126
+ isRefetching: boolean;
1127
+ isStale: boolean;
1128
+ isEnabled: boolean;
1129
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingRegionsResponseDto, Error>>;
1130
+ fetchStatus: _tanstack_query_core.FetchStatus;
1131
+ promise: Promise<ShippingRegionsResponseDto>;
1132
+ shippingRegions: ShippingRegionsResponseDto | undefined;
1133
+ } | {
1134
+ error: Error;
1135
+ isError: true;
1136
+ isPending: false;
1137
+ isLoading: false;
1138
+ isLoadingError: true;
1139
+ isRefetchError: false;
1140
+ isSuccess: false;
1141
+ isPlaceholderData: false;
1142
+ status: "error";
1143
+ dataUpdatedAt: number;
1144
+ errorUpdatedAt: number;
1145
+ failureCount: number;
1146
+ failureReason: Error | null;
1147
+ errorUpdateCount: number;
1148
+ isFetched: boolean;
1149
+ isFetchedAfterMount: boolean;
1150
+ isFetching: boolean;
1151
+ isInitialLoading: boolean;
1152
+ isPaused: boolean;
1153
+ isRefetching: boolean;
1154
+ isStale: boolean;
1155
+ isEnabled: boolean;
1156
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingRegionsResponseDto, Error>>;
1157
+ fetchStatus: _tanstack_query_core.FetchStatus;
1158
+ promise: Promise<ShippingRegionsResponseDto>;
1159
+ shippingRegions: ShippingRegionsResponseDto | undefined;
1160
+ } | {
1161
+ error: null;
1162
+ isError: false;
1163
+ isPending: true;
1164
+ isLoading: true;
1165
+ isLoadingError: false;
1166
+ isRefetchError: false;
1167
+ isSuccess: false;
1168
+ isPlaceholderData: false;
1169
+ status: "pending";
1170
+ dataUpdatedAt: number;
1171
+ errorUpdatedAt: number;
1172
+ failureCount: number;
1173
+ failureReason: Error | null;
1174
+ errorUpdateCount: number;
1175
+ isFetched: boolean;
1176
+ isFetchedAfterMount: boolean;
1177
+ isFetching: boolean;
1178
+ isInitialLoading: boolean;
1179
+ isPaused: boolean;
1180
+ isRefetching: boolean;
1181
+ isStale: boolean;
1182
+ isEnabled: boolean;
1183
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingRegionsResponseDto, Error>>;
1184
+ fetchStatus: _tanstack_query_core.FetchStatus;
1185
+ promise: Promise<ShippingRegionsResponseDto>;
1186
+ shippingRegions: ShippingRegionsResponseDto | undefined;
1187
+ } | {
1188
+ error: null;
1189
+ isError: false;
1190
+ isPending: true;
1191
+ isLoadingError: false;
1192
+ isRefetchError: false;
1193
+ isSuccess: false;
1194
+ isPlaceholderData: false;
1195
+ status: "pending";
1196
+ dataUpdatedAt: number;
1197
+ errorUpdatedAt: number;
1198
+ failureCount: number;
1199
+ failureReason: Error | null;
1200
+ errorUpdateCount: number;
1201
+ isFetched: boolean;
1202
+ isFetchedAfterMount: boolean;
1203
+ isFetching: boolean;
1204
+ isLoading: boolean;
1205
+ isInitialLoading: boolean;
1206
+ isPaused: boolean;
1207
+ isRefetching: boolean;
1208
+ isStale: boolean;
1209
+ isEnabled: boolean;
1210
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingRegionsResponseDto, Error>>;
1211
+ fetchStatus: _tanstack_query_core.FetchStatus;
1212
+ promise: Promise<ShippingRegionsResponseDto>;
1213
+ shippingRegions: ShippingRegionsResponseDto | undefined;
1214
+ } | {
1215
+ isError: false;
1216
+ error: null;
1217
+ isPending: false;
1218
+ isLoading: false;
1219
+ isLoadingError: false;
1220
+ isRefetchError: false;
1221
+ isSuccess: true;
1222
+ isPlaceholderData: true;
1223
+ status: "success";
1224
+ dataUpdatedAt: number;
1225
+ errorUpdatedAt: number;
1226
+ failureCount: number;
1227
+ failureReason: Error | null;
1228
+ errorUpdateCount: number;
1229
+ isFetched: boolean;
1230
+ isFetchedAfterMount: boolean;
1231
+ isFetching: boolean;
1232
+ isInitialLoading: boolean;
1233
+ isPaused: boolean;
1234
+ isRefetching: boolean;
1235
+ isStale: boolean;
1236
+ isEnabled: boolean;
1237
+ refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<ShippingRegionsResponseDto, Error>>;
1238
+ fetchStatus: _tanstack_query_core.FetchStatus;
1239
+ promise: Promise<ShippingRegionsResponseDto>;
1240
+ shippingRegions: ShippingRegionsResponseDto | undefined;
1241
+ };
901
1242
  interface UpdateShippingSelectionsParams {
902
1243
  selections: ShippingSelectionDto[];
903
1244
  }
@@ -952,4 +1293,4 @@ interface CartProviderProps {
952
1293
  }
953
1294
  declare function CartProvider({ children, tenantSlug, cartApiUrl, storageAdapter, autoInitialize, queryClient, }: CartProviderProps): react_jsx_runtime.JSX.Element;
954
1295
 
955
- export { type CartContextValue, CartProvider, type CartProviderProps, type CartResponseDto, type CreateCheckoutDto, type CreateEmbeddedPaymentSessionDto, type EmbeddedPaymentSessionResponseDto, type LineItemResponseDto, type LoadStripeFn, type MutationCallbacks, type ShippingOptionDto, type ShippingSelectionDto, type StorageAdapter, type UpdateCheckoutDto, type VerificationResultDto, cartKeys, localStorageAdapter, paymentKeys, shippingKeys, useAddToCart, useCart, useCartContext, useClearCart, useCreateCart, useCreateCheckoutSession, useCreateEmbeddedCheckoutSession, useInitializeCart, usePaymentSession, useRemoveItem, useShippingOptions, useStripePromise, useUpdateCheckoutSession, useUpdateItemQty, useUpdateShippingSelections, useVerifyCart };
1296
+ export { type CartContextValue, CartProvider, type CartProviderProps, type CartResponseDto, type CreateCheckoutDto, type CreateEmbeddedPaymentSessionDto, type EmbeddedPaymentSessionResponseDto, type LineItemResponseDto, type LoadStripeFn, type MutationCallbacks, type ShippingOptionDto, type ShippingRegionDto, type ShippingRegionsResponseDto, type ShippingSelectionDto, type StorageAdapter, type UpdateCheckoutDto, type VerificationResultDto, cartKeys, localStorageAdapter, paymentKeys, shippingKeys, useAddToCart, useCart, useCartContext, useClearCart, useCreateCart, useCreateCheckoutSession, useCreateEmbeddedCheckoutSession, useInitializeCart, usePaymentSession, useRemoveItem, useShippingOptions, useShippingRegions, useStripePromise, useUpdateCheckoutSession, useUpdateItemQty, useUpdateShippingSelections, useVerifyCart };
package/dist/index.js CHANGED
@@ -917,6 +917,12 @@ var checkoutControllerVerifyCartV1 = (options) => {
917
917
  }
918
918
  });
919
919
  };
920
+ var checkoutControllerGetShippingRegionsV1 = (options) => {
921
+ return (options.client ?? client).get({
922
+ url: "/v1/t/{tenantSlug}/checkout/shipping-regions",
923
+ ...options
924
+ });
925
+ };
920
926
  var checkoutControllerUpdateCheckoutSessionV1 = (options) => {
921
927
  return (options.client ?? client).patch({
922
928
  url: "/v1/t/{tenantSlug}/checkout/{cartSessionId}",
@@ -1092,6 +1098,19 @@ var checkoutControllerVerifyCartV1Mutation = (options) => {
1092
1098
  };
1093
1099
  return mutationOptions;
1094
1100
  };
1101
+ var checkoutControllerGetShippingRegionsV1QueryKey = (options) => createQueryKey("checkoutControllerGetShippingRegionsV1", options);
1102
+ var checkoutControllerGetShippingRegionsV1Options = (options) => queryOptions({
1103
+ queryFn: async ({ queryKey, signal }) => {
1104
+ const { data } = await checkoutControllerGetShippingRegionsV1({
1105
+ ...options,
1106
+ ...queryKey[0],
1107
+ signal,
1108
+ throwOnError: true
1109
+ });
1110
+ return data;
1111
+ },
1112
+ queryKey: checkoutControllerGetShippingRegionsV1QueryKey(options)
1113
+ });
1095
1114
  var checkoutControllerUpdateCheckoutSessionV1Mutation = (options) => {
1096
1115
  const mutationOptions = {
1097
1116
  mutationFn: async (fnOptions) => {
@@ -1523,7 +1542,7 @@ function useUpdateCheckoutSession() {
1523
1542
  }
1524
1543
  function useShippingOptions(cartSessionId) {
1525
1544
  const { tenantSlug, cartApiUrl } = useCartContext();
1526
- return useQuery2({
1545
+ const { data, ...rest } = useQuery2({
1527
1546
  ...checkoutControllerGetShippingOptionsV1Options({
1528
1547
  path: {
1529
1548
  tenantSlug,
@@ -1533,6 +1552,17 @@ function useShippingOptions(cartSessionId) {
1533
1552
  }),
1534
1553
  enabled: !!cartSessionId
1535
1554
  });
1555
+ return { shippingOptions: data, ...rest };
1556
+ }
1557
+ function useShippingRegions() {
1558
+ const { tenantSlug, cartApiUrl } = useCartContext();
1559
+ const { data, ...rest } = useQuery2({
1560
+ ...checkoutControllerGetShippingRegionsV1Options({
1561
+ path: { tenantSlug },
1562
+ baseUrl: cartApiUrl
1563
+ })
1564
+ });
1565
+ return { shippingRegions: data, ...rest };
1536
1566
  }
1537
1567
  function useUpdateShippingSelections() {
1538
1568
  const { tenantSlug, cartApiUrl, cartSessionId } = useCartContext();
@@ -1733,6 +1763,7 @@ export {
1733
1763
  usePaymentSession,
1734
1764
  useRemoveItem,
1735
1765
  useShippingOptions,
1766
+ useShippingRegions,
1736
1767
  useStripePromise,
1737
1768
  useUpdateCheckoutSession,
1738
1769
  useUpdateItemQty,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eetech-commerce/cart-react",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"