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,194 @@
1
+ /**
2
+ * Products API Adapter
3
+ * Connects frontend products to real backend products APIs
4
+ */
5
+
6
+ import { ProductsApi } from '../Apis/apis/products-api';
7
+ import { CategoriesApi } from '../Apis/apis/categories-api';
8
+ import { getApiConfiguration } from './config';
9
+ import { mapProduct } from './mappers';
10
+ import { Product, ApiResponse, PaginatedResponse, ProductFilters, Category } from '../types';
11
+
12
+ export const productsAdapter = {
13
+ /**
14
+ * Get all products with optional filters and pagination
15
+ */
16
+ async getProducts(
17
+ filters?: ProductFilters,
18
+ page: number = 1,
19
+ limit: number = 20
20
+ ): Promise<PaginatedResponse<Product>> {
21
+ try {
22
+ const productsApi = new ProductsApi(getApiConfiguration());
23
+
24
+ const response = await productsApi.getAllProductsForStore(
25
+ filters?.search,
26
+ undefined, // productType
27
+ filters?.category,
28
+ filters?.maxPrice,
29
+ filters?.minPrice,
30
+ undefined, // brandFilter
31
+ filters?.inStock !== undefined ? (filters.inStock ? 'in-stock' : 'out-of-stock') : undefined,
32
+ undefined, // sort
33
+ true, // includeNoVariantProducts
34
+ true, // isActive
35
+ limit,
36
+ page
37
+ );
38
+
39
+ const products = response.data.data?.map(mapProduct) || [];
40
+
41
+ return {
42
+ data: products,
43
+ pagination: {
44
+ page: response.data.currentPage || page,
45
+ limit: response.data.limit || limit,
46
+ total: response.data.totalItems || products.length,
47
+ totalPages: response.data.totalPages || 1,
48
+ },
49
+ };
50
+ } catch (error: any) {
51
+ console.error('Failed to get products:', error);
52
+ return {
53
+ data: [],
54
+ pagination: { page, limit, total: 0, totalPages: 0 },
55
+ };
56
+ }
57
+ },
58
+
59
+ /**
60
+ * Get a single product by ID
61
+ */
62
+ async getProduct(id: string): Promise<ApiResponse<Product>> {
63
+ try {
64
+ const productsApi = new ProductsApi(getApiConfiguration());
65
+ const response = await productsApi.getSingleProduct(id);
66
+
67
+ return {
68
+ success: true,
69
+ data: mapProduct(response.data),
70
+ };
71
+ } catch (error: any) {
72
+ return {
73
+ success: false,
74
+ message: error.response?.data?.message || 'Failed to get product',
75
+ data: {} as Product,
76
+ };
77
+ }
78
+ },
79
+
80
+ /**
81
+ * Get featured/top selling products
82
+ */
83
+ async getFeaturedProducts(limit: number = 8): Promise<ApiResponse<Product[]>> {
84
+ try {
85
+ const productsApi = new ProductsApi(getApiConfiguration());
86
+ const response = await productsApi.getTopSellingProducts(limit, 1, true, true);
87
+
88
+ const products = response.data.data?.map(mapProduct) || [];
89
+
90
+ return {
91
+ success: true,
92
+ data: products,
93
+ };
94
+ } catch (error: any) {
95
+ return {
96
+ success: false,
97
+ message: error.response?.data?.message || 'Failed to get featured products',
98
+ data: [],
99
+ };
100
+ }
101
+ },
102
+
103
+ /**
104
+ * Get related products
105
+ */
106
+ async getRelatedProducts(productId: string, limit: number = 4): Promise<ApiResponse<Product[]>> {
107
+ try {
108
+ const productsApi = new ProductsApi(getApiConfiguration());
109
+ const response = await productsApi.getRelatedProducts(productId);
110
+
111
+ const products = (response.data || [])
112
+ .map(mapProduct)
113
+ .slice(0, limit);
114
+
115
+ return {
116
+ success: true,
117
+ data: products,
118
+ };
119
+ } catch (error: any) {
120
+ return {
121
+ success: false,
122
+ message: error.response?.data?.message || 'Failed to get related products',
123
+ data: [],
124
+ };
125
+ }
126
+ },
127
+
128
+ /**
129
+ * Get all categories
130
+ */
131
+ async getCategories(): Promise<ApiResponse<Category[]>> {
132
+ try {
133
+ const categoriesApi = new CategoriesApi(getApiConfiguration());
134
+ const response = await categoriesApi.getAllCategories();
135
+
136
+ const categories: Category[] = (response.data.data || []).map((cat: any) => ({
137
+ id: cat.id || cat._id || '',
138
+ name: cat.name || '',
139
+ slug: cat.slug || cat.name?.toLowerCase().replace(/\s+/g, '-') || '',
140
+ description: cat.description,
141
+ image: cat.image,
142
+ productCount: cat.productCount || 0,
143
+ }));
144
+
145
+ return {
146
+ success: true,
147
+ data: categories,
148
+ };
149
+ } catch (error: any) {
150
+ return {
151
+ success: false,
152
+ message: error.response?.data?.message || 'Failed to get categories',
153
+ data: [],
154
+ };
155
+ }
156
+ },
157
+
158
+ /**
159
+ * Search products
160
+ */
161
+ async searchProducts(query: string, limit: number = 10): Promise<ApiResponse<Product[]>> {
162
+ try {
163
+ const productsApi = new ProductsApi(getApiConfiguration());
164
+ const response = await productsApi.getAllProductsForStore(
165
+ query, // searchTerm
166
+ undefined,
167
+ undefined,
168
+ undefined,
169
+ undefined,
170
+ undefined,
171
+ undefined,
172
+ undefined,
173
+ true,
174
+ true,
175
+ limit,
176
+ 1
177
+ );
178
+
179
+ const products = response.data.data?.map(mapProduct) || [];
180
+
181
+ return {
182
+ success: true,
183
+ data: products,
184
+ };
185
+ } catch (error: any) {
186
+ return {
187
+ success: false,
188
+ message: error.response?.data?.message || 'Failed to search products',
189
+ data: [],
190
+ };
191
+ }
192
+ },
193
+ };
194
+
@@ -0,0 +1,152 @@
1
+ // Configuration Types
2
+ export interface EcommerceConfig {
3
+ storeId: string;
4
+ storeName: string;
5
+ logo: string;
6
+ colors: {
7
+ primary: string;
8
+ secondary: string;
9
+ accent: string;
10
+ };
11
+ apiBaseUrl: string;
12
+ stripePublicKey: string;
13
+ }
14
+
15
+ // Product Types
16
+ export interface Product {
17
+ id: string;
18
+ name: string;
19
+ description: string;
20
+ price: number;
21
+ compareAtPrice?: number;
22
+ images: string[];
23
+ category: string;
24
+ inStock: boolean;
25
+ stock?: number;
26
+ sku?: string;
27
+ tags?: string[];
28
+ createdAt: string;
29
+ updatedAt: string;
30
+ }
31
+
32
+ export interface ProductFilters {
33
+ category?: string;
34
+ minPrice?: number;
35
+ maxPrice?: number;
36
+ search?: string;
37
+ tags?: string[];
38
+ inStock?: boolean;
39
+ }
40
+
41
+ // Cart Types
42
+ export interface CartItem {
43
+ productId: string;
44
+ quantity: number;
45
+ product: Product;
46
+ }
47
+
48
+ export interface Cart {
49
+ items: CartItem[];
50
+ total: number;
51
+ itemCount: number;
52
+ }
53
+
54
+ // Order Types
55
+ export enum OrderStatus {
56
+ PENDING = 'pending',
57
+ PROCESSING = 'processing',
58
+ SHIPPED = 'shipped',
59
+ DELIVERED = 'delivered',
60
+ CANCELLED = 'cancelled',
61
+ }
62
+
63
+ export interface Order {
64
+ id: string;
65
+ orderNumber: string;
66
+ items: OrderItem[];
67
+ total: number;
68
+ status: OrderStatus;
69
+ shippingAddress: Address;
70
+ billingAddress: Address;
71
+ paymentStatus: 'pending' | 'paid' | 'failed';
72
+ stripeCheckoutUrl?: string;
73
+ createdAt: string;
74
+ updatedAt: string;
75
+ }
76
+
77
+ export interface OrderItem {
78
+ id: string;
79
+ productId: string;
80
+ productName: string;
81
+ productImage: string;
82
+ quantity: number;
83
+ price: number;
84
+ }
85
+
86
+ export interface Address {
87
+ fullName: string;
88
+ addressLine1: string;
89
+ addressLine2?: string;
90
+ city: string;
91
+ state: string;
92
+ zipCode: string;
93
+ country: string;
94
+ phone: string;
95
+ }
96
+
97
+ // Auth Types
98
+ export interface User {
99
+ id: string;
100
+ email: string;
101
+ firstName: string;
102
+ lastName: string;
103
+ phone?: string;
104
+ avatar?: string;
105
+ createdAt: string;
106
+ }
107
+
108
+ export interface AuthTokens {
109
+ accessToken: string;
110
+ refreshToken: string;
111
+ }
112
+
113
+ export interface LoginCredentials {
114
+ email: string;
115
+ password: string;
116
+ }
117
+
118
+ export interface RegisterData {
119
+ email: string;
120
+ password: string;
121
+ firstName: string;
122
+ lastName: string;
123
+ phone?: string;
124
+ }
125
+
126
+ // API Response Types
127
+ export interface ApiResponse<T> {
128
+ data: T;
129
+ message?: string;
130
+ success: boolean;
131
+ }
132
+
133
+ export interface PaginatedResponse<T> {
134
+ data: T[];
135
+ pagination: {
136
+ page: number;
137
+ limit: number;
138
+ total: number;
139
+ totalPages: number;
140
+ };
141
+ }
142
+
143
+ // Category Types
144
+ export interface Category {
145
+ id: string;
146
+ name: string;
147
+ slug: string;
148
+ description?: string;
149
+ image?: string;
150
+ productCount: number;
151
+ }
152
+
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Convert hex color to RGB array
3
+ */
4
+ export function hexToRgb(hex: string): [number, number, number] {
5
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
6
+ return result
7
+ ? [
8
+ parseInt(result[1], 16),
9
+ parseInt(result[2], 16),
10
+ parseInt(result[3], 16),
11
+ ]
12
+ : [0, 0, 0];
13
+ }
14
+
15
+ /**
16
+ * Generate color shades from a base color
17
+ */
18
+ export function generateColorShades(baseColor: string) {
19
+ const [r, g, b] = hexToRgb(baseColor);
20
+
21
+ const shades = {
22
+ 50: lighten(r, g, b, 0.95),
23
+ 100: lighten(r, g, b, 0.9),
24
+ 200: lighten(r, g, b, 0.75),
25
+ 300: lighten(r, g, b, 0.6),
26
+ 400: lighten(r, g, b, 0.3),
27
+ 500: `${r}, ${g}, ${b}`,
28
+ 600: darken(r, g, b, 0.1),
29
+ 700: darken(r, g, b, 0.2),
30
+ 800: darken(r, g, b, 0.3),
31
+ 900: darken(r, g, b, 0.4),
32
+ 950: darken(r, g, b, 0.5),
33
+ };
34
+
35
+ return shades;
36
+ }
37
+
38
+ function lighten(r: number, g: number, b: number, amount: number): string {
39
+ const newR = Math.round(r + (255 - r) * amount);
40
+ const newG = Math.round(g + (255 - g) * amount);
41
+ const newB = Math.round(b + (255 - b) * amount);
42
+ return `${newR}, ${newG}, ${newB}`;
43
+ }
44
+
45
+ function darken(r: number, g: number, b: number, amount: number): string {
46
+ const newR = Math.round(r * (1 - amount));
47
+ const newG = Math.round(g * (1 - amount));
48
+ const newB = Math.round(b * (1 - amount));
49
+ return `${newR}, ${newG}, ${newB}`;
50
+ }
51
+
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Format price with currency symbol
3
+ */
4
+ export function formatPrice(price: number, currency: string = 'USD'): string {
5
+ return new Intl.NumberFormat('en-US', {
6
+ style: 'currency',
7
+ currency,
8
+ }).format(price);
9
+ }
10
+
11
+ /**
12
+ * Format date
13
+ */
14
+ export function formatDate(date: string | Date, format: 'short' | 'long' = 'short'): string {
15
+ const d = typeof date === 'string' ? new Date(date) : date;
16
+
17
+ if (format === 'long') {
18
+ return new Intl.DateTimeFormat('en-US', {
19
+ year: 'numeric',
20
+ month: 'long',
21
+ day: 'numeric',
22
+ hour: '2-digit',
23
+ minute: '2-digit',
24
+ }).format(d);
25
+ }
26
+
27
+ return new Intl.DateTimeFormat('en-US', {
28
+ year: 'numeric',
29
+ month: 'short',
30
+ day: 'numeric',
31
+ }).format(d);
32
+ }
33
+
34
+ /**
35
+ * Truncate text with ellipsis
36
+ */
37
+ export function truncate(text: string, maxLength: number): string {
38
+ if (text.length <= maxLength) return text;
39
+ return text.slice(0, maxLength) + '...';
40
+ }
41
+
42
+ /**
43
+ * Generate initials from name
44
+ */
45
+ export function getInitials(firstName: string, lastName: string): string {
46
+ return `${firstName.charAt(0)}${lastName.charAt(0)}`.toUpperCase();
47
+ }
48
+
@@ -0,0 +1,117 @@
1
+ 'use client';
2
+
3
+ import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';
4
+ import { User, LoginCredentials, RegisterData } from '@/lib/types';
5
+ import { authApi } from '@/lib/api/auth';
6
+ import { getAuthToken } from '@/lib/api/client';
7
+
8
+ interface AuthContextValue {
9
+ user: User | null;
10
+ isAuthenticated: boolean;
11
+ isLoading: boolean;
12
+ login: (credentials: LoginCredentials) => Promise<void>;
13
+ register: (data: RegisterData) => Promise<void>;
14
+ logout: () => Promise<void>;
15
+ updateUser: (data: Partial<User>) => Promise<void>;
16
+ refreshUser: () => Promise<void>;
17
+ }
18
+
19
+ const AuthContext = createContext<AuthContextValue | undefined>(undefined);
20
+
21
+ export function useAuth() {
22
+ const context = useContext(AuthContext);
23
+ if (!context) {
24
+ throw new Error('useAuth must be used within AuthProvider');
25
+ }
26
+ return context;
27
+ }
28
+
29
+ interface AuthProviderProps {
30
+ children: React.ReactNode;
31
+ }
32
+
33
+ export function AuthProvider({ children }: AuthProviderProps) {
34
+ const [user, setUser] = useState<User | null>(null);
35
+ const [isLoading, setIsLoading] = useState(true);
36
+
37
+ const refreshUser = useCallback(async () => {
38
+ try {
39
+ const token = getAuthToken();
40
+ if (token) {
41
+ const response = await authApi.getCurrentUser();
42
+ if (response.success) {
43
+ setUser(response.data);
44
+ }
45
+ }
46
+ } catch (error) {
47
+ console.error('Failed to refresh user:', error);
48
+ setUser(null);
49
+ } finally {
50
+ setIsLoading(false);
51
+ }
52
+ }, []);
53
+
54
+ useEffect(() => {
55
+ refreshUser();
56
+ }, [refreshUser]);
57
+
58
+ const login = async (credentials: LoginCredentials) => {
59
+ setIsLoading(true);
60
+ try {
61
+ const response = await authApi.login(credentials);
62
+ if (response.success) {
63
+ setUser(response.data.user);
64
+ }
65
+ } finally {
66
+ setIsLoading(false);
67
+ }
68
+ };
69
+
70
+ const register = async (data: RegisterData) => {
71
+ setIsLoading(true);
72
+ try {
73
+ const response = await authApi.register(data);
74
+ if (response.success) {
75
+ setUser(response.data.user);
76
+ }
77
+ } finally {
78
+ setIsLoading(false);
79
+ }
80
+ };
81
+
82
+ const logout = async () => {
83
+ setIsLoading(true);
84
+ try {
85
+ await authApi.logout();
86
+ setUser(null);
87
+ } finally {
88
+ setIsLoading(false);
89
+ }
90
+ };
91
+
92
+ const updateUser = async (data: Partial<User>) => {
93
+ try {
94
+ const response = await authApi.updateProfile(data);
95
+ if (response.success) {
96
+ setUser(response.data);
97
+ }
98
+ } catch (error) {
99
+ console.error('Failed to update user:', error);
100
+ throw error;
101
+ }
102
+ };
103
+
104
+ const value: AuthContextValue = {
105
+ user,
106
+ isAuthenticated: !!user,
107
+ isLoading,
108
+ login,
109
+ register,
110
+ logout,
111
+ updateUser,
112
+ refreshUser,
113
+ };
114
+
115
+ return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
116
+ }
117
+
@@ -0,0 +1,131 @@
1
+ 'use client';
2
+
3
+ import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';
4
+ import { Cart, CartItem } from '@/lib/types';
5
+ import { cartApi } from '@/lib/api/cart';
6
+ import { useAuth } from './AuthProvider';
7
+ import { toast } from 'sonner';
8
+
9
+ interface CartContextValue {
10
+ cart: Cart | null;
11
+ isLoading: boolean;
12
+ addToCart: (productId: string, quantity?: number) => Promise<void>;
13
+ updateQuantity: (productId: string, quantity: number) => Promise<void>;
14
+ removeFromCart: (productId: string) => Promise<void>;
15
+ clearCart: () => Promise<void>;
16
+ refreshCart: () => Promise<void>;
17
+ }
18
+
19
+ const CartContext = createContext<CartContextValue | undefined>(undefined);
20
+
21
+ export function useCart() {
22
+ const context = useContext(CartContext);
23
+ if (!context) {
24
+ throw new Error('useCart must be used within CartProvider');
25
+ }
26
+ return context;
27
+ }
28
+
29
+ interface CartProviderProps {
30
+ children: React.ReactNode;
31
+ }
32
+
33
+ export function CartProvider({ children }: CartProviderProps) {
34
+ const [cart, setCart] = useState<Cart | null>(null);
35
+ const [isLoading, setIsLoading] = useState(false);
36
+ const { isAuthenticated } = useAuth();
37
+
38
+ const refreshCart = useCallback(async () => {
39
+ if (!isAuthenticated) {
40
+ setCart(null);
41
+ return;
42
+ }
43
+
44
+ try {
45
+ const response = await cartApi.getCart();
46
+ if (response.success) {
47
+ setCart(response.data);
48
+ }
49
+ } catch (error) {
50
+ console.error('Failed to fetch cart:', error);
51
+ }
52
+ }, [isAuthenticated]);
53
+
54
+ useEffect(() => {
55
+ refreshCart();
56
+ }, [refreshCart]);
57
+
58
+ const addToCart = async (productId: string, quantity: number = 1) => {
59
+ setIsLoading(true);
60
+ try {
61
+ const response = await cartApi.addToCart(productId, quantity);
62
+ if (response.success) {
63
+ setCart(response.data);
64
+ toast.success('Added to cart!');
65
+ }
66
+ } catch (error: any) {
67
+ toast.error(error.response?.data?.message || 'Failed to add to cart');
68
+ throw error;
69
+ } finally {
70
+ setIsLoading(false);
71
+ }
72
+ };
73
+
74
+ const updateQuantity = async (productId: string, quantity: number) => {
75
+ setIsLoading(true);
76
+ try {
77
+ const response = await cartApi.updateCartItem(productId, quantity);
78
+ if (response.success) {
79
+ setCart(response.data);
80
+ }
81
+ } catch (error: any) {
82
+ toast.error(error.response?.data?.message || 'Failed to update cart');
83
+ throw error;
84
+ } finally {
85
+ setIsLoading(false);
86
+ }
87
+ };
88
+
89
+ const removeFromCart = async (productId: string) => {
90
+ setIsLoading(true);
91
+ try {
92
+ const response = await cartApi.removeFromCart(productId);
93
+ if (response.success) {
94
+ setCart(response.data);
95
+ toast.success('Removed from cart');
96
+ }
97
+ } catch (error: any) {
98
+ toast.error(error.response?.data?.message || 'Failed to remove from cart');
99
+ throw error;
100
+ } finally {
101
+ setIsLoading(false);
102
+ }
103
+ };
104
+
105
+ const clearCart = async () => {
106
+ setIsLoading(true);
107
+ try {
108
+ await cartApi.clearCart();
109
+ setCart({ items: [], total: 0, itemCount: 0 });
110
+ toast.success('Cart cleared');
111
+ } catch (error: any) {
112
+ toast.error(error.response?.data?.message || 'Failed to clear cart');
113
+ throw error;
114
+ } finally {
115
+ setIsLoading(false);
116
+ }
117
+ };
118
+
119
+ const value: CartContextValue = {
120
+ cart,
121
+ isLoading,
122
+ addToCart,
123
+ updateQuantity,
124
+ removeFromCart,
125
+ clearCart,
126
+ refreshCart,
127
+ };
128
+
129
+ return <CartContext.Provider value={value}>{children}</CartContext.Provider>;
130
+ }
131
+