@kasuvia/sdk 0.0.8 → 0.0.9

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 (176) hide show
  1. package/README.md +42 -15
  2. package/dist/AddressAutocomplete-CjcqPElD.d.mts +46 -0
  3. package/dist/AddressAutocomplete-CvJHuRkf.d.ts +46 -0
  4. package/dist/components/index.d.mts +497 -0
  5. package/dist/components/index.d.ts +497 -0
  6. package/dist/components/index.js +4217 -0
  7. package/dist/components/index.js.map +1 -0
  8. package/dist/components/index.mjs +4194 -0
  9. package/dist/components/index.mjs.map +1 -0
  10. package/dist/config/server.d.mts +26 -0
  11. package/dist/config/server.d.ts +26 -0
  12. package/dist/config/server.js +38 -0
  13. package/dist/config/server.js.map +1 -0
  14. package/dist/config/server.mjs +13 -0
  15. package/dist/config/server.mjs.map +1 -0
  16. package/dist/hooks/index.d.mts +393 -160
  17. package/dist/hooks/index.d.ts +393 -160
  18. package/dist/hooks/index.js +2792 -2137
  19. package/dist/hooks/index.js.map +1 -1
  20. package/dist/hooks/index.mjs +2734 -2121
  21. package/dist/hooks/index.mjs.map +1 -1
  22. package/dist/index-CNW_LINy.d.mts +578 -0
  23. package/dist/index-CNW_LINy.d.ts +578 -0
  24. package/dist/{index-C1chUA3P.d.mts → index-F7N6UItS.d.mts} +1 -1
  25. package/dist/{index-C1chUA3P.d.ts → index-F7N6UItS.d.ts} +1 -1
  26. package/dist/index-NkI10J_E.d.mts +40 -0
  27. package/dist/index-NkI10J_E.d.ts +40 -0
  28. package/dist/index.d.mts +20437 -103
  29. package/dist/index.d.ts +20437 -103
  30. package/dist/index.js +2111 -1802
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +2006 -1786
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/media.service-Cx7dQjzX.d.mts +1393 -0
  35. package/dist/media.service-mrBFJ2UQ.d.ts +1393 -0
  36. package/dist/services/index.d.mts +908 -2
  37. package/dist/services/index.d.ts +908 -2
  38. package/dist/services/index.js +1492 -1686
  39. package/dist/services/index.js.map +1 -1
  40. package/dist/services/index.mjs +1431 -1670
  41. package/dist/services/index.mjs.map +1 -1
  42. package/package.json +46 -6
  43. package/src/components/bespoke/BespokeAvailabilityBadge.tsx +32 -0
  44. package/src/components/bespoke/BespokeProgressTracker.tsx +58 -0
  45. package/src/components/bespoke/index.ts +3 -0
  46. package/src/components/booking/SlotPicker.tsx +97 -0
  47. package/src/components/booking/index.ts +1 -0
  48. package/src/components/cart/CartItem.tsx +81 -0
  49. package/src/components/cart/CartSidebar.tsx +115 -0
  50. package/src/components/cart/CartTypeMismatchBanner.tsx +55 -0
  51. package/src/components/cart/index.ts +3 -0
  52. package/src/components/index.ts +8 -0
  53. package/src/components/orders/DeliverableReviewer.tsx +139 -0
  54. package/src/components/orders/index.ts +1 -0
  55. package/src/components/product/ProductCard.tsx +350 -0
  56. package/src/components/product/ProductGrid.tsx +84 -0
  57. package/src/components/product/index.ts +2 -0
  58. package/src/components/shared/AddressAutocomplete.tsx +212 -0
  59. package/src/components/shared/AnalyticsScripts.tsx +56 -0
  60. package/src/components/shared/CookieConsentBanner.tsx +98 -0
  61. package/src/components/shared/ImageEditorModal.tsx +1066 -0
  62. package/src/components/shared/ImageViewerModal.tsx +598 -0
  63. package/src/components/shared/LucideReactIcon.tsx +52 -0
  64. package/src/components/shared/MapPinDrop.tsx +101 -0
  65. package/src/components/shared/MultiSelectPicker.tsx +193 -0
  66. package/src/components/shared/OfflineBanner.tsx +46 -0
  67. package/src/components/shared/SearchableInput.tsx +153 -0
  68. package/src/components/shared/SearchablePopover.tsx +166 -0
  69. package/src/components/shared/SmartImage.tsx +311 -0
  70. package/src/components/shared/TruncatedValue.tsx +27 -0
  71. package/src/components/shared/UnsavedChangesGuard.tsx +138 -0
  72. package/src/components/shared/index.ts +15 -0
  73. package/src/components/skeletons/CardSkeleton.tsx +26 -0
  74. package/src/components/skeletons/CartItemSkeleton.tsx +26 -0
  75. package/src/components/skeletons/OrderItemSkeleton.tsx +26 -0
  76. package/src/components/skeletons/ProductCardSkeleton.tsx +26 -0
  77. package/src/components/skeletons/TableSkeleton.tsx +42 -0
  78. package/src/components/skeletons/index.ts +5 -0
  79. package/src/config/index.ts +22 -4
  80. package/src/config/server.ts +45 -0
  81. package/src/context/sdk-context.tsx +5 -2
  82. package/src/generated/auth-openapi.ts +2935 -0
  83. package/src/generated/cart-openapi.ts +652 -0
  84. package/src/generated/cms-openapi.ts +1668 -0
  85. package/src/generated/crm-openapi.ts +986 -0
  86. package/src/generated/graphql.ts +126 -0
  87. package/src/generated/index.ts +11 -0
  88. package/src/generated/media-openapi.ts +613 -0
  89. package/src/generated/notification-openapi.ts +862 -0
  90. package/src/generated/payment-openapi.ts +2713 -0
  91. package/src/generated/store-openapi.ts +9510 -0
  92. package/src/graphql/operations/collections.graphql +32 -0
  93. package/src/graphql/operations/products.graphql +197 -0
  94. package/src/graphql/operations/wishlist.graphql +25 -0
  95. package/src/hooks/index.ts +9 -2
  96. package/src/hooks/use-auth.ts +163 -69
  97. package/src/hooks/use-bespoke-availability.ts +39 -22
  98. package/src/hooks/use-business-config.ts +51 -0
  99. package/src/hooks/use-cart.ts +310 -238
  100. package/src/hooks/use-cms.ts +107 -127
  101. package/src/hooks/use-collections.ts +35 -55
  102. package/src/hooks/use-consultations.ts +9 -136
  103. package/src/hooks/use-countries.ts +19 -28
  104. package/src/hooks/use-currencies.ts +8 -20
  105. package/src/hooks/use-customer-address.ts +64 -0
  106. package/src/hooks/use-feedback.ts +34 -0
  107. package/src/hooks/use-languages.ts +26 -39
  108. package/src/hooks/use-media-upload.ts +23 -0
  109. package/src/hooks/use-notification-stream.ts +88 -0
  110. package/src/hooks/use-notifications.ts +163 -0
  111. package/src/hooks/use-order-stream.ts +29 -29
  112. package/src/hooks/use-orders.ts +91 -73
  113. package/src/hooks/use-payment.ts +116 -84
  114. package/src/hooks/use-products.ts +65 -269
  115. package/src/hooks/use-push-notifications.ts +122 -0
  116. package/src/hooks/use-reviews.ts +175 -0
  117. package/src/hooks/use-service-booking.ts +109 -132
  118. package/src/hooks/use-states.ts +16 -30
  119. package/src/hooks/use-wishlist.ts +44 -69
  120. package/src/index.ts +15 -11
  121. package/src/services/auth.service.ts +422 -132
  122. package/src/services/bespoke.service.ts +69 -10
  123. package/src/services/cart.service.ts +155 -186
  124. package/src/services/cms.service.ts +41 -50
  125. package/src/services/collection.service.ts +25 -63
  126. package/src/services/config.service.ts +10 -21
  127. package/src/services/consultation.service.ts +36 -93
  128. package/src/services/feedback.service.ts +76 -0
  129. package/src/services/index.ts +7 -1
  130. package/src/services/legal.service.ts +62 -0
  131. package/src/services/logistics.service.ts +235 -53
  132. package/src/services/media.service.ts +115 -0
  133. package/src/services/notifications.service.ts +204 -20
  134. package/src/services/order.service.ts +498 -127
  135. package/src/services/payment.service.ts +149 -100
  136. package/src/services/product.service.ts +157 -814
  137. package/src/services/review.service.ts +211 -0
  138. package/src/services/service-booking.service.ts +198 -99
  139. package/src/services/wishlist.service.ts +27 -74
  140. package/src/types/auth/index.ts +161 -18
  141. package/src/types/business/index.ts +9 -1
  142. package/src/types/cms/index.ts +91 -6
  143. package/src/types/cms/legal.ts +18 -0
  144. package/src/types/consultations/index.ts +60 -68
  145. package/src/types/index.ts +5 -3
  146. package/src/types/media/index.ts +35 -3
  147. package/src/types/payments/index.ts +80 -16
  148. package/src/types/reviews/index.ts +116 -0
  149. package/src/types/services/index.ts +113 -38
  150. package/src/types/store/checkout.ts +53 -0
  151. package/src/types/store/index.ts +273 -52
  152. package/src/types/store/invoice.ts +31 -0
  153. package/src/types/store/shipping.ts +84 -3
  154. package/src/types/ui/index.ts +1 -1
  155. package/src/utils/checkout.ts +19 -3
  156. package/src/utils/cookieConsent.ts +34 -0
  157. package/src/utils/format.ts +408 -0
  158. package/src/utils/geolocation.ts +134 -0
  159. package/src/utils/graphql-url.ts +47 -0
  160. package/src/utils/guest-session.ts +59 -0
  161. package/src/utils/http-client.ts +147 -0
  162. package/src/utils/index.ts +11 -4
  163. package/src/utils/status-colors.ts +79 -0
  164. package/src/utils/token-refresh.ts +115 -0
  165. package/src/utils/validators.ts +13 -0
  166. package/src/utils/youtube.ts +18 -0
  167. package/dist/index-C5YO9gTl.d.mts +0 -507
  168. package/dist/index-C5YO9gTl.d.ts +0 -507
  169. package/dist/index-CefG7_xq.d.mts +0 -793
  170. package/dist/index-DeHCf3zI.d.ts +0 -793
  171. package/src/graphql/collections.graphql.ts +0 -48
  172. package/src/graphql/index.ts +0 -7
  173. package/src/graphql/products.graphql.ts +0 -860
  174. package/src/graphql/wishlist.graphql.ts +0 -34
  175. package/src/hooks/use-consultation-stream.ts +0 -142
  176. package/src/types/bespoke/index.ts +0 -39
@@ -5,34 +5,34 @@
5
5
  * config and accessToken are optional — if omitted, they are read from SdkContext.
6
6
  */
7
7
  import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
8
- import { getOrders, findOrder, createOrder, cancelOrder, trackOrder } from '../services/order.service'
8
+ import { getOrders, findOrder, createOrder, cancelOrder, trackOrder, createBespokeOrder, createServiceBookingOrder } from '../services/order.service'
9
9
  import type { FindOrderParams, CreateOrderParams } from '../types/store'
10
+ import type { CreateBespokeOrderParams, CreateServiceBookingOrderParams } from '../services/order.service'
10
11
  import type { SdkConfig } from '../config'
11
- import { logger } from '../utils'
12
12
  import { useSdkContext, resolveHookArgs } from '../context/sdk-context'
13
13
 
14
- export function useOrders(arg1?: SdkConfig | { page?: number; pageSize?: number }, arg2?: string | null, arg3?: { page?: number; pageSize?: number }) {
14
+ // REAL BUG FIXED (2026-09-21): this used `pageSize` (camelCase), but the
15
+ // real `getOrders` param it's forwarded to reads `page_size` (snake_case,
16
+ // matching every other Kasuvia paginated endpoint) — the value was silently
17
+ // dropped on every call, always falling back to the backend's default page
18
+ // size instead of the caller's requested one.
19
+ export function useOrders(arg1?: SdkConfig | { page?: number; page_size?: number }, arg2?: string | null, arg3?: { page?: number; page_size?: number }) {
15
20
  const ctx = useSdkContext()
16
21
  const isArg1Config = typeof arg1 === 'object' && arg1 !== null && 'businessId' in arg1
17
22
  const explicitConfig = isArg1Config ? (arg1 as SdkConfig) : undefined
18
23
  const explicitToken = isArg1Config ? arg2 : undefined
19
- const params = isArg1Config ? arg3 : (arg1 as { page?: number; pageSize?: number } | undefined)
24
+ const params = isArg1Config ? arg3 : (arg1 as { page?: number; page_size?: number } | undefined)
20
25
 
21
- try {
22
- const { config: cfg, accessToken: token } = resolveHookArgs(explicitConfig, explicitToken, ctx)
23
- return useQuery({
24
- queryKey: ['orders', params],
25
- queryFn: () => token ? getOrders(cfg, token, params || {}) : Promise.resolve(undefined),
26
- enabled: !!token,
27
- })
28
- } catch (error) {
29
- logger.warn('[useOrders] Called outside QueryClientProvider, returning empty list')
30
- return { data: undefined, isLoading: false, error: null, isFetching: false, refetch: () => Promise.resolve({ data: undefined }) } as any
31
- }
26
+ const { config: cfg, accessToken: token } = resolveHookArgs(explicitConfig, explicitToken, ctx)
27
+ return useQuery({
28
+ queryKey: ['orders', params],
29
+ queryFn: () => token ? getOrders(cfg, token, params || {}) : Promise.reject(new Error('No access token available')),
30
+ enabled: !!token,
31
+ })
32
32
  }
33
33
 
34
- export function useOrdersList(arg1?: any, arg2?: any, arg3?: any) {
35
- return useOrders(arg1, arg2, arg3)
34
+ export function useOrdersList(arg1?: unknown, arg2?: unknown, arg3?: unknown) {
35
+ return useOrders(arg1 as SdkConfig, arg2 as string, arg3 as { page?: number; page_size?: number })
36
36
  }
37
37
 
38
38
  export function useFindOrder(arg1?: SdkConfig | string | FindOrderParams, arg2?: FindOrderParams) {
@@ -45,75 +45,93 @@ export function useFindOrder(arg1?: SdkConfig | string | FindOrderParams, arg2?:
45
45
  ? { order_id: arg1, email: '' }
46
46
  : (arg1 as FindOrderParams | undefined)
47
47
 
48
- try {
49
- const { config: cfg } = resolveHookArgs(explicitConfig, undefined, ctx)
50
- return useQuery({
51
- queryKey: ['order', params],
52
- queryFn: () => params ? findOrder(cfg, params) : Promise.resolve(undefined),
53
- enabled: !!params?.order_id,
54
- })
55
- } catch (error) {
56
- logger.warn('[useFindOrder] Called outside QueryClientProvider, returning undefined')
57
- return { data: undefined, isLoading: false, error: null, isFetching: false, refetch: () => Promise.resolve({ data: undefined }) } as any
58
- }
48
+ const { config: cfg } = resolveHookArgs(explicitConfig, undefined, ctx)
49
+ return useQuery({
50
+ queryKey: ['order', params],
51
+ queryFn: () => params ? findOrder(cfg, params) : Promise.reject(new Error('Missing search parameters')),
52
+ // findOrder's real backend contract (POST /orders/track) requires both
53
+ // order_id and email — matches that instead of firing on order_id alone.
54
+ enabled: !!params?.order_id && !!params?.email,
55
+ })
59
56
  }
60
57
 
61
58
  export function useOrder(arg1?: SdkConfig | string | FindOrderParams, arg2?: FindOrderParams) {
62
59
  return useFindOrder(arg1, arg2)
63
60
  }
64
61
 
65
- export function useOrderTracking(arg1?: SdkConfig | string, arg2?: string, arg3?: string) {
62
+ /**
63
+ * REAL BUG FIXED (2026-09-22): took an arbitrary "guestToken" string —
64
+ * trackOrder's real backend endpoint (GET /orders/{id}) has no guest-token
65
+ * concept at all, it requires a genuine authenticated JWT belonging to the
66
+ * order's own customer (see trackOrder's doc comment). Resolves a real
67
+ * accessToken from SdkContext like every other authenticated hook instead.
68
+ */
69
+ export function useOrderTracking(config?: SdkConfig, accessToken?: string | null, orderId?: string) {
66
70
  const ctx = useSdkContext()
67
- const isArg1Config = typeof arg1 === 'object' && arg1 !== null && 'businessId' in arg1
68
- const explicitConfig = isArg1Config ? (arg1 as SdkConfig) : undefined
69
- const orderId = isArg1Config ? arg2 : (typeof arg1 === 'string' ? arg1 : undefined)
70
- const guestToken = isArg1Config ? arg3 : (typeof arg2 === 'string' ? arg2 : undefined)
71
-
72
- try {
73
- const { config: cfg } = resolveHookArgs(explicitConfig, undefined, ctx)
74
- return useQuery({
75
- queryKey: ['order-tracking', orderId, guestToken],
76
- queryFn: () => trackOrder(cfg, orderId!, guestToken),
77
- enabled: !!orderId,
78
- refetchInterval: 30000,
79
- })
80
- } catch (error) {
81
- logger.warn('[useOrderTracking] Called outside QueryClientProvider, returning undefined')
82
- return { data: undefined, isLoading: false, error: null, isFetching: false, refetch: () => Promise.resolve({ data: undefined }) } as any
83
- }
71
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx)
72
+ return useQuery({
73
+ queryKey: ['order-tracking', orderId],
74
+ queryFn: () => token && orderId ? trackOrder(cfg, orderId, token) : Promise.reject(new Error('Missing order ID or access token')),
75
+ enabled: !!orderId && !!token,
76
+ refetchInterval: 30000,
77
+ })
84
78
  }
85
79
 
80
+ /**
81
+ * REAL BUG FIXED (2026-09-22): passed `token || ''` — an empty string
82
+ * `accessToken`, which used to produce a malformed `Authorization: Bearer `
83
+ * header instead of genuinely omitting it. Combined with createOrder's own
84
+ * fix (see its doc comment), guest checkout through this hook has never
85
+ * actually worked even though the real backend endpoint was built to
86
+ * support it via X-Guest-Session — the same guestSessionId SdkContext
87
+ * already resolves for every useCart() call site now also reaches here.
88
+ */
86
89
  export function useCreateOrder(config?: SdkConfig, accessToken?: string | null) {
87
90
  const ctx = useSdkContext()
88
- try {
89
- const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx)
90
- const queryClient = useQueryClient()
91
- return useMutation({
92
- mutationFn: (payload: CreateOrderParams) => createOrder(cfg, token || '', payload),
93
- onSuccess: () => {
94
- queryClient.invalidateQueries({ queryKey: ['orders'] })
95
- },
96
- })
97
- } catch (error) {
98
- logger.warn('[useCreateOrder] Called outside QueryClientProvider, returning no-op mutation')
99
- return { mutate: () => {}, mutateAsync: () => Promise.resolve(undefined) } as any
100
- }
91
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx)
92
+ const guestSessionId = ctx?.guestSessionId ?? undefined
93
+ const queryClient = useQueryClient()
94
+ return useMutation({
95
+ mutationFn: (payload: CreateOrderParams) => createOrder(cfg, token ?? undefined, payload, guestSessionId),
96
+ onSuccess: () => {
97
+ queryClient.invalidateQueries({ queryKey: ['orders'] })
98
+ },
99
+ })
100
+ }
101
+
102
+ export function useCreateBespokeOrder(config?: SdkConfig, accessToken?: string | null) {
103
+ const ctx = useSdkContext()
104
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx)
105
+ const queryClient = useQueryClient()
106
+ return useMutation({
107
+ mutationFn: (payload: CreateBespokeOrderParams) => createBespokeOrder(cfg, token || undefined, payload),
108
+ onSuccess: () => {
109
+ queryClient.invalidateQueries({ queryKey: ['orders'] })
110
+ },
111
+ })
112
+ }
113
+
114
+ export function useCreateServiceBookingOrder(config?: SdkConfig, accessToken?: string | null) {
115
+ const ctx = useSdkContext()
116
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx)
117
+ const queryClient = useQueryClient()
118
+ return useMutation({
119
+ mutationFn: (payload: CreateServiceBookingOrderParams) => createServiceBookingOrder(cfg, token || undefined, payload),
120
+ onSuccess: () => {
121
+ queryClient.invalidateQueries({ queryKey: ['orders'] })
122
+ },
123
+ })
101
124
  }
102
125
 
103
126
  export function useCancelOrder(config?: SdkConfig, accessToken?: string | null) {
104
127
  const ctx = useSdkContext()
105
- try {
106
- const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx)
107
- const queryClient = useQueryClient()
108
- return useMutation({
109
- mutationFn: ({ orderId, reason = '' }: { orderId: string; reason?: string }) =>
110
- token ? cancelOrder(cfg, token, orderId, reason) : Promise.reject('No access token'),
111
- onSuccess: () => {
112
- queryClient.invalidateQueries({ queryKey: ['orders'] })
113
- },
114
- })
115
- } catch (error) {
116
- logger.warn('[useCancelOrder] Called outside QueryClientProvider, returning no-op mutation')
117
- return { mutate: () => {}, mutateAsync: () => Promise.resolve(undefined) } as any
118
- }
128
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx)
129
+ const queryClient = useQueryClient()
130
+ return useMutation({
131
+ mutationFn: ({ orderId, reason = '' }: { orderId: string; reason?: string }) =>
132
+ token ? cancelOrder(cfg, token, orderId, reason) : Promise.reject(new Error('No access token available')),
133
+ onSuccess: () => {
134
+ queryClient.invalidateQueries({ queryKey: ['orders'] })
135
+ },
136
+ })
119
137
  }
@@ -1,55 +1,117 @@
1
1
  import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
2
- import { createDedicatedAccount, initiatePayment, verifyTransaction, getTransactionStatus } from "../services/payment.service";
2
+ import {
3
+ createDedicatedAccount,
4
+ initiatePayment,
5
+ verifyTransaction,
6
+ getTransactionStatus,
7
+ getAvailablePaymentMethods,
8
+ getWalletBalance,
9
+ getWalletLedger,
10
+ claimWalletCredit,
11
+ } from "../services/payment.service";
3
12
  import type { SdkConfig } from "../config";
4
13
  import type { DVACreateRequest, PaymentInitiateRequest } from "../types/payments";
5
- import { logger } from "../utils";
6
14
  import { useSdkContext, resolveHookArgs } from "../context/sdk-context";
7
15
 
16
+ /**
17
+ * Hook for fetching available payment methods for a region.
18
+ *
19
+ * `currency`/`countryCode` are optional with no SDK-level default — see
20
+ * getAvailablePaymentMethods' doc comment: the real backend already
21
+ * declares its own default for this route, so leaving them unset here
22
+ * lets that be the single source of truth instead of risking a second,
23
+ * independently-hardcoded copy drifting out of sync with it.
24
+ */
25
+ export function useAvailablePaymentMethods(
26
+ config?: SdkConfig,
27
+ currency?: string,
28
+ countryCode?: string
29
+ ) {
30
+ const ctx = useSdkContext();
31
+ const { config: cfg } = resolveHookArgs(config, undefined, ctx);
32
+ return useQuery({
33
+ queryKey: ['payment', 'available-methods', currency, countryCode],
34
+ queryFn: () => getAvailablePaymentMethods(cfg, currency, countryCode),
35
+ });
36
+ }
37
+
38
+ /**
39
+ * Hook for fetching authenticated customer's wallet balance.
40
+ */
41
+ export function useWalletBalance(config?: SdkConfig, accessToken?: string | null) {
42
+ const ctx = useSdkContext();
43
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx);
44
+ return useQuery({
45
+ queryKey: ['wallet', 'balance', token],
46
+ queryFn: () => token ? getWalletBalance(cfg, token) : Promise.reject(new Error('No access token available')),
47
+ enabled: !!token,
48
+ });
49
+ }
50
+
51
+ /**
52
+ * Hook for fetching authenticated customer's wallet ledger history.
53
+ */
54
+ export function useWalletLedger(
55
+ config?: SdkConfig,
56
+ accessToken?: string | null,
57
+ params?: { page?: number; page_size?: number }
58
+ ) {
59
+ const ctx = useSdkContext();
60
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx);
61
+ const page = params?.page ?? 1;
62
+ const pageSize = params?.page_size ?? 20;
63
+
64
+ return useQuery({
65
+ queryKey: ['wallet', 'ledger', token, page, pageSize],
66
+ queryFn: () => token ? getWalletLedger(cfg, token, { page, page_size: pageSize }) : Promise.reject(new Error('No access token available')),
67
+ enabled: !!token,
68
+ });
69
+ }
70
+
71
+ /**
72
+ * Hook for claiming pending guest wallet credit into customer's wallet.
73
+ */
74
+ export function useClaimWalletCredit(config?: SdkConfig, accessToken?: string | null) {
75
+ const ctx = useSdkContext();
76
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx);
77
+ const queryClient = useQueryClient();
78
+
79
+ return useMutation({
80
+ mutationFn: (claimToken: string) =>
81
+ token ? claimWalletCredit(cfg, token, claimToken) : Promise.reject(new Error('No access token available')),
82
+ onSuccess: () => {
83
+ queryClient.invalidateQueries({ queryKey: ['wallet'] });
84
+ },
85
+ });
86
+ }
87
+
8
88
  /**
9
89
  * Hook for creating a Dedicated Virtual Account (DVA)
10
- * Optional config and accessToken — read from SdkContext if omitted.
90
+ * Supports both authenticated users and guest checkout.
11
91
  */
12
92
  export function useCreateDVA(config?: SdkConfig, accessToken?: string | null) {
13
93
  const ctx = useSdkContext();
14
- try {
15
- const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx);
16
- const queryClient = useQueryClient();
94
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx);
95
+ const queryClient = useQueryClient();
17
96
 
18
- return useMutation({
19
- mutationFn: (request: DVACreateRequest) =>
20
- token ? createDedicatedAccount(cfg, token, request) : Promise.reject('No access token'),
21
- onSuccess: () => {
22
- queryClient.invalidateQueries({ queryKey: ['payment'] });
23
- },
24
- });
25
- } catch (error) {
26
- logger.warn('[useCreateDVA] Called outside QueryClientProvider, returning no-op mutation');
27
- return {
28
- mutate: () => {},
29
- mutateAsync: () => Promise.resolve(undefined),
30
- } as any;
31
- }
97
+ return useMutation({
98
+ mutationFn: (request: DVACreateRequest) => createDedicatedAccount(cfg, token, request),
99
+ onSuccess: () => {
100
+ queryClient.invalidateQueries({ queryKey: ['payment'] });
101
+ },
102
+ });
32
103
  }
33
104
 
34
105
  /**
35
- * Hook for initiating card payment
36
- * Optional config and accessToken — read from SdkContext if omitted.
106
+ * Hook for initiating payment (card, transfer, etc.)
107
+ * Supports both authenticated users and guest checkout.
37
108
  */
38
109
  export function useInitiatePayment(config?: SdkConfig, accessToken?: string | null) {
39
110
  const ctx = useSdkContext();
40
- try {
41
- const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx);
42
- return useMutation({
43
- mutationFn: (request: PaymentInitiateRequest) =>
44
- token ? initiatePayment(cfg, token, request) : Promise.reject('No access token'),
45
- });
46
- } catch (error) {
47
- logger.warn('[useInitiatePayment] Called outside QueryClientProvider, returning no-op mutation');
48
- return {
49
- mutate: () => {},
50
- mutateAsync: () => Promise.resolve(undefined),
51
- } as any;
52
- }
111
+ const { config: cfg, accessToken: token } = resolveHookArgs(config, accessToken, ctx);
112
+ return useMutation({
113
+ mutationFn: (request: PaymentInitiateRequest) => initiatePayment(cfg, token, request),
114
+ });
53
115
  }
54
116
 
55
117
  /**
@@ -58,18 +120,10 @@ export function useInitiatePayment(config?: SdkConfig, accessToken?: string | nu
58
120
  */
59
121
  export function useVerifyTransaction(config?: SdkConfig) {
60
122
  const ctx = useSdkContext();
61
- try {
62
- const { config: cfg } = resolveHookArgs(config, undefined, ctx);
63
- return useMutation({
64
- mutationFn: (reference: string) => verifyTransaction(cfg, reference),
65
- });
66
- } catch (error) {
67
- logger.warn('[useVerifyTransaction] Called outside QueryClientProvider, returning no-op mutation');
68
- return {
69
- mutate: () => {},
70
- mutateAsync: () => Promise.resolve(undefined),
71
- } as any;
72
- }
123
+ const { config: cfg } = resolveHookArgs(config, undefined, ctx);
124
+ return useMutation({
125
+ mutationFn: (reference: string) => verifyTransaction(cfg, reference),
126
+ });
73
127
  }
74
128
 
75
129
  /**
@@ -83,24 +137,13 @@ export function useTransactionStatus(arg1?: SdkConfig | string, arg2?: string |
83
137
  const transactionId = isArg1Config ? (arg2 as string) : (typeof arg1 === 'string' ? arg1 : '');
84
138
  const enabled = isArg1Config ? (arg3 ?? false) : (typeof arg2 === 'boolean' ? arg2 : false);
85
139
 
86
- try {
87
- const { config: cfg } = resolveHookArgs(explicitConfig, undefined, ctx);
88
- return useQuery({
89
- queryKey: ['transaction', 'status', transactionId],
90
- queryFn: () => getTransactionStatus(cfg, transactionId),
91
- enabled: enabled && !!transactionId,
92
- refetchInterval: 3000,
93
- });
94
- } catch (error) {
95
- logger.warn('[useTransactionStatus] Called outside QueryClientProvider, returning undefined');
96
- return {
97
- data: undefined,
98
- isLoading: false,
99
- error: null,
100
- isFetching: false,
101
- refetch: () => Promise.resolve({ data: undefined }),
102
- } as any;
103
- }
140
+ const { config: cfg } = resolveHookArgs(explicitConfig, undefined, ctx);
141
+ return useQuery({
142
+ queryKey: ['transaction', 'status', transactionId],
143
+ queryFn: () => getTransactionStatus(cfg, transactionId),
144
+ enabled: enabled && !!transactionId,
145
+ refetchInterval: 3000,
146
+ });
104
147
  }
105
148
 
106
149
  /**
@@ -114,23 +157,12 @@ export function usePollTransactionStatus(arg1?: SdkConfig | string, arg2?: strin
114
157
  const reference = isArg1Config ? (arg2 as string) : (typeof arg1 === 'string' ? arg1 : '');
115
158
  const enabled = isArg1Config ? (arg3 ?? false) : (typeof arg2 === 'boolean' ? arg2 : false);
116
159
 
117
- try {
118
- const { config: cfg } = resolveHookArgs(explicitConfig, undefined, ctx);
119
- return useQuery({
120
- queryKey: ['transaction', 'poll', reference],
121
- queryFn: () => verifyTransaction(cfg, reference),
122
- enabled: enabled && !!reference,
123
- refetchInterval: 2000,
124
- retry: 10,
125
- });
126
- } catch (error) {
127
- logger.warn('[usePollTransactionStatus] Called outside QueryClientProvider, returning undefined');
128
- return {
129
- data: undefined,
130
- isLoading: false,
131
- error: null,
132
- isFetching: false,
133
- refetch: () => Promise.resolve({ data: undefined }),
134
- } as any;
135
- }
160
+ const { config: cfg } = resolveHookArgs(explicitConfig, undefined, ctx);
161
+ return useQuery({
162
+ queryKey: ['transaction', 'poll', reference],
163
+ queryFn: () => verifyTransaction(cfg, reference),
164
+ enabled: enabled && !!reference,
165
+ refetchInterval: 2000,
166
+ retry: 10,
167
+ });
136
168
  }