hey-pharmacist-ecommerce 1.0.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.
Files changed (287) hide show
  1. package/README.md +269 -0
  2. package/dist/index.d.mts +564 -0
  3. package/dist/index.d.ts +564 -0
  4. package/dist/index.js +7541 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +7485 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +70 -0
  9. package/src/components/CartItem.tsx +103 -0
  10. package/src/components/EmptyState.tsx +27 -0
  11. package/src/components/Footer.tsx +147 -0
  12. package/src/components/Header.tsx +151 -0
  13. package/src/components/OrderCard.tsx +98 -0
  14. package/src/components/ProductCard.tsx +122 -0
  15. package/src/components/ui/Badge.tsx +31 -0
  16. package/src/components/ui/Button.tsx +61 -0
  17. package/src/components/ui/Input.tsx +45 -0
  18. package/src/components/ui/Modal.tsx +79 -0
  19. package/src/components/ui/Skeleton.tsx +46 -0
  20. package/src/hooks/useOrders.ts +98 -0
  21. package/src/hooks/useProducts.ts +125 -0
  22. package/src/index.ts +71 -0
  23. package/src/lib/Apis/api.ts +46 -0
  24. package/src/lib/Apis/apis/addresses-api.ts +1461 -0
  25. package/src/lib/Apis/apis/auth-api.ts +945 -0
  26. package/src/lib/Apis/apis/blogs-api.ts +582 -0
  27. package/src/lib/Apis/apis/cart-api.ts +456 -0
  28. package/src/lib/Apis/apis/categories-api.ts +725 -0
  29. package/src/lib/Apis/apis/chats-api.ts +1101 -0
  30. package/src/lib/Apis/apis/contact-us-api.ts +394 -0
  31. package/src/lib/Apis/apis/discounts-api.ts +763 -0
  32. package/src/lib/Apis/apis/drafts-api.ts +448 -0
  33. package/src/lib/Apis/apis/events-api.ts +1311 -0
  34. package/src/lib/Apis/apis/file-proccesor-api.ts +293 -0
  35. package/src/lib/Apis/apis/health-api.ts +119 -0
  36. package/src/lib/Apis/apis/images-api.ts +271 -0
  37. package/src/lib/Apis/apis/inventory-api.ts +375 -0
  38. package/src/lib/Apis/apis/marketing-api.ts +3099 -0
  39. package/src/lib/Apis/apis/notifications-api.ts +843 -0
  40. package/src/lib/Apis/apis/open-aiapi.ts +513 -0
  41. package/src/lib/Apis/apis/orders-api.ts +1343 -0
  42. package/src/lib/Apis/apis/payment-methods-api.ts +411 -0
  43. package/src/lib/Apis/apis/payments-api.ts +469 -0
  44. package/src/lib/Apis/apis/product-attributes-api.ts +538 -0
  45. package/src/lib/Apis/apis/product-favorite-list-api.ts +321 -0
  46. package/src/lib/Apis/apis/product-variants-api.ts +648 -0
  47. package/src/lib/Apis/apis/products-api.ts +1442 -0
  48. package/src/lib/Apis/apis/review-api.ts +1383 -0
  49. package/src/lib/Apis/apis/roles-api.ts +614 -0
  50. package/src/lib/Apis/apis/shipping-api.ts +703 -0
  51. package/src/lib/Apis/apis/statistics-api.ts +234 -0
  52. package/src/lib/Apis/apis/stores-api.ts +1519 -0
  53. package/src/lib/Apis/apis/sub-categories-api.ts +1208 -0
  54. package/src/lib/Apis/apis/user-groups-api.ts +1198 -0
  55. package/src/lib/Apis/apis/users-api.ts +1403 -0
  56. package/src/lib/Apis/apis/web-hooks-api.ts +198 -0
  57. package/src/lib/Apis/base.ts +70 -0
  58. package/src/lib/Apis/configuration.ts +75 -0
  59. package/src/lib/Apis/index.ts +17 -0
  60. package/src/lib/Apis/models/add-contact-to-list-dto.ts +33 -0
  61. package/src/lib/Apis/models/add-message-dto.ts +56 -0
  62. package/src/lib/Apis/models/address-created-request.ts +134 -0
  63. package/src/lib/Apis/models/address.ts +164 -0
  64. package/src/lib/Apis/models/allow-user-credit-dto.ts +27 -0
  65. package/src/lib/Apis/models/appointment.ts +75 -0
  66. package/src/lib/Apis/models/available-dates-dto.ts +33 -0
  67. package/src/lib/Apis/models/available-suggested-dates-dto.ts +33 -0
  68. package/src/lib/Apis/models/blog.ts +75 -0
  69. package/src/lib/Apis/models/browser-stats-response-dto.ts +40 -0
  70. package/src/lib/Apis/models/bulk-move-subcategories-dto.ts +33 -0
  71. package/src/lib/Apis/models/bulk-unassign-subcategories-dto.ts +27 -0
  72. package/src/lib/Apis/models/campaign-content-response-dto.ts +40 -0
  73. package/src/lib/Apis/models/campaign-draft-dto.ts +175 -0
  74. package/src/lib/Apis/models/campaign-draft-response-dto.ts +40 -0
  75. package/src/lib/Apis/models/campaign-draft-schedule-dto.ts +49 -0
  76. package/src/lib/Apis/models/campaign-draft-schedule-response-dto.ts +40 -0
  77. package/src/lib/Apis/models/campaign-draft-sending-dto.ts +43 -0
  78. package/src/lib/Apis/models/campaign-draft-sending-response-dto.ts +40 -0
  79. package/src/lib/Apis/models/cart-body-dto.ts +40 -0
  80. package/src/lib/Apis/models/cart-body-populated.ts +47 -0
  81. package/src/lib/Apis/models/cart-item-populated.ts +41 -0
  82. package/src/lib/Apis/models/cart-item.ts +33 -0
  83. package/src/lib/Apis/models/cart-response-dto.ts +70 -0
  84. package/src/lib/Apis/models/categories-paginated-response-dto.ts +52 -0
  85. package/src/lib/Apis/models/category-filters.ts +40 -0
  86. package/src/lib/Apis/models/category-populated.ts +106 -0
  87. package/src/lib/Apis/models/category-sub-category-populated.ts +51 -0
  88. package/src/lib/Apis/models/category.ts +99 -0
  89. package/src/lib/Apis/models/categorys-headlines-response-dto.ts +40 -0
  90. package/src/lib/Apis/models/change-user-email-dto.ts +27 -0
  91. package/src/lib/Apis/models/chat.ts +33 -0
  92. package/src/lib/Apis/models/check-notifications-response-dto.ts +33 -0
  93. package/src/lib/Apis/models/contact-aggregated-stats-response-dto.ts +40 -0
  94. package/src/lib/Apis/models/contact-full-dto.ts +93 -0
  95. package/src/lib/Apis/models/contact-full-response-dto.ts +40 -0
  96. package/src/lib/Apis/models/contact-list-stats-response-dto.ts +40 -0
  97. package/src/lib/Apis/models/contact-lists-response-dto.ts +40 -0
  98. package/src/lib/Apis/models/contact-us.ts +81 -0
  99. package/src/lib/Apis/models/country-stats-response-dto.ts +40 -0
  100. package/src/lib/Apis/models/create-address-dto.ts +134 -0
  101. package/src/lib/Apis/models/create-blog-dto.ts +45 -0
  102. package/src/lib/Apis/models/create-category-dto.ts +45 -0
  103. package/src/lib/Apis/models/create-chat-dto.ts +39 -0
  104. package/src/lib/Apis/models/create-contact-dto.ts +39 -0
  105. package/src/lib/Apis/models/create-contact-list-dto.ts +27 -0
  106. package/src/lib/Apis/models/create-discount-dto.ts +208 -0
  107. package/src/lib/Apis/models/create-draft-dto.ts +67 -0
  108. package/src/lib/Apis/models/create-email-template-dto.ts +51 -0
  109. package/src/lib/Apis/models/create-event-dto.ts +52 -0
  110. package/src/lib/Apis/models/create-marketing-campaign-dto.ts +81 -0
  111. package/src/lib/Apis/models/create-message-dto.ts +57 -0
  112. package/src/lib/Apis/models/create-notification-dto.ts +75 -0
  113. package/src/lib/Apis/models/create-product-attribute-dto.ts +33 -0
  114. package/src/lib/Apis/models/create-product-dto.ts +94 -0
  115. package/src/lib/Apis/models/create-review-dto.ts +63 -0
  116. package/src/lib/Apis/models/create-role-dto.ts +57 -0
  117. package/src/lib/Apis/models/create-single-variant-product-dto.ts +155 -0
  118. package/src/lib/Apis/models/create-store-address-dto.ts +134 -0
  119. package/src/lib/Apis/models/create-store-dto.ts +105 -0
  120. package/src/lib/Apis/models/create-sub-category-dto.ts +45 -0
  121. package/src/lib/Apis/models/create-user-dto.ts +89 -0
  122. package/src/lib/Apis/models/create-user-group-dto.ts +39 -0
  123. package/src/lib/Apis/models/create-variant-dto.ts +119 -0
  124. package/src/lib/Apis/models/create-zone-dto.ts +82 -0
  125. package/src/lib/Apis/models/custom-product-dto.ts +63 -0
  126. package/src/lib/Apis/models/default-payment-method-request-dto.ts +27 -0
  127. package/src/lib/Apis/models/delete-file-dto.ts +27 -0
  128. package/src/lib/Apis/models/delete-many-files-dto.ts +27 -0
  129. package/src/lib/Apis/models/discount-paginated-response.ts +52 -0
  130. package/src/lib/Apis/models/discount.ts +245 -0
  131. package/src/lib/Apis/models/discounts-insights-dto.ts +57 -0
  132. package/src/lib/Apis/models/draft.ts +79 -0
  133. package/src/lib/Apis/models/email-invoice-dto.ts +45 -0
  134. package/src/lib/Apis/models/email-template-response-dto.ts +117 -0
  135. package/src/lib/Apis/models/event.ts +76 -0
  136. package/src/lib/Apis/models/extended-product-dto.ts +204 -0
  137. package/src/lib/Apis/models/fileproccesor-upload-body.ts +27 -0
  138. package/src/lib/Apis/models/forget-password.ts +27 -0
  139. package/src/lib/Apis/models/frequently-bought-product-dto.ts +71 -0
  140. package/src/lib/Apis/models/general-stats-response-dto.ts +40 -0
  141. package/src/lib/Apis/models/generate-day-slots-dto.ts +51 -0
  142. package/src/lib/Apis/models/generate-month-slots-dto.ts +57 -0
  143. package/src/lib/Apis/models/generate-week-slots-dto.ts +57 -0
  144. package/src/lib/Apis/models/google-analytics-request-dto.ts +55 -0
  145. package/src/lib/Apis/models/google-analytics-response-dto.ts +39 -0
  146. package/src/lib/Apis/models/group-with-no-users-dto.ts +75 -0
  147. package/src/lib/Apis/models/group-with-users-dto.ts +76 -0
  148. package/src/lib/Apis/models/images-upload-body.ts +27 -0
  149. package/src/lib/Apis/models/index.ts +197 -0
  150. package/src/lib/Apis/models/inventory-paginated-response.ts +75 -0
  151. package/src/lib/Apis/models/link-stats-response-dto.ts +40 -0
  152. package/src/lib/Apis/models/login-dto.ts +33 -0
  153. package/src/lib/Apis/models/manual-discount.ts +49 -0
  154. package/src/lib/Apis/models/manual-order-dto.ts +133 -0
  155. package/src/lib/Apis/models/manual-shipping-dto.ts +45 -0
  156. package/src/lib/Apis/models/marketing-campaign-content-dto.ts +27 -0
  157. package/src/lib/Apis/models/marketing-list-contact-dto.ts +51 -0
  158. package/src/lib/Apis/models/move-subcategory-dto.ts +27 -0
  159. package/src/lib/Apis/models/my-favorite-list-dto.ts +52 -0
  160. package/src/lib/Apis/models/notification.ts +93 -0
  161. package/src/lib/Apis/models/object-id.ts +21 -0
  162. package/src/lib/Apis/models/open-api.ts +33 -0
  163. package/src/lib/Apis/models/order-paginated-response.ts +52 -0
  164. package/src/lib/Apis/models/order.ts +214 -0
  165. package/src/lib/Apis/models/orders-insights-dto.ts +69 -0
  166. package/src/lib/Apis/models/paginated-products-dto.ts +52 -0
  167. package/src/lib/Apis/models/payment-method-data.ts +34 -0
  168. package/src/lib/Apis/models/payment-method.ts +51 -0
  169. package/src/lib/Apis/models/payment-time-line-dto.ts +56 -0
  170. package/src/lib/Apis/models/payment.ts +182 -0
  171. package/src/lib/Apis/models/payments-insights-dto.ts +69 -0
  172. package/src/lib/Apis/models/payments-paginated-response.ts +52 -0
  173. package/src/lib/Apis/models/pick-type-class.ts +51 -0
  174. package/src/lib/Apis/models/populated-chat-dto.ts +95 -0
  175. package/src/lib/Apis/models/populated-discount.ts +246 -0
  176. package/src/lib/Apis/models/populated-order.ts +209 -0
  177. package/src/lib/Apis/models/prefered-pick-or-delivery-time-dto.ts +33 -0
  178. package/src/lib/Apis/models/price-range.ts +33 -0
  179. package/src/lib/Apis/models/product-attribute.ts +57 -0
  180. package/src/lib/Apis/models/product-variant.ts +167 -0
  181. package/src/lib/Apis/models/product.ts +136 -0
  182. package/src/lib/Apis/models/products-insights-dto.ts +45 -0
  183. package/src/lib/Apis/models/rate-dto.ts +123 -0
  184. package/src/lib/Apis/models/refill-request-dto.ts +75 -0
  185. package/src/lib/Apis/models/refill-request.ts +105 -0
  186. package/src/lib/Apis/models/register-or-login-with-gmail.ts +27 -0
  187. package/src/lib/Apis/models/reserve-appointment.ts +261 -0
  188. package/src/lib/Apis/models/review.ts +93 -0
  189. package/src/lib/Apis/models/role.ts +69 -0
  190. package/src/lib/Apis/models/schedule-campaign-draft-dto.ts +27 -0
  191. package/src/lib/Apis/models/send-test-email-dto.ts +28 -0
  192. package/src/lib/Apis/models/shallow-parent-category-dto.ts +33 -0
  193. package/src/lib/Apis/models/shipment-details-dto.ts +88 -0
  194. package/src/lib/Apis/models/shipment-status-dto.ts +117 -0
  195. package/src/lib/Apis/models/shipment-with-order.ts +105 -0
  196. package/src/lib/Apis/models/shipment.ts +104 -0
  197. package/src/lib/Apis/models/shipping-info.ts +88 -0
  198. package/src/lib/Apis/models/single-browser-stats-dto.ts +45 -0
  199. package/src/lib/Apis/models/single-contact-aggregated-stats-dto.ts +129 -0
  200. package/src/lib/Apis/models/single-contact-list-stats-dto.ts +117 -0
  201. package/src/lib/Apis/models/single-country-stats-dto.ts +39 -0
  202. package/src/lib/Apis/models/single-general-stats.ts +153 -0
  203. package/src/lib/Apis/models/single-link-stats-dto.ts +39 -0
  204. package/src/lib/Apis/models/single-message-populated.ts +59 -0
  205. package/src/lib/Apis/models/single-notification-dto.ts +99 -0
  206. package/src/lib/Apis/models/single-product-media.ts +74 -0
  207. package/src/lib/Apis/models/single-recipient-dto.ts +33 -0
  208. package/src/lib/Apis/models/single-suggest-attribute.ts +33 -0
  209. package/src/lib/Apis/models/statistic-dto.ts +171 -0
  210. package/src/lib/Apis/models/store-entity.ts +117 -0
  211. package/src/lib/Apis/models/store.ts +135 -0
  212. package/src/lib/Apis/models/sub-category-headlines-only-response-dto.ts +39 -0
  213. package/src/lib/Apis/models/sub-category.ts +93 -0
  214. package/src/lib/Apis/models/suggest-attributes.ts +28 -0
  215. package/src/lib/Apis/models/suggested-slot.ts +33 -0
  216. package/src/lib/Apis/models/table-cell-dto.ts +33 -0
  217. package/src/lib/Apis/models/table-dto.ts +34 -0
  218. package/src/lib/Apis/models/tadmin-session-data.ts +47 -0
  219. package/src/lib/Apis/models/track-dto.ts +94 -0
  220. package/src/lib/Apis/models/tracking-status-location-base.ts +45 -0
  221. package/src/lib/Apis/models/tracking-status-substatus.ts +39 -0
  222. package/src/lib/Apis/models/tracking-status.ts +71 -0
  223. package/src/lib/Apis/models/transfere-patient-request.ts +123 -0
  224. package/src/lib/Apis/models/transfere-patients-request-dto.ts +99 -0
  225. package/src/lib/Apis/models/tuser-session-data.ts +34 -0
  226. package/src/lib/Apis/models/update-address-dto.ts +134 -0
  227. package/src/lib/Apis/models/update-blog-dto.ts +45 -0
  228. package/src/lib/Apis/models/update-campaign-draft-content-dto.ts +27 -0
  229. package/src/lib/Apis/models/update-category-dto.ts +45 -0
  230. package/src/lib/Apis/models/update-discount-dto.ts +208 -0
  231. package/src/lib/Apis/models/update-event-dto.ts +52 -0
  232. package/src/lib/Apis/models/update-items-order-dto.ts +27 -0
  233. package/src/lib/Apis/models/update-marketing-camp-draft-dto.ts +81 -0
  234. package/src/lib/Apis/models/update-message-dto.ts +57 -0
  235. package/src/lib/Apis/models/update-product-attribute-dto.ts +33 -0
  236. package/src/lib/Apis/models/update-product-dto.ts +96 -0
  237. package/src/lib/Apis/models/update-product-variant-dto.ts +119 -0
  238. package/src/lib/Apis/models/update-refill-request-dto.ts +75 -0
  239. package/src/lib/Apis/models/update-review-dto.ts +63 -0
  240. package/src/lib/Apis/models/update-role-dto.ts +57 -0
  241. package/src/lib/Apis/models/update-store-dto.ts +105 -0
  242. package/src/lib/Apis/models/update-sub-category-dto.ts +45 -0
  243. package/src/lib/Apis/models/update-transfere-patients-request-dto.ts +99 -0
  244. package/src/lib/Apis/models/update-user-dto.ts +239 -0
  245. package/src/lib/Apis/models/update-user-group-dto.ts +39 -0
  246. package/src/lib/Apis/models/update-zone-dto.ts +82 -0
  247. package/src/lib/Apis/models/upload-pdf-body.ts +27 -0
  248. package/src/lib/Apis/models/used-by.ts +87 -0
  249. package/src/lib/Apis/models/user-entity.ts +220 -0
  250. package/src/lib/Apis/models/user-group.ts +75 -0
  251. package/src/lib/Apis/models/user-insights-dto.ts +39 -0
  252. package/src/lib/Apis/models/user-with-no-id.ts +226 -0
  253. package/src/lib/Apis/models/user.ts +232 -0
  254. package/src/lib/Apis/models/users-paginated-response.ts +52 -0
  255. package/src/lib/Apis/models/verify-email-dto.ts +33 -0
  256. package/src/lib/Apis/models/zone-single-size.ts +51 -0
  257. package/src/lib/Apis/models/zone.ts +106 -0
  258. package/src/lib/Apis/wrapper.ts +37 -0
  259. package/src/lib/api/auth.ts +81 -0
  260. package/src/lib/api/cart.ts +42 -0
  261. package/src/lib/api/client.ts +118 -0
  262. package/src/lib/api/orders.ts +53 -0
  263. package/src/lib/api/products.ts +51 -0
  264. package/src/lib/api-adapter/auth-adapter.ts +196 -0
  265. package/src/lib/api-adapter/cart-adapter.ts +193 -0
  266. package/src/lib/api-adapter/config.ts +76 -0
  267. package/src/lib/api-adapter/index.ts +13 -0
  268. package/src/lib/api-adapter/mappers.ts +147 -0
  269. package/src/lib/api-adapter/orders-adapter.ts +195 -0
  270. package/src/lib/api-adapter/products-adapter.ts +194 -0
  271. package/src/lib/types/index.ts +152 -0
  272. package/src/lib/utils/colors.ts +51 -0
  273. package/src/lib/utils/format.ts +48 -0
  274. package/src/providers/AuthProvider.tsx +117 -0
  275. package/src/providers/CartProvider.tsx +131 -0
  276. package/src/providers/EcommerceProvider.tsx +34 -0
  277. package/src/providers/ThemeProvider.tsx +57 -0
  278. package/src/screens/CartScreen.tsx +140 -0
  279. package/src/screens/CheckoutScreen.tsx +340 -0
  280. package/src/screens/CurrentOrdersScreen.tsx +85 -0
  281. package/src/screens/LoginScreen.tsx +149 -0
  282. package/src/screens/OrdersScreen.tsx +86 -0
  283. package/src/screens/ProductDetailScreen.tsx +255 -0
  284. package/src/screens/ProfileScreen.tsx +211 -0
  285. package/src/screens/RegisterScreen.tsx +200 -0
  286. package/src/screens/ShopScreen.tsx +233 -0
  287. package/src/styles/globals.css +51 -0
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Cart API Adapter
3
+ * Connects frontend cart to real backend cart APIs
4
+ */
5
+
6
+ import { CartApi } from '../Apis/apis/cart-api';
7
+ import { CartBodyDTO } from '../Apis/models';
8
+ import { getApiConfiguration } from './config';
9
+ import { mapCart } from './mappers';
10
+ import { Cart, ApiResponse } from '../types';
11
+
12
+ export const cartAdapter = {
13
+ /**
14
+ * Get user's cart
15
+ */
16
+ async getCart(): Promise<ApiResponse<Cart>> {
17
+ try {
18
+ const cartApi = new CartApi(getApiConfiguration());
19
+ const response = await cartApi.getUserCart();
20
+
21
+ return {
22
+ success: true,
23
+ data: mapCart(response.data),
24
+ };
25
+ } catch (error: any) {
26
+ return {
27
+ success: false,
28
+ message: error.response?.data?.message || 'Failed to get cart',
29
+ data: { items: [], total: 0, itemCount: 0 },
30
+ };
31
+ }
32
+ },
33
+
34
+ /**
35
+ * Add item to cart
36
+ * In your backend, cart is updated as a whole, not individual items
37
+ */
38
+ async addToCart(productId: string, variantId: string, quantity: number = 1): Promise<ApiResponse<Cart>> {
39
+ try {
40
+ const cartApi = new CartApi(getApiConfiguration());
41
+
42
+ // First get current cart
43
+ const currentCartResponse = await cartApi.getUserCart();
44
+ const currentCart = currentCartResponse.data;
45
+
46
+ // Build updated cart body
47
+ const existingItems = currentCart.cartBody?.items || [];
48
+ const existingIndex = existingItems.findIndex(
49
+ (p: any) => p.productVariantId === variantId
50
+ );
51
+
52
+ let updatedItems;
53
+ if (existingIndex >= 0) {
54
+ // Update existing item
55
+ updatedItems = [...existingItems];
56
+ updatedItems[existingIndex] = {
57
+ ...updatedItems[existingIndex],
58
+ quantity: updatedItems[existingIndex].quantity + quantity,
59
+ };
60
+ } else {
61
+ // Add new item
62
+ updatedItems = [
63
+ ...existingItems,
64
+ {
65
+ productVariantId: variantId,
66
+ quantity,
67
+ },
68
+ ];
69
+ }
70
+
71
+ const cartBodyDTO: CartBodyDTO = {
72
+ items: updatedItems,
73
+ };
74
+
75
+ await cartApi.handleUserCart(cartBodyDTO);
76
+
77
+ // Get updated cart
78
+ const updatedCartResponse = await cartApi.getUserCart();
79
+
80
+ return {
81
+ success: true,
82
+ data: mapCart(updatedCartResponse.data),
83
+ };
84
+ } catch (error: any) {
85
+ return {
86
+ success: false,
87
+ message: error.response?.data?.message || 'Failed to add to cart',
88
+ data: { items: [], total: 0, itemCount: 0 },
89
+ };
90
+ }
91
+ },
92
+
93
+ /**
94
+ * Update cart item quantity
95
+ */
96
+ async updateCartItem(productId: string, variantId: string, quantity: number): Promise<ApiResponse<Cart>> {
97
+ try {
98
+ const cartApi = new CartApi(getApiConfiguration());
99
+
100
+ // Get current cart
101
+ const currentCartResponse = await cartApi.getUserCart();
102
+ const currentCart = currentCartResponse.data;
103
+
104
+ // Update the specific item
105
+ const updatedItems = (currentCart.cartBody?.items || []).map((p: any) => {
106
+ if (p.productVariantId === variantId) {
107
+ return { ...p, quantity };
108
+ }
109
+ return p;
110
+ });
111
+
112
+ const cartBodyDTO: CartBodyDTO = {
113
+ items: updatedItems,
114
+ };
115
+
116
+ await cartApi.handleUserCart(cartBodyDTO);
117
+
118
+ // Get updated cart
119
+ const updatedCartResponse = await cartApi.getUserCart();
120
+
121
+ return {
122
+ success: true,
123
+ data: mapCart(updatedCartResponse.data),
124
+ };
125
+ } catch (error: any) {
126
+ return {
127
+ success: false,
128
+ message: error.response?.data?.message || 'Failed to update cart',
129
+ data: { items: [], total: 0, itemCount: 0 },
130
+ };
131
+ }
132
+ },
133
+
134
+ /**
135
+ * Remove item from cart
136
+ */
137
+ async removeFromCart(productId: string, variantId: string): Promise<ApiResponse<Cart>> {
138
+ try {
139
+ const cartApi = new CartApi(getApiConfiguration());
140
+
141
+ // Get current cart
142
+ const currentCartResponse = await cartApi.getUserCart();
143
+ const currentCart = currentCartResponse.data;
144
+
145
+ // Filter out the item
146
+ const updatedItems = (currentCart.cartBody?.items || []).filter(
147
+ (p: any) => p.productVariantId !== variantId
148
+ );
149
+
150
+ const cartBodyDTO: CartBodyDTO = {
151
+ items: updatedItems,
152
+ };
153
+
154
+ await cartApi.handleUserCart(cartBodyDTO);
155
+
156
+ // Get updated cart
157
+ const updatedCartResponse = await cartApi.getUserCart();
158
+
159
+ return {
160
+ success: true,
161
+ data: mapCart(updatedCartResponse.data),
162
+ };
163
+ } catch (error: any) {
164
+ return {
165
+ success: false,
166
+ message: error.response?.data?.message || 'Failed to remove from cart',
167
+ data: { items: [], total: 0, itemCount: 0 },
168
+ };
169
+ }
170
+ },
171
+
172
+ /**
173
+ * Clear cart
174
+ */
175
+ async clearCart(): Promise<ApiResponse<void>> {
176
+ try {
177
+ const cartApi = new CartApi(getApiConfiguration());
178
+ await cartApi.clearCart();
179
+
180
+ return {
181
+ success: true,
182
+ data: undefined,
183
+ };
184
+ } catch (error: any) {
185
+ return {
186
+ success: false,
187
+ message: error.response?.data?.message || 'Failed to clear cart',
188
+ data: undefined,
189
+ };
190
+ }
191
+ },
192
+ };
193
+
@@ -0,0 +1,76 @@
1
+ /**
2
+ * API Adapter Configuration
3
+ * Bridges the frontend components with the real backend APIs
4
+ */
5
+
6
+ import { Configuration } from '../Apis/configuration';
7
+ import { EcommerceConfig } from '../types';
8
+
9
+ let apiConfiguration: Configuration | null = null;
10
+ let currentConfig: EcommerceConfig | null = null;
11
+
12
+ /**
13
+ * Initialize the API configuration with store settings
14
+ */
15
+ export function initializeApiAdapter(config: EcommerceConfig): Configuration {
16
+ currentConfig = config;
17
+
18
+ apiConfiguration = new Configuration({
19
+ basePath: config.apiBaseUrl,
20
+ apiKey: () => config.storeId, // x-store-key header
21
+ accessToken: () => getAuthToken() || '', // Bearer token
22
+ });
23
+
24
+ return apiConfiguration;
25
+ }
26
+
27
+ /**
28
+ * Get the current API configuration
29
+ */
30
+ export function getApiConfiguration(): Configuration {
31
+ if (!apiConfiguration) {
32
+ throw new Error('API adapter not initialized. Call initializeApiAdapter first.');
33
+ }
34
+ return apiConfiguration;
35
+ }
36
+
37
+ /**
38
+ * Get the current ecommerce config
39
+ */
40
+ export function getCurrentConfig(): EcommerceConfig {
41
+ if (!currentConfig) {
42
+ throw new Error('API adapter not initialized.');
43
+ }
44
+ return currentConfig;
45
+ }
46
+
47
+ // Token management
48
+ const TOKEN_KEY = 'ecommerce_access_token';
49
+
50
+ export function setAuthToken(token: string): void {
51
+ if (typeof window !== 'undefined') {
52
+ localStorage.setItem(TOKEN_KEY, token);
53
+ // Update the configuration with new token
54
+ if (apiConfiguration) {
55
+ apiConfiguration.accessToken = () => token;
56
+ }
57
+ }
58
+ }
59
+
60
+ export function getAuthToken(): string | null {
61
+ if (typeof window !== 'undefined') {
62
+ return localStorage.getItem(TOKEN_KEY);
63
+ }
64
+ return null;
65
+ }
66
+
67
+ export function clearAuthToken(): void {
68
+ if (typeof window !== 'undefined') {
69
+ localStorage.removeItem(TOKEN_KEY);
70
+ // Clear from configuration
71
+ if (apiConfiguration) {
72
+ apiConfiguration.accessToken = () => '';
73
+ }
74
+ }
75
+ }
76
+
@@ -0,0 +1,13 @@
1
+ /**
2
+ * API Adapter - Main Export
3
+ * Central export point for all adapters
4
+ */
5
+
6
+ export { initializeApiAdapter, getApiConfiguration, getCurrentConfig, setAuthToken, getAuthToken, clearAuthToken } from './config';
7
+ export { authAdapter } from './auth-adapter';
8
+ export { productsAdapter } from './products-adapter';
9
+ export { cartAdapter } from './cart-adapter';
10
+ export { ordersAdapter } from './orders-adapter';
11
+ export type { CreateOrderData } from './orders-adapter';
12
+ export * from './mappers';
13
+
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Data Mappers
3
+ * Convert backend models to frontend types
4
+ */
5
+
6
+ import { UserEntity, TUserSessionData } from '../Apis/models';
7
+ import { ExtendedProductDTO } from '../Apis/models';
8
+ import { CartResponseDto } from '../Apis/models';
9
+ import { PopulatedOrder } from '../Apis/models';
10
+ import { User, Product, Cart, Order, OrderStatus, CartItem } from '../types';
11
+
12
+ /**
13
+ * Map backend UserEntity to frontend User
14
+ */
15
+ export function mapUser(backendUser: UserEntity): User {
16
+ return {
17
+ id: backendUser.id || backendUser._id || '',
18
+ email: backendUser.email || '',
19
+ firstName: backendUser.firstname || '',
20
+ lastName: backendUser.lastname || '',
21
+ phone: backendUser.phoneNumber,
22
+ avatar: backendUser.avatar,
23
+ createdAt: backendUser.createdAt ? backendUser.createdAt.toString() : new Date().toISOString(),
24
+ };
25
+ }
26
+
27
+ /**
28
+ * Map backend session data to user and token
29
+ */
30
+ export function mapSessionData(sessionData: TUserSessionData): { user: User; token: string } {
31
+ return {
32
+ user: mapUser(sessionData.userData),
33
+ token: sessionData.authToken,
34
+ };
35
+ }
36
+
37
+ /**
38
+ * Map backend product to frontend Product
39
+ */
40
+ export function mapProduct(backendProduct: ExtendedProductDTO): Product {
41
+ const images = backendProduct.productMedia?.map((media) => media.file) || [];
42
+
43
+ return {
44
+ id: backendProduct.id || backendProduct._id || '',
45
+ name: backendProduct.name || '',
46
+ description: backendProduct.description || '',
47
+ price: backendProduct.finalPrice || 0,
48
+ compareAtPrice: backendProduct.isDiscounted ? backendProduct.priceBeforeDiscount : undefined,
49
+ images: images.filter(Boolean),
50
+ category: backendProduct.parentCategories?.[0] || '',
51
+ inStock: (backendProduct.inventoryCount || 0) > 0,
52
+ stock: backendProduct.inventoryCount,
53
+ sku: backendProduct.sku,
54
+ tags: backendProduct.tags || [],
55
+ createdAt: backendProduct.createdAt ? backendProduct.createdAt.toString() : new Date().toISOString(),
56
+ updatedAt: backendProduct.updatedAt ? backendProduct.updatedAt.toString() : new Date().toISOString(),
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Map backend cart to frontend Cart
62
+ */
63
+ export function mapCart(backendCart: CartResponseDto): Cart {
64
+ const items: CartItem[] = [];
65
+
66
+ // Map cart body items
67
+ if (backendCart.cartBody?.items) {
68
+ backendCart.cartBody.items.forEach((item: any) => {
69
+ if (item.productVariantData) {
70
+ // Extract product info from variant data
71
+ const productData = item.productVariantData.product || item.productVariantData;
72
+ items.push({
73
+ productId: productData.id || productData._id || '',
74
+ quantity: item.quantity || 0,
75
+ product: mapProduct(productData),
76
+ });
77
+ }
78
+ });
79
+ }
80
+
81
+ return {
82
+ items,
83
+ total: backendCart.total || 0,
84
+ itemCount: items.reduce((sum, item) => sum + item.quantity, 0),
85
+ };
86
+ }
87
+
88
+ /**
89
+ * Map backend order status to frontend OrderStatus
90
+ */
91
+ export function mapOrderStatus(backendStatus: string): OrderStatus {
92
+ const statusMap: Record<string, OrderStatus> = {
93
+ 'pending': OrderStatus.PENDING,
94
+ 'processing': OrderStatus.PROCESSING,
95
+ 'shipped': OrderStatus.SHIPPED,
96
+ 'delivered': OrderStatus.DELIVERED,
97
+ 'cancelled': OrderStatus.CANCELLED,
98
+ };
99
+
100
+ return statusMap[backendStatus.toLowerCase()] || OrderStatus.PENDING;
101
+ }
102
+
103
+ /**
104
+ * Map backend order to frontend Order
105
+ */
106
+ export function mapOrder(backendOrder: PopulatedOrder): Order {
107
+ return {
108
+ id: backendOrder.id || backendOrder._id || '',
109
+ orderNumber: backendOrder.stringId || backendOrder.id || backendOrder._id || '',
110
+ items: backendOrder.items?.map((item: any) => ({
111
+ id: item.id || item._id || '',
112
+ productId: item.productVariantData?.product?.id || item.productVariantData?.id || '',
113
+ productName: item.productVariantData?.product?.name || item.productVariantData?.name || '',
114
+ productImage: item.productVariantData?.product?.productMedia?.[0]?.url ||
115
+ item.productVariantData?.productMedia?.[0]?.url || '',
116
+ quantity: item.quantity || 0,
117
+ price: item.productVariantData?.finalPrice || 0,
118
+ })) || [],
119
+ total: backendOrder.grandTotal || 0,
120
+ status: mapOrderStatus(backendOrder.orderStatus || 'pending'),
121
+ shippingAddress: backendOrder.shippingInfo?.addressTo ? {
122
+ fullName: backendOrder.shippingInfo.addressTo.name || '',
123
+ addressLine1: backendOrder.shippingInfo.addressTo.street1 || '',
124
+ addressLine2: backendOrder.shippingInfo.addressTo.street2 || '',
125
+ city: backendOrder.shippingInfo.addressTo.city || '',
126
+ state: backendOrder.shippingInfo.addressTo.state || '',
127
+ zipCode: backendOrder.shippingInfo.addressTo.zip || '',
128
+ country: backendOrder.shippingInfo.addressTo.country || '',
129
+ phone: backendOrder.shippingInfo.addressTo.phone || '',
130
+ } : {} as any,
131
+ billingAddress: backendOrder.shippingInfo?.addressTo ? {
132
+ fullName: backendOrder.shippingInfo.addressTo.name || '',
133
+ addressLine1: backendOrder.shippingInfo.addressTo.street1 || '',
134
+ addressLine2: backendOrder.shippingInfo.addressTo.street2 || '',
135
+ city: backendOrder.shippingInfo.addressTo.city || '',
136
+ state: backendOrder.shippingInfo.addressTo.state || '',
137
+ zipCode: backendOrder.shippingInfo.addressTo.zip || '',
138
+ country: backendOrder.shippingInfo.addressTo.country || '',
139
+ phone: backendOrder.shippingInfo.addressTo.phone || '',
140
+ } : {} as any,
141
+ paymentStatus: (backendOrder.payment?.paymentStatus?.toLowerCase() || 'unpaid') as any,
142
+ stripeCheckoutUrl: backendOrder.payment?.hostedInvoiceUrl,
143
+ createdAt: backendOrder.createdAt ? backendOrder.createdAt.toString() : new Date().toISOString(),
144
+ updatedAt: backendOrder.updatedAt ? backendOrder.updatedAt.toString() : new Date().toISOString(),
145
+ };
146
+ }
147
+
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Orders API Adapter
3
+ * Connects frontend orders to real backend orders APIs
4
+ */
5
+
6
+ import { OrdersApi } from '../Apis/apis/orders-api';
7
+ import { ManualOrderDTO } from '../Apis/models';
8
+ import { getApiConfiguration } from './config';
9
+ import { mapOrder } from './mappers';
10
+ import { Order, ApiResponse, PaginatedResponse, Address } from '../types';
11
+
12
+ export interface CreateOrderData {
13
+ shippingAddress: Address;
14
+ billingAddress: Address;
15
+ sameAsShipping?: boolean;
16
+ paymentMethod?: string;
17
+ }
18
+
19
+ export const ordersAdapter = {
20
+ /**
21
+ * Get user's orders with pagination
22
+ */
23
+ async getOrders(page: number = 1, limit: number = 10): Promise<PaginatedResponse<Order>> {
24
+ try {
25
+ const ordersApi = new OrdersApi(getApiConfiguration());
26
+ const response = await ordersApi.getAllOrders(
27
+ undefined, // paymentStatus
28
+ undefined, // orderStatus
29
+ page,
30
+ limit,
31
+ undefined, // search
32
+ undefined, // createdAfter
33
+ undefined, // createdBefore
34
+ undefined // userId
35
+ );
36
+
37
+ const orders = response.data.data?.map(mapOrder) || [];
38
+
39
+ return {
40
+ data: orders,
41
+ pagination: {
42
+ page: response.data.page || page,
43
+ limit: response.data.limit || limit,
44
+ total: response.data.total || orders.length,
45
+ totalPages: response.data.totalPages || 1,
46
+ },
47
+ };
48
+ } catch (error: any) {
49
+ console.error('Failed to get orders:', error);
50
+ return {
51
+ data: [],
52
+ pagination: { page, limit, total: 0, totalPages: 0 },
53
+ };
54
+ }
55
+ },
56
+
57
+ /**
58
+ * Get current/active orders
59
+ * Orders that are not delivered or cancelled
60
+ */
61
+ async getCurrentOrders(): Promise<ApiResponse<Order[]>> {
62
+ try {
63
+ const ordersApi = new OrdersApi(getApiConfiguration());
64
+ const response = await ordersApi.getUserOrders();
65
+
66
+ const orders = (response.data || [])
67
+ .map((order: any) => mapOrder(order))
68
+ .filter((order: Order) =>
69
+ order.status !== 'delivered' &&
70
+ order.status !== 'cancelled'
71
+ );
72
+
73
+ return {
74
+ success: true,
75
+ data: orders,
76
+ };
77
+ } catch (error: any) {
78
+ return {
79
+ success: false,
80
+ message: error.response?.data?.message || 'Failed to get current orders',
81
+ data: [],
82
+ };
83
+ }
84
+ },
85
+
86
+ /**
87
+ * Get a single order by ID
88
+ */
89
+ async getOrder(id: string): Promise<ApiResponse<Order>> {
90
+ try {
91
+ const ordersApi = new OrdersApi(getApiConfiguration());
92
+ const response = await ordersApi.getSingleOrder(id);
93
+
94
+ return {
95
+ success: true,
96
+ data: mapOrder(response.data),
97
+ };
98
+ } catch (error: any) {
99
+ return {
100
+ success: false,
101
+ message: error.response?.data?.message || 'Failed to get order',
102
+ data: {} as Order,
103
+ };
104
+ }
105
+ },
106
+
107
+ /**
108
+ * Create a new order
109
+ */
110
+ async createOrder(data: CreateOrderData): Promise<ApiResponse<Order>> {
111
+ try {
112
+ const ordersApi = new OrdersApi(getApiConfiguration());
113
+
114
+ // Build the order DTO
115
+ // Note: Cart items are handled automatically by backend
116
+ const orderDTO: ManualOrderDTO = {
117
+ items: [], // Will be populated from user's cart by backend
118
+ paymentMethod: 'Card' as any, // Card for Stripe, Cash for COD
119
+ orderStatus: 'Pending' as any,
120
+ manualDiscount: {} as any,
121
+ discountId: '',
122
+ manualShipping: {} as any,
123
+ paymentDueDate: new Date(),
124
+ chargeTax: true,
125
+ orderRemindingDates: [],
126
+ };
127
+
128
+ const response = await ordersApi.createCheckout(
129
+ orderDTO,
130
+ true, // isDelivery
131
+ undefined, // userId (from token)
132
+ undefined, // rateId
133
+ undefined // billingAddressId
134
+ );
135
+
136
+ return {
137
+ success: true,
138
+ data: mapOrder(response.data),
139
+ };
140
+ } catch (error: any) {
141
+ return {
142
+ success: false,
143
+ message: error.response?.data?.message || 'Failed to create order',
144
+ data: {} as Order,
145
+ };
146
+ }
147
+ },
148
+
149
+ /**
150
+ * Cancel an order
151
+ */
152
+ async cancelOrder(id: string): Promise<ApiResponse<Order>> {
153
+ try {
154
+ const ordersApi = new OrdersApi(getApiConfiguration());
155
+ const response = await ordersApi.cancelOrder(id);
156
+
157
+ return {
158
+ success: true,
159
+ data: mapOrder(response.data),
160
+ };
161
+ } catch (error: any) {
162
+ return {
163
+ success: false,
164
+ message: error.response?.data?.message || 'Failed to cancel order',
165
+ data: {} as Order,
166
+ };
167
+ }
168
+ },
169
+
170
+ /**
171
+ * Get order tracking information
172
+ */
173
+ async getOrderTracking(id: string): Promise<ApiResponse<any>> {
174
+ try {
175
+ const ordersApi = new OrdersApi(getApiConfiguration());
176
+ const response = await ordersApi.getSingleOrder(id);
177
+
178
+ return {
179
+ success: true,
180
+ data: {
181
+ orderStatus: response.data.orderStatus,
182
+ orderTimeLine: response.data.orderTimeLine,
183
+ shippingInfo: response.data.shippingInfo,
184
+ },
185
+ };
186
+ } catch (error: any) {
187
+ return {
188
+ success: false,
189
+ message: error.response?.data?.message || 'Failed to get tracking',
190
+ data: {},
191
+ };
192
+ }
193
+ },
194
+ };
195
+