flowrix 1.0.1-beta.155 → 1.0.1-beta.157

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 (226) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +23 -192
  3. package/dist/runtime/components/Types/page/index.d.vue.ts +5 -4
  4. package/dist/runtime/components/Types/page/index.vue +7 -11
  5. package/dist/runtime/components/Types/page/index.vue.d.ts +5 -4
  6. package/dist/runtime/composables/Blog/useBlogSingle.js +4 -5
  7. package/dist/runtime/composables/Category/useCategoryIndex.js +5 -5
  8. package/dist/runtime/composables/Checkout/useCheckout.d.ts +4 -0
  9. package/dist/runtime/composables/Checkout/useCheckout.js +15 -3
  10. package/dist/runtime/composables/Customer/useBillingAddress.d.ts +3 -0
  11. package/dist/runtime/composables/Customer/useBillingAddress.js +2 -0
  12. package/dist/runtime/composables/Customer/useShippingAddress.d.ts +3 -0
  13. package/dist/runtime/composables/Customer/useShippingAddress.js +2 -1
  14. package/dist/runtime/composables/Customer/useWishlists.d.ts +1 -1
  15. package/dist/runtime/composables/Product/CustomProduct/useCustomeScript.d.ts +4 -0
  16. package/dist/runtime/composables/Product/CustomProduct/useCustomeScript.js +5 -11
  17. package/dist/runtime/composables/Product/useProductCard.d.ts +90 -9
  18. package/dist/runtime/composables/Product/useProductCard.js +257 -55
  19. package/dist/runtime/composables/Product/useProductComponent.js +3 -10
  20. package/dist/runtime/composables/Product/useQuickView.d.ts +1 -1
  21. package/dist/runtime/composables/Product/useService.d.ts +1 -12
  22. package/dist/runtime/composables/Product/useService.js +2 -2
  23. package/dist/runtime/composables/index.d.ts +1 -1
  24. package/dist/runtime/composables/index.js +1 -1
  25. package/dist/runtime/composables/useAddresses.js +27 -6
  26. package/dist/runtime/composables/useApp.js +3 -4
  27. package/dist/runtime/composables/useCards.js +0 -1
  28. package/dist/runtime/composables/useClientApi.d.ts +8 -8
  29. package/dist/runtime/composables/useClientApi.js +74 -30
  30. package/dist/runtime/composables/useLocation.d.ts +3 -15
  31. package/dist/runtime/composables/useLocation.js +6 -27
  32. package/dist/runtime/composables/usePriceCalculation.d.ts +33 -0
  33. package/dist/runtime/composables/usePriceCalculation.js +107 -0
  34. package/dist/runtime/composables/useQuotationCheckout.d.ts +1 -1
  35. package/dist/runtime/middleware/flowrix.d.ts +5 -5
  36. package/dist/runtime/middleware/flowrix.js +2 -2
  37. package/dist/runtime/middleware/flowrixs3.d.ts +3 -0
  38. package/dist/runtime/middleware/flowrixs3.js +65 -0
  39. package/dist/runtime/pages/flowrix-default.vue +62 -15
  40. package/dist/runtime/plugins/full-reload.client.d.ts +2 -0
  41. package/dist/runtime/plugins/full-reload.client.js +28 -0
  42. package/dist/runtime/server/api/albums.d.ts +0 -1
  43. package/dist/runtime/server/api/albums.js +13 -40
  44. package/dist/runtime/server/api/auth/login.d.ts +0 -18
  45. package/dist/runtime/server/api/auth/login.js +0 -57
  46. package/dist/runtime/server/api/banners.d.ts +0 -1
  47. package/dist/runtime/server/api/banners.js +13 -40
  48. package/dist/runtime/server/api/brand/[...slug].d.ts +0 -1
  49. package/dist/runtime/server/api/brand/[...slug].js +14 -43
  50. package/dist/runtime/server/api/brand/index.d.ts +0 -1
  51. package/dist/runtime/server/api/brand/index.js +13 -39
  52. package/dist/runtime/server/api/cache/[...slug].delete.js +1 -2
  53. package/dist/runtime/server/api/cache/clean.get.js +1 -2
  54. package/dist/runtime/server/api/cart/[slug]/add.d.ts +0 -2
  55. package/dist/runtime/server/api/cart/[slug]/add.js +0 -21
  56. package/dist/runtime/server/api/cart/[slug]/update.d.ts +0 -2
  57. package/dist/runtime/server/api/cart/[slug]/update.js +0 -21
  58. package/dist/runtime/server/api/cart/related.d.ts +0 -2
  59. package/dist/runtime/server/api/cart/related.js +0 -34
  60. package/dist/runtime/server/api/cart/remove.d.ts +0 -2
  61. package/dist/runtime/server/api/cart/remove.js +0 -21
  62. package/dist/runtime/server/api/catalog/brands.d.ts +0 -1
  63. package/dist/runtime/server/api/catalog/brands.js +13 -45
  64. package/dist/runtime/server/api/catalog/categories.d.ts +0 -1
  65. package/dist/runtime/server/api/catalog/categories.js +13 -45
  66. package/dist/runtime/server/api/catalog/categoriesall.d.ts +0 -1
  67. package/dist/runtime/server/api/catalog/categoriesall.js +13 -45
  68. package/dist/runtime/server/api/catalog/featured.d.ts +0 -1
  69. package/dist/runtime/server/api/catalog/featured.js +13 -45
  70. package/dist/runtime/server/api/catalog/posts.d.ts +0 -1
  71. package/dist/runtime/server/api/catalog/posts.js +13 -45
  72. package/dist/runtime/server/api/catalog/samples.d.ts +0 -1
  73. package/dist/runtime/server/api/catalog/samples.js +13 -46
  74. package/dist/runtime/server/api/catalog/search.d.ts +0 -1
  75. package/dist/runtime/server/api/catalog/search.js +13 -46
  76. package/dist/runtime/server/api/category/[...slug].d.ts +1 -2
  77. package/dist/runtime/server/api/category/[...slug].js +34 -49
  78. package/dist/runtime/server/api/checkout/applyCoupon.d.ts +0 -2
  79. package/dist/runtime/server/api/checkout/applyCoupon.js +0 -20
  80. package/dist/runtime/server/api/checkout/configs.d.ts +0 -2
  81. package/dist/runtime/server/api/checkout/configs.js +0 -20
  82. package/dist/runtime/server/api/checkout/countries.d.ts +0 -2
  83. package/dist/runtime/server/api/checkout/countries.js +0 -13
  84. package/dist/runtime/server/api/checkout/paymentmethod.d.ts +0 -2
  85. package/dist/runtime/server/api/checkout/paymentmethod.js +0 -25
  86. package/dist/runtime/server/api/checkout/quotation/guest/customer.d.ts +0 -2
  87. package/dist/runtime/server/api/checkout/quotation/guest/customer.js +0 -20
  88. package/dist/runtime/server/api/checkvariables.js +1 -2
  89. package/dist/runtime/server/api/cmspost/[...slug].d.ts +0 -1
  90. package/dist/runtime/server/api/cmspost/[...slug].js +14 -44
  91. package/dist/runtime/server/api/cmspost/all.js +1 -2
  92. package/dist/runtime/server/api/company/profile.d.ts +1 -1
  93. package/dist/runtime/server/api/company/profile.js +13 -17
  94. package/dist/runtime/server/api/contact-center/webforms/[id]/details.d.ts +0 -3
  95. package/dist/runtime/server/api/contact-center/webforms/[id]/details.js +0 -54
  96. package/dist/runtime/server/api/countries.js +13 -38
  97. package/dist/runtime/server/api/customer/wishlist/deleteFromWishList.d.ts +0 -2
  98. package/dist/runtime/server/api/customer/wishlist/deleteFromWishList.js +0 -45
  99. package/dist/runtime/server/api/featured.d.ts +0 -3
  100. package/dist/runtime/server/api/featured.js +0 -52
  101. package/dist/runtime/server/api/generate/robots.get.js +0 -2
  102. package/dist/runtime/server/api/generate/sitemap.get.d.ts +1 -1
  103. package/dist/runtime/server/api/generate/sitemap.get.js +8 -12
  104. package/dist/runtime/server/api/global/[...slug].js +20 -0
  105. package/dist/runtime/server/api/location.d.ts +0 -2
  106. package/dist/runtime/server/api/location.js +0 -25
  107. package/dist/runtime/server/api/nav/[id]/links.d.ts +0 -1
  108. package/dist/runtime/server/api/nav/[id]/links.js +13 -43
  109. package/dist/runtime/server/api/page/[...slug].d.ts +0 -1
  110. package/dist/runtime/server/api/page/[...slug].js +14 -44
  111. package/dist/runtime/server/api/permalink/[...slug].get.js +31 -0
  112. package/dist/runtime/server/api/product/[...slug].d.ts +0 -1
  113. package/dist/runtime/server/api/product/[...slug].js +14 -49
  114. package/dist/runtime/server/api/quickview/[slug].d.ts +1 -1
  115. package/dist/runtime/server/api/quickview/[slug].js +15 -16
  116. package/dist/runtime/server/api/reviews.d.ts +1 -1
  117. package/dist/runtime/server/api/reviews.js +1 -2
  118. package/dist/runtime/server/api/reviews3.js +19 -0
  119. package/dist/runtime/server/api/samples.d.ts +0 -1
  120. package/dist/runtime/server/api/samples.js +13 -46
  121. package/dist/runtime/server/api/search.d.ts +0 -1
  122. package/dist/runtime/server/api/search.js +13 -46
  123. package/dist/runtime/server/api/service/[slug].d.ts +0 -1
  124. package/dist/runtime/server/api/service/[slug].js +13 -44
  125. package/dist/runtime/server/api/service/availability.d.ts +1 -1
  126. package/dist/runtime/server/api/service/getall.d.ts +0 -1
  127. package/dist/runtime/server/api/service/getall.js +13 -51
  128. package/dist/runtime/server/api/shop.d.ts +0 -1
  129. package/dist/runtime/server/api/shop.js +13 -46
  130. package/dist/runtime/server/api/subscribe.d.ts +0 -2
  131. package/dist/runtime/server/api/subscribe.js +0 -25
  132. package/dist/runtime/server/api/webform.d.ts +0 -3
  133. package/dist/runtime/server/api/webform.js +0 -54
  134. package/dist/runtime/server/middleware/powertools.d.ts +9 -0
  135. package/dist/runtime/server/middleware/powertools.js +30 -0
  136. package/dist/runtime/stores/Booking.js +23 -7
  137. package/dist/runtime/stores/Cart.js +18 -3
  138. package/dist/runtime/stores/Checkout.js +14 -3
  139. package/dist/runtime/stores/NavMenu.js +2 -4
  140. package/dist/runtime/stores/Search.js +9 -3
  141. package/dist/runtime/stores/auth.d.ts +28 -1
  142. package/dist/runtime/stores/auth.js +0 -5
  143. package/dist/runtime/stores/countries.js +1 -1
  144. package/dist/runtime/stores/index.d.ts +0 -1
  145. package/dist/runtime/stores/index.js +0 -1
  146. package/dist/runtime/stores/locations.d.ts +1 -5
  147. package/dist/runtime/stores/locations.js +8 -5
  148. package/dist/runtime/stores/product.js +9 -3
  149. package/dist/runtime/stores/promotions.d.ts +51 -0
  150. package/dist/runtime/stores/promotions.js +65 -0
  151. package/dist/runtime/stores/useCompanyProfile.js +5 -2
  152. package/dist/runtime/stores/wishlists.d.ts +1 -1
  153. package/dist/runtime/stores/wishlists.js +1 -1
  154. package/package.json +11 -3
  155. package/dist/runtime/composables/useLocations.d.ts +0 -12
  156. package/dist/runtime/composables/useLocations.js +0 -53
  157. package/dist/runtime/server/api/auth/forgot.d.ts +0 -5
  158. package/dist/runtime/server/api/auth/forgot.js +0 -43
  159. package/dist/runtime/server/api/auth/logout.d.ts +0 -5
  160. package/dist/runtime/server/api/auth/logout.js +0 -22
  161. package/dist/runtime/server/api/auth/register.js +0 -50
  162. package/dist/runtime/server/api/auth/session.get.js +0 -44
  163. package/dist/runtime/server/api/auth/user/reset-password.d.ts +0 -5
  164. package/dist/runtime/server/api/auth/user/reset-password.js +0 -39
  165. package/dist/runtime/server/api/auth/user/session.js +0 -42
  166. package/dist/runtime/server/api/auth/user/verify-token.d.ts +0 -6
  167. package/dist/runtime/server/api/auth/user/verify-token.js +0 -49
  168. package/dist/runtime/server/api/cart/service/[slug]/add.d.ts +0 -2
  169. package/dist/runtime/server/api/cart/service/[slug]/add.js +0 -16
  170. package/dist/runtime/server/api/check-404.d.ts +0 -4
  171. package/dist/runtime/server/api/check-404.js +0 -8
  172. package/dist/runtime/server/api/checkout/quotation/[slug].d.ts +0 -2
  173. package/dist/runtime/server/api/checkout/quotation/[slug].js +0 -20
  174. package/dist/runtime/server/api/checkout/quotation/guest/[slug].d.ts +0 -2
  175. package/dist/runtime/server/api/checkout/quotation/guest/[slug].js +0 -35
  176. package/dist/runtime/server/api/checkout/quotation/submit/[slug].d.ts +0 -2
  177. package/dist/runtime/server/api/checkout/quotation/submit/[slug].js +0 -22
  178. package/dist/runtime/server/api/contact-center/webforms/create.d.ts +0 -2
  179. package/dist/runtime/server/api/contact-center/webforms/create.js +0 -20
  180. package/dist/runtime/server/api/customer/address/add.d.ts +0 -14
  181. package/dist/runtime/server/api/customer/address/add.js +0 -32
  182. package/dist/runtime/server/api/customer/address/delete.d.ts +0 -20
  183. package/dist/runtime/server/api/customer/address/delete.js +0 -36
  184. package/dist/runtime/server/api/customer/address/setshipping.d.ts +0 -20
  185. package/dist/runtime/server/api/customer/address/setshipping.js +0 -40
  186. package/dist/runtime/server/api/customer/address/update.d.ts +0 -20
  187. package/dist/runtime/server/api/customer/address/update.js +0 -41
  188. package/dist/runtime/server/api/customer/cards/delete.d.ts +0 -2
  189. package/dist/runtime/server/api/customer/cards/delete.js +0 -22
  190. package/dist/runtime/server/api/customer/cards/get.d.ts +0 -2
  191. package/dist/runtime/server/api/customer/cards/get.js +0 -16
  192. package/dist/runtime/server/api/customer/change-password.d.ts +0 -14
  193. package/dist/runtime/server/api/customer/change-password.js +0 -33
  194. package/dist/runtime/server/api/customer/checkout.d.ts +0 -2
  195. package/dist/runtime/server/api/customer/checkout.js +0 -19
  196. package/dist/runtime/server/api/customer/orders.d.ts +0 -2
  197. package/dist/runtime/server/api/customer/orders.js +0 -16
  198. package/dist/runtime/server/api/customer/profile/update.d.ts +0 -14
  199. package/dist/runtime/server/api/customer/profile/update.js +0 -33
  200. package/dist/runtime/server/api/customer/quotations.d.ts +0 -2
  201. package/dist/runtime/server/api/customer/quotations.js +0 -16
  202. package/dist/runtime/server/api/customer/search.d.ts +0 -2
  203. package/dist/runtime/server/api/customer/search.js +0 -14
  204. package/dist/runtime/server/api/customer/tax-invoice.d.ts +0 -8
  205. package/dist/runtime/server/api/customer/tax-invoice.js +0 -35
  206. package/dist/runtime/server/api/customer/wishlist/add.d.ts +0 -2
  207. package/dist/runtime/server/api/customer/wishlist/add.js +0 -29
  208. package/dist/runtime/server/api/customer/wishlist/createWishList.d.ts +0 -2
  209. package/dist/runtime/server/api/customer/wishlist/createWishList.js +0 -28
  210. package/dist/runtime/server/api/customer/wishlist/deleteWishList.d.ts +0 -2
  211. package/dist/runtime/server/api/customer/wishlist/deleteWishList.js +0 -29
  212. package/dist/runtime/server/api/customer/wishlist/get.d.ts +0 -2
  213. package/dist/runtime/server/api/customer/wishlist/get.js +0 -16
  214. package/dist/runtime/server/api/customer/wishlist/getWishListItems.d.ts +0 -2
  215. package/dist/runtime/server/api/customer/wishlist/getWishListItems.js +0 -20
  216. package/dist/runtime/server/api/customer/wishlist/updateWishList.d.ts +0 -2
  217. package/dist/runtime/server/api/customer/wishlist/updateWishList.js +0 -29
  218. package/dist/runtime/server/api/v2/[...slug].get.d.ts +0 -2
  219. package/dist/runtime/server/api/v2/[...slug].get.js +0 -34
  220. package/dist/runtime/stores/IpLocation.d.ts +0 -109
  221. package/dist/runtime/stores/IpLocation.js +0 -107
  222. package/dist/runtime/utils/api.d.ts +0 -13
  223. package/dist/runtime/utils/api.js +0 -96
  224. /package/dist/runtime/server/api/{auth/register.d.ts → global/[...slug].d.ts} +0 -0
  225. /package/dist/runtime/server/api/{auth/session.get.d.ts → permalink/[...slug].get.d.ts} +0 -0
  226. /package/dist/runtime/server/api/{auth/user/session.d.ts → reviews3.d.ts} +0 -0
@@ -1,109 +0,0 @@
1
- export interface LocationData {
2
- city?: string;
3
- country_name?: string;
4
- country_code?: string;
5
- country_id?: number;
6
- ip?: string;
7
- proxy?: boolean;
8
- region?: string;
9
- region_short?: string;
10
- region_id?: number;
11
- zip_code?: string;
12
- }
13
- export interface LocationResponse {
14
- status: string;
15
- message?: string;
16
- data: LocationData | null;
17
- }
18
- export declare const useIpLocation: import("pinia").StoreDefinition<"IpLocation", {
19
- location: LocationData | null;
20
- loading: boolean;
21
- error: string | null;
22
- }, {
23
- hasLocation: (state: {
24
- location: {
25
- city?: string | undefined;
26
- country_name?: string | undefined;
27
- country_code?: string | undefined;
28
- country_id?: number | undefined;
29
- ip?: string | undefined;
30
- proxy?: boolean | undefined;
31
- region?: string | undefined;
32
- region_short?: string | undefined;
33
- region_id?: number | undefined;
34
- zip_code?: string | undefined;
35
- } | null;
36
- loading: boolean;
37
- error: string | null;
38
- } & import("pinia").PiniaCustomStateProperties<{
39
- location: LocationData | null;
40
- loading: boolean;
41
- error: string | null;
42
- }>) => boolean;
43
- isLoading: (state: {
44
- location: {
45
- city?: string | undefined;
46
- country_name?: string | undefined;
47
- country_code?: string | undefined;
48
- country_id?: number | undefined;
49
- ip?: string | undefined;
50
- proxy?: boolean | undefined;
51
- region?: string | undefined;
52
- region_short?: string | undefined;
53
- region_id?: number | undefined;
54
- zip_code?: string | undefined;
55
- } | null;
56
- loading: boolean;
57
- error: string | null;
58
- } & import("pinia").PiniaCustomStateProperties<{
59
- location: LocationData | null;
60
- loading: boolean;
61
- error: string | null;
62
- }>) => boolean;
63
- locationString: (state: {
64
- location: {
65
- city?: string | undefined;
66
- country_name?: string | undefined;
67
- country_code?: string | undefined;
68
- country_id?: number | undefined;
69
- ip?: string | undefined;
70
- proxy?: boolean | undefined;
71
- region?: string | undefined;
72
- region_short?: string | undefined;
73
- region_id?: number | undefined;
74
- zip_code?: string | undefined;
75
- } | null;
76
- loading: boolean;
77
- error: string | null;
78
- } & import("pinia").PiniaCustomStateProperties<{
79
- location: LocationData | null;
80
- loading: boolean;
81
- error: string | null;
82
- }>) => string;
83
- fullAddress: (state: {
84
- location: {
85
- city?: string | undefined;
86
- country_name?: string | undefined;
87
- country_code?: string | undefined;
88
- country_id?: number | undefined;
89
- ip?: string | undefined;
90
- proxy?: boolean | undefined;
91
- region?: string | undefined;
92
- region_short?: string | undefined;
93
- region_id?: number | undefined;
94
- zip_code?: string | undefined;
95
- } | null;
96
- loading: boolean;
97
- error: string | null;
98
- } & import("pinia").PiniaCustomStateProperties<{
99
- location: LocationData | null;
100
- loading: boolean;
101
- error: string | null;
102
- }>) => string;
103
- }, {
104
- getLocation(): Promise<LocationData | null>;
105
- setLocation(locationData: LocationData): void;
106
- updateLocation(partialData: Partial<LocationData>): void;
107
- clearLocation(): void;
108
- clearError(): void;
109
- }>;
@@ -1,107 +0,0 @@
1
- import { defineStore } from "pinia";
2
- import { flowrixApi } from "../middleware/flowrix.js";
3
- import { useRuntimeConfig } from "#imports";
4
- function formatErrorMessage(message) {
5
- if (Array.isArray(message)) {
6
- return message.join(", ");
7
- }
8
- return message;
9
- }
10
- export const useIpLocation = defineStore("IpLocation", {
11
- state: () => ({
12
- location: null,
13
- loading: false,
14
- error: null
15
- }),
16
- getters: {
17
- hasLocation: (state) => state.location !== null,
18
- isLoading: (state) => state.loading,
19
- locationString: (state) => {
20
- if (!state.location) return "";
21
- const parts = [
22
- state.location.city,
23
- state.location.region_short || state.location.region,
24
- state.location.zip_code
25
- ].filter(Boolean);
26
- return parts.join(", ");
27
- },
28
- fullAddress: (state) => {
29
- if (!state.location) return "";
30
- const parts = [
31
- state.location.city,
32
- state.location.region,
33
- state.location.zip_code,
34
- state.location.country_name
35
- ].filter(Boolean);
36
- return parts.join(", ");
37
- }
38
- },
39
- actions: {
40
- async getLocation() {
41
- if (this.loading || this.location !== null) {
42
- console.log("Location already loaded or loading:", this.location);
43
- return this.location;
44
- }
45
- this.loading = true;
46
- this.error = null;
47
- try {
48
- const config = useRuntimeConfig();
49
- let rawCookies = "";
50
- if (process.client) {
51
- rawCookies = document.cookie || "";
52
- }
53
- const apiConfig = {
54
- ...config,
55
- cookies: rawCookies
56
- };
57
- const apiUrl = "location";
58
- const response = await flowrixApi.post(apiUrl, apiConfig);
59
- if (response.status === "Success" && response.data !== null) {
60
- this.location = response.data;
61
- console.log("Location loaded:", this.location);
62
- return response.data;
63
- } else {
64
- const errorMessage = response.message ? formatErrorMessage(response.message) : "Failed to fetch location";
65
- this.error = errorMessage;
66
- console.error("Failed to fetch location:", errorMessage);
67
- this.location = null;
68
- return null;
69
- }
70
- } catch (error) {
71
- console.error("Error fetching location:", error);
72
- this.error = error.message || "Unknown error occurred";
73
- this.location = null;
74
- return null;
75
- } finally {
76
- this.loading = false;
77
- }
78
- },
79
- setLocation(locationData) {
80
- this.location = locationData;
81
- this.error = null;
82
- console.log("Location set manually:", this.location);
83
- },
84
- updateLocation(partialData) {
85
- if (this.location) {
86
- this.location = { ...this.location, ...partialData };
87
- console.log("Location updated:", this.location);
88
- } else {
89
- console.warn("Cannot update location: no location data exists");
90
- }
91
- },
92
- clearLocation() {
93
- this.location = null;
94
- this.error = null;
95
- this.loading = false;
96
- console.log("Location cleared");
97
- },
98
- clearError() {
99
- this.error = null;
100
- }
101
- },
102
- persist: {
103
- key: "IpLocation",
104
- storage: typeof window !== "undefined" ? localStorage : void 0,
105
- paths: ["location"]
106
- }
107
- });
@@ -1,13 +0,0 @@
1
- import type { FetchOptions } from "ofetch";
2
- export interface ApiErrorResponse {
3
- status: string;
4
- message: string | Record<string, string[]>;
5
- data: any;
6
- }
7
- export declare function useApi(): {
8
- get: <T>(url: string, options?: FetchOptions, extraHeaders?: Record<string, string>) => Promise<T>;
9
- post: <T>(url: string, data: any, options?: FetchOptions, extraHeaders?: Record<string, string>) => Promise<T>;
10
- patch: <T>(url: string, data: any, options?: FetchOptions, extraHeaders?: Record<string, string>) => Promise<T>;
11
- put: <T>(url: string, data: any, options?: FetchOptions, extraHeaders?: Record<string, string>) => Promise<T>;
12
- delete: <T>(url: string, options?: FetchOptions, extraHeaders?: Record<string, string>) => Promise<T>;
13
- };
@@ -1,96 +0,0 @@
1
- import { useRuntimeConfig } from "nuxt/app";
2
- import { useCookie } from "nuxt/app";
3
- import { useAuthStore } from "../stores/auth.js";
4
- function getLocationHeaders() {
5
- const headers = {};
6
- if (process.client) {
7
- try {
8
- const locationCookie = useCookie("location");
9
- if (locationCookie.value && typeof locationCookie.value === "object") {
10
- const location = locationCookie.value;
11
- if (location.country) {
12
- headers["shipping-country"] = location.country_id;
13
- }
14
- }
15
- const ipLocationCookie = useCookie("IpLocation");
16
- if (ipLocationCookie.value && typeof ipLocationCookie.value === "object") {
17
- const ipLocation = ipLocationCookie.value;
18
- const locationData = ipLocation.location;
19
- if (locationData) {
20
- if (locationData.country_id && !headers["shipping-country"]) {
21
- headers["shipping-country"] = locationData.country_id;
22
- }
23
- if (locationData.region_id) {
24
- headers["shipping-region"] = locationData.region_id;
25
- }
26
- if (locationData.zip_code) {
27
- headers["shipping-postcode"] = locationData.zip_code;
28
- }
29
- }
30
- }
31
- } catch (error) {
32
- console.warn("Failed to read location cookies on client:", error);
33
- }
34
- }
35
- return headers;
36
- }
37
- export function useApi() {
38
- const authStore = useAuthStore();
39
- const config = useRuntimeConfig();
40
- const FLOWRIX_API_KEY = config.FLOWRIX_API_KEY;
41
- const FLOWRIX_API_ORIGIN = config.FLOWRIX_API_ORIGIN;
42
- const FLOWRIX_API_BASE = config.FLOWRIX_API_BASE;
43
- const baseURL = FLOWRIX_API_BASE || "";
44
- async function request(method, url, data = null, options = {}, extraHeaders = {}) {
45
- const locationHeaders = getLocationHeaders();
46
- const headers = {
47
- "Content-Type": "application/json",
48
- "x-public-key": FLOWRIX_API_KEY,
49
- // Add location headers from cookies
50
- ...locationHeaders,
51
- // Add extra headers
52
- ...extraHeaders,
53
- // Add auth header if available (should be last to override if needed)
54
- ...authStore.getToken ? { Authorization: `Bearer ${authStore.getToken}` } : {}
55
- };
56
- try {
57
- const requestOptions = {
58
- method,
59
- baseURL,
60
- headers,
61
- body: data ? JSON.stringify(data) : void 0,
62
- ...options
63
- };
64
- const response = await $fetch(url, requestOptions);
65
- return response;
66
- } catch (error) {
67
- console.error("API Error:", error);
68
- if (error.response?._data || error.data) {
69
- const apiError = error.response?._data || error.data;
70
- let errorMessage = "An error occurred";
71
- if (apiError.message) {
72
- if (typeof apiError.message === "string") {
73
- errorMessage = apiError.message;
74
- } else if (typeof apiError.message === "object" && apiError.message !== null) {
75
- const errors = Object.values(apiError.message).flat();
76
- errorMessage = errors.join(", ");
77
- }
78
- } else if (apiError.status === "Error") {
79
- errorMessage = "Validation failed. Please check your input.";
80
- }
81
- throw new Error(errorMessage);
82
- }
83
- if (error.statusCode === 422) {
84
- throw new Error("Validation failed. Please check your input.");
85
- }
86
- throw new Error(error.message || "API request failed");
87
- }
88
- }
89
- return {
90
- get: (url, options = {}, extraHeaders = {}) => request("GET", url, null, options, extraHeaders),
91
- post: (url, data, options = {}, extraHeaders = {}) => request("POST", url, data, options, extraHeaders),
92
- patch: (url, data, options = {}, extraHeaders = {}) => request("PATCH", url, data, options, extraHeaders),
93
- put: (url, data, options = {}, extraHeaders = {}) => request("PUT", url, data, options, extraHeaders),
94
- delete: (url, options = {}, extraHeaders = {}) => request("DELETE", url, null, options, extraHeaders)
95
- };
96
- }