flowrix 1.0.1-beta.9 → 1.0.1-beta.92

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 (232) hide show
  1. package/dist/module.d.mts +1 -6
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +103 -34
  4. package/dist/runtime/composables/Blog/useBlogIndex.d.ts +2 -5
  5. package/dist/runtime/composables/Brand/brand.js +2 -0
  6. package/dist/runtime/composables/Cart/useCart.d.ts +40 -0
  7. package/dist/runtime/composables/Cart/useCart.js +10 -0
  8. package/dist/runtime/composables/Cart/useCartDetail.d.ts +15 -5
  9. package/dist/runtime/composables/Cart/useCartDetail.js +3 -0
  10. package/dist/runtime/composables/Checkout/PaymentMethods/useFlowrixpay.d.ts +40 -1
  11. package/dist/runtime/composables/Checkout/PaymentMethods/useFlowrixpay.js +2 -2
  12. package/dist/runtime/composables/Checkout/PaymentMethods/useOpayo.d.ts +40 -1
  13. package/dist/runtime/composables/Checkout/PaymentMethods/useOpayo.js +2 -2
  14. package/dist/runtime/composables/Checkout/PaymentMethods/usePaymentMethods.js +3 -14
  15. package/dist/runtime/composables/Checkout/PaymentMethods/useStripe.d.ts +2 -2
  16. package/dist/runtime/composables/Checkout/useCheckout.d.ts +84 -73
  17. package/dist/runtime/composables/Checkout/useCheckout.js +81 -34
  18. package/dist/runtime/composables/Checkout/useCheckoutBillingAddress.d.ts +43 -0
  19. package/dist/runtime/composables/Checkout/useCheckoutBillingAddress.js +84 -0
  20. package/dist/runtime/composables/Checkout/useCheckoutShippingAddress.d.ts +55 -0
  21. package/dist/runtime/composables/Checkout/useCheckoutShippingAddress.js +196 -0
  22. package/dist/runtime/composables/Checkout/useCreateAccount.d.ts +7 -7
  23. package/dist/runtime/composables/Checkout/useCreateAccount.js +3 -1
  24. package/dist/runtime/composables/Checkout/useDeliveryMethod.d.ts +2 -2
  25. package/dist/runtime/composables/Checkout/useDeliveryMethod.js +8 -7
  26. package/dist/runtime/composables/Customer/useBillingAddress.d.ts +112 -0
  27. package/dist/runtime/composables/Customer/useBillingAddress.js +93 -0
  28. package/dist/runtime/composables/Customer/useLogin.d.ts +9 -0
  29. package/dist/runtime/composables/Customer/useLogin.js +34 -0
  30. package/dist/runtime/composables/Customer/useOrders.d.ts +29 -0
  31. package/dist/runtime/composables/Customer/useOrders.js +56 -0
  32. package/dist/runtime/composables/Customer/usePasswordReset.d.ts +26 -0
  33. package/dist/runtime/composables/Customer/usePasswordReset.js +258 -0
  34. package/dist/runtime/composables/Customer/useProfile.d.ts +75 -0
  35. package/dist/runtime/composables/Customer/useProfile.js +106 -0
  36. package/dist/runtime/composables/Customer/useQuotations.d.ts +32 -0
  37. package/dist/runtime/composables/Customer/useQuotations.js +40 -0
  38. package/dist/runtime/composables/Customer/useRegister.d.ts +120 -11
  39. package/dist/runtime/composables/Customer/useRegister.js +311 -34
  40. package/dist/runtime/composables/Customer/useShippingAddress.d.ts +121 -0
  41. package/dist/runtime/composables/Customer/useShippingAddress.js +145 -0
  42. package/dist/runtime/composables/Customer/useUpdatePassword.d.ts +21 -0
  43. package/dist/runtime/composables/Customer/useUpdatePassword.js +94 -0
  44. package/dist/runtime/composables/Customer/useUserCards.d.ts +22 -0
  45. package/dist/runtime/composables/Customer/useUserCards.js +65 -0
  46. package/dist/runtime/composables/{useWishlists.d.ts → Customer/useWishlists.d.ts} +6 -19
  47. package/dist/runtime/composables/{useWishlists.js → Customer/useWishlists.js} +21 -29
  48. package/dist/runtime/composables/Extras/useCountry.d.ts +11 -6
  49. package/dist/runtime/composables/Extras/useCountry.js +5 -4
  50. package/dist/runtime/composables/Header/useHeader.d.ts +6 -20
  51. package/dist/runtime/composables/Header/useHeader.js +3 -2
  52. package/dist/runtime/composables/Product/CustomProduct/useCustomeScript.js +4 -4
  53. package/dist/runtime/composables/Product/CustomProduct/useSteps.d.ts +1 -1
  54. package/dist/runtime/composables/Product/useProductComponent.js +2 -0
  55. package/dist/runtime/composables/Product/useProductSlug.d.ts +8 -1
  56. package/dist/runtime/composables/Product/useQuickView.d.ts +8 -0
  57. package/dist/runtime/composables/Product/useQuickView.js +27 -0
  58. package/dist/runtime/composables/Product/useService.d.ts +1 -1
  59. package/dist/runtime/composables/Product/useService.js +0 -3
  60. package/dist/runtime/composables/SideBar/Filters/useFilters.d.ts +2 -2
  61. package/dist/runtime/composables/SideBar/Filters/useSorting.d.ts +2 -2
  62. package/dist/runtime/composables/index.d.ts +16 -12
  63. package/dist/runtime/composables/index.js +16 -12
  64. package/dist/runtime/composables/useAddresses.js +6 -6
  65. package/dist/runtime/composables/useCards.js +2 -2
  66. package/dist/runtime/composables/useDataLayer.js +2 -1
  67. package/dist/runtime/composables/useLocation.d.ts +2 -12
  68. package/dist/runtime/composables/useQuotationCheckout.d.ts +78 -0
  69. package/dist/runtime/composables/useQuotationCheckout.js +138 -0
  70. package/dist/runtime/middleware/flowrix.d.ts +5 -4
  71. package/dist/runtime/middleware/flowrix.js +41 -21
  72. package/dist/runtime/pages/flowrix-default.d.vue.ts +3 -0
  73. package/dist/runtime/pages/flowrix-default.vue +34 -0
  74. package/dist/runtime/pages/flowrix-default.vue.d.ts +3 -0
  75. package/dist/runtime/plugin.d.ts +1 -1
  76. package/dist/runtime/server/api/albums.d.ts +1 -0
  77. package/dist/runtime/server/api/albums.js +38 -12
  78. package/dist/runtime/server/api/auth/forgot.js +1 -1
  79. package/dist/runtime/server/api/auth/login.js +5 -6
  80. package/dist/runtime/server/api/auth/logout.js +1 -1
  81. package/dist/runtime/server/api/auth/register.js +1 -1
  82. package/dist/runtime/server/api/auth/session.get.js +1 -1
  83. package/dist/runtime/server/api/auth/user/reset-password.js +1 -1
  84. package/dist/runtime/server/api/auth/user/session.js +1 -1
  85. package/dist/runtime/server/api/auth/user/verify-token.js +1 -1
  86. package/dist/runtime/server/api/banners.js +15 -12
  87. package/dist/runtime/server/api/brand/[...slug].js +55 -0
  88. package/dist/runtime/server/api/brand/index.d.ts +3 -0
  89. package/dist/runtime/server/api/brand/index.js +49 -0
  90. package/dist/runtime/server/api/cache/[...slug].delete.d.ts +2 -0
  91. package/dist/runtime/server/api/cache/[...slug].delete.js +40 -0
  92. package/dist/runtime/server/api/cache/clean.get.d.ts +5 -0
  93. package/dist/runtime/server/api/cache/clean.get.js +16 -0
  94. package/dist/runtime/server/api/cart/[slug]/add.d.ts +1 -1
  95. package/dist/runtime/server/api/cart/[slug]/add.js +11 -11
  96. package/dist/runtime/server/api/cart/[slug]/update.d.ts +1 -1
  97. package/dist/runtime/server/api/cart/[slug]/update.js +11 -11
  98. package/dist/runtime/server/api/{blog/blog.d.ts → cart/related.d.ts} +0 -1
  99. package/dist/runtime/server/api/cart/related.js +21 -0
  100. package/dist/runtime/server/api/cart/remove.js +1 -1
  101. package/dist/runtime/server/api/cart/service/[slug]/add.d.ts +1 -1
  102. package/dist/runtime/server/api/cart/service/[slug]/add.js +12 -12
  103. package/dist/runtime/server/api/catalog/brands.d.ts +3 -0
  104. package/dist/runtime/server/api/catalog/brands.js +49 -0
  105. package/dist/runtime/server/api/catalog/categories.js +22 -16
  106. package/dist/runtime/server/api/catalog/categoriesall.d.ts +3 -0
  107. package/dist/runtime/server/api/catalog/categoriesall.js +49 -0
  108. package/dist/runtime/server/api/catalog/featured.js +22 -14
  109. package/dist/runtime/server/api/catalog/posts.d.ts +3 -0
  110. package/dist/runtime/server/api/catalog/posts.js +49 -0
  111. package/dist/runtime/server/api/catalog/samples.js +22 -16
  112. package/dist/runtime/server/api/catalog/search.js +21 -15
  113. package/dist/runtime/server/api/category/[...slug].js +22 -16
  114. package/dist/runtime/server/api/checkout/applyCoupon.d.ts +1 -1
  115. package/dist/runtime/server/api/checkout/applyCoupon.js +13 -13
  116. package/dist/runtime/server/api/checkout/configs.d.ts +1 -1
  117. package/dist/runtime/server/api/checkout/configs.js +11 -11
  118. package/dist/runtime/server/api/checkout/countries.d.ts +1 -1
  119. package/dist/runtime/server/api/checkout/countries.js +5 -9
  120. package/dist/runtime/server/api/checkout/paymentmethod.d.ts +1 -1
  121. package/dist/runtime/server/api/checkout/paymentmethod.js +16 -11
  122. package/dist/runtime/server/api/checkout/quotation/[slug].d.ts +2 -0
  123. package/dist/runtime/server/api/checkout/quotation/[slug].js +21 -0
  124. package/dist/runtime/server/api/checkout/quotation/guest/[slug].d.ts +2 -0
  125. package/dist/runtime/server/api/checkout/quotation/guest/[slug].js +37 -0
  126. package/dist/runtime/server/api/checkout/quotation/guest/customer.d.ts +2 -0
  127. package/dist/runtime/server/api/checkout/quotation/guest/customer.js +21 -0
  128. package/dist/runtime/server/api/checkout/quotation/submit/[slug].d.ts +2 -0
  129. package/dist/runtime/server/api/checkout/quotation/submit/[slug].js +23 -0
  130. package/dist/runtime/server/api/{blog/[slug].js → cmspost/[...slug].js} +19 -18
  131. package/dist/runtime/server/api/cmspost/all.d.ts +3 -0
  132. package/dist/runtime/server/api/cmspost/all.js +49 -0
  133. package/dist/runtime/server/api/company/profile.d.ts +1 -1
  134. package/dist/runtime/server/api/company/profile.js +9 -9
  135. package/dist/runtime/server/api/contact-center/webforms/[id]/details.d.ts +1 -1
  136. package/dist/runtime/server/api/contact-center/webforms/[id]/details.js +48 -15
  137. package/dist/runtime/server/api/contact-center/webforms/create.d.ts +1 -1
  138. package/dist/runtime/server/api/contact-center/webforms/create.js +10 -10
  139. package/dist/runtime/server/api/countries.d.ts +2 -0
  140. package/dist/runtime/server/api/countries.js +42 -0
  141. package/dist/runtime/server/api/customer/address/add.js +1 -1
  142. package/dist/runtime/server/api/customer/address/delete.js +2 -2
  143. package/dist/runtime/server/api/customer/address/setshipping.js +1 -1
  144. package/dist/runtime/server/api/customer/address/update.js +1 -1
  145. package/dist/runtime/server/api/customer/cards/delete.js +2 -2
  146. package/dist/runtime/server/api/customer/cards/get.js +2 -2
  147. package/dist/runtime/server/api/customer/change-password.js +2 -2
  148. package/dist/runtime/server/api/customer/checkout.js +1 -1
  149. package/dist/runtime/server/api/customer/orders.js +2 -2
  150. package/dist/runtime/server/api/customer/profile/update.js +1 -1
  151. package/dist/runtime/server/api/customer/quotations.js +2 -2
  152. package/dist/runtime/server/api/customer/search.js +1 -1
  153. package/dist/runtime/server/api/customer/tax-invoice.js +1 -1
  154. package/dist/runtime/server/api/customer/wishlist/add.js +1 -1
  155. package/dist/runtime/server/api/customer/wishlist/createWishList.js +1 -1
  156. package/dist/runtime/server/api/customer/wishlist/deleteFromWishList.js +1 -1
  157. package/dist/runtime/server/api/customer/wishlist/deleteWishList.js +1 -1
  158. package/dist/runtime/server/api/customer/wishlist/get.js +2 -2
  159. package/dist/runtime/server/api/customer/wishlist/getWishListItems.js +1 -1
  160. package/dist/runtime/server/api/customer/wishlist/updateWishList.js +2 -2
  161. package/dist/runtime/server/api/featured.d.ts +3 -0
  162. package/dist/runtime/server/api/featured.js +49 -0
  163. package/dist/runtime/server/api/generate/robots.get.d.ts +2 -0
  164. package/dist/runtime/server/api/generate/robots.get.js +20 -0
  165. package/dist/runtime/server/api/generate/sitemap.get.d.ts +2 -0
  166. package/dist/runtime/server/api/generate/sitemap.get.js +32 -0
  167. package/dist/runtime/server/api/location.d.ts +1 -1
  168. package/dist/runtime/server/api/location.js +20 -12
  169. package/dist/runtime/server/api/nav/[id]/links.d.ts +1 -0
  170. package/dist/runtime/server/api/nav/[id]/links.js +48 -14
  171. package/dist/runtime/server/api/page/{[slug].js → [...slug].js} +18 -17
  172. package/dist/runtime/server/api/product/[...slug].js +23 -9
  173. package/dist/runtime/server/api/{v2/[...slug].d.ts → quickview/[slug].d.ts} +0 -1
  174. package/dist/runtime/server/api/quickview/[slug].js +17 -0
  175. package/dist/runtime/server/api/reviews.d.ts +2 -0
  176. package/dist/runtime/server/api/reviews.js +18 -0
  177. package/dist/runtime/server/api/samples.d.ts +3 -0
  178. package/dist/runtime/server/api/samples.js +50 -0
  179. package/dist/runtime/server/api/search.d.ts +3 -0
  180. package/dist/runtime/server/api/search.js +50 -0
  181. package/dist/runtime/server/api/service/[slug].js +17 -13
  182. package/dist/runtime/server/api/service/availability.d.ts +1 -1
  183. package/dist/runtime/server/api/service/availability.js +11 -13
  184. package/dist/runtime/server/api/service/getall.d.ts +3 -0
  185. package/dist/runtime/server/api/service/getall.js +55 -0
  186. package/dist/runtime/server/api/shop.d.ts +3 -0
  187. package/dist/runtime/server/api/shop.js +50 -0
  188. package/dist/runtime/server/api/subscribe.d.ts +1 -1
  189. package/dist/runtime/server/api/subscribe.js +19 -14
  190. package/dist/runtime/server/api/v2/[...slug].get.d.ts +2 -0
  191. package/dist/runtime/server/api/v2/[...slug].get.js +16 -0
  192. package/dist/runtime/server/api/webform.d.ts +3 -0
  193. package/dist/runtime/server/api/webform.js +52 -0
  194. package/dist/runtime/server/tsconfig.json +3 -3
  195. package/dist/runtime/stores/Cart.d.ts +12 -0
  196. package/dist/runtime/stores/Cart.js +56 -19
  197. package/dist/runtime/stores/Checkout.d.ts +9 -15
  198. package/dist/runtime/stores/Checkout.js +19 -24
  199. package/dist/runtime/stores/Search.d.ts +1 -1
  200. package/dist/runtime/stores/Services.js +2 -2
  201. package/dist/runtime/stores/auth.d.ts +8 -11
  202. package/dist/runtime/stores/auth.js +390 -8
  203. package/dist/runtime/stores/countries.d.ts +1 -3
  204. package/dist/runtime/stores/countries.js +4 -8
  205. package/dist/runtime/stores/product/slug.d.ts +1 -17
  206. package/dist/runtime/stores/wishlists.d.ts +114 -6
  207. package/dist/runtime/stores/wishlists.js +209 -9
  208. package/dist/runtime/utils/api.js +9 -13
  209. package/dist/runtime/utils/htmlCache.d.ts +2 -2
  210. package/dist/runtime/utils/htmlCache.js +23 -13
  211. package/dist/types.d.mts +6 -2
  212. package/package.json +30 -20
  213. package/dist/runtime/composables/Checkout/useBillingAddress.d.ts +0 -19
  214. package/dist/runtime/composables/Checkout/useBillingAddress.js +0 -82
  215. package/dist/runtime/composables/Checkout/useShippingAddress.d.ts +0 -9
  216. package/dist/runtime/composables/Checkout/useShippingAddress.js +0 -121
  217. package/dist/runtime/composables/useAuth.d.ts +0 -45
  218. package/dist/runtime/composables/useAuth.js +0 -180
  219. package/dist/runtime/composables/useCountries.d.ts +0 -12
  220. package/dist/runtime/composables/useCountries.js +0 -50
  221. package/dist/runtime/composables/useOrders.d.ts +0 -21
  222. package/dist/runtime/composables/useOrders.js +0 -82
  223. package/dist/runtime/composables/useQuotations.d.ts +0 -14
  224. package/dist/runtime/composables/useQuotations.js +0 -50
  225. package/dist/runtime/plugins/fullReload.client.d.ts +0 -2
  226. package/dist/runtime/plugins/fullReload.client.js +0 -10
  227. package/dist/runtime/server/api/blog/blog.js +0 -17
  228. package/dist/runtime/server/api/brand/[slug].js +0 -58
  229. package/dist/runtime/server/api/v2/[...slug].js +0 -9
  230. /package/dist/runtime/server/api/brand/{[slug].d.ts → [...slug].d.ts} +0 -0
  231. /package/dist/runtime/server/api/{blog/[slug].d.ts → cmspost/[...slug].d.ts} +0 -0
  232. /package/dist/runtime/server/api/page/{[slug].d.ts → [...slug].d.ts} +0 -0
@@ -1,19 +1,53 @@
1
- import { defineEventHandler, setResponseStatus, getRouterParam } from "h3";
2
- import { $fetch } from "ofetch";
1
+ import { defineEventHandler, getRouterParam, getQuery, createError, getCookie } from "h3";
2
+ import { writeFile, mkdir, readFile } from "fs/promises";
3
+ import { join } from "path";
4
+ import { flowrixApi } from "../../../../middleware/flowrix.js";
5
+ import { useRuntimeConfig } from "#imports";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "navigation");
7
+ export const menuCache = /* @__PURE__ */ new Map();
8
+ async function ensureCacheDir() {
9
+ try {
10
+ await mkdir(CACHE_DIR, { recursive: true });
11
+ } catch (error) {
12
+ console.error("Error creating cache directory:", error);
13
+ }
14
+ }
3
15
  export default defineEventHandler(async (event) => {
4
- const id = getRouterParam(event, "id");
16
+ const slug = getRouterParam(event, "id");
17
+ const customerType = getCookie(event, "customertype") || "";
18
+ let query = getQuery(event);
19
+ if (!slug) {
20
+ throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
21
+ }
22
+ if (!/^[a-zA-Z0-9-_]+$/.test(slug)) {
23
+ }
24
+ const cacheKey = `${slug}-${JSON.stringify(query)}`;
25
+ const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
26
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
5
27
  try {
6
- const response = await $fetch(`${process.env.FLOWRIX_API_BASE}nav/${id}/links`, {
7
- method: "GET",
8
- headers: {
9
- "x-api-key": process.env.FLOWRIX_API_KEY,
10
- "x-api-secret": process.env.FLOWRIX_API_SECRET,
11
- "Origin": process.env.FLOWRIX_API_ORIGIN
12
- }
13
- });
14
- return response;
28
+ const fileContent = await readFile(filePath, "utf-8");
29
+ const menu = JSON.parse(fileContent);
30
+ return menu;
15
31
  } catch (error) {
16
- setResponseStatus(event, 500);
17
- return { success: false, error: error.message };
32
+ }
33
+ try {
34
+ const config = useRuntimeConfig();
35
+ const rawCookies = event.req.headers.cookie || "";
36
+ const apiConfig = {
37
+ ...config,
38
+ cookies: rawCookies
39
+ };
40
+ const menu = await flowrixApi.get(`nav/${slug}/links`, apiConfig, {});
41
+ if (config.public.FLOWRIX_CACHE == true) {
42
+ await ensureCacheDir();
43
+ await writeFile(filePath, JSON.stringify(menu, null, 2), "utf-8");
44
+ }
45
+ return menu;
46
+ } catch (error) {
47
+ throw createError({
48
+ statusCode: 500,
49
+ statusMessage: `Failed to fetch menu for id = ${slug}`,
50
+ data: error.message
51
+ });
18
52
  }
19
53
  });
@@ -1,8 +1,9 @@
1
- import { defineEventHandler, getRouterParam, getQuery, createError, readBody } from "h3";
2
- import { $fetch } from "ofetch";
1
+ import { defineEventHandler, getQuery, createError, readBody, getCookie } from "h3";
3
2
  import { writeFile, mkdir, readFile } from "fs/promises";
4
3
  import { join } from "path";
5
- const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "pages");
4
+ import { useRuntimeConfig } from "#imports";
5
+ import { flowrixApi } from "../../../middleware/flowrix.js";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "pages");
6
7
  export const pageCache = /* @__PURE__ */ new Map();
7
8
  async function ensureCacheDir() {
8
9
  try {
@@ -12,18 +13,16 @@ async function ensureCacheDir() {
12
13
  }
13
14
  }
14
15
  export default defineEventHandler(async (event) => {
15
- const slug = getRouterParam(event, "slug");
16
+ const slug = event.context.params._;
17
+ const customerType = getCookie(event, "customertype") || "";
16
18
  const query = getQuery(event);
17
19
  const body = await readBody(event);
18
20
  if (!slug) {
19
21
  throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
20
22
  }
21
- if (!/^[a-zA-Z0-9-_]+$/.test(slug)) {
22
- throw createError({ statusCode: 400, statusMessage: "Invalid slug" });
23
- }
24
23
  const cacheKey = `${slug}-${JSON.stringify(query)}`;
25
24
  const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
26
- const filePath = join(CACHE_DIR, `${fileName}.json`);
25
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
27
26
  try {
28
27
  const fileContent = await readFile(filePath, "utf-8");
29
28
  const page = JSON.parse(fileContent);
@@ -31,15 +30,17 @@ export default defineEventHandler(async (event) => {
31
30
  } catch (error) {
32
31
  }
33
32
  try {
34
- const page = await $fetch(`${process.env.FLOWRIX_API_BASE}page/${slug}`, {
35
- headers: {
36
- "x-api-key": process.env.FLOWRIX_API_KEY,
37
- "x-api-secret": process.env.FLOWRIX_API_SECRET,
38
- "Origin": process.env.FLOWRIX_API_ORIGIN
39
- }
40
- });
41
- await ensureCacheDir();
42
- await writeFile(filePath, JSON.stringify(page, null, 2), "utf-8");
33
+ const config = useRuntimeConfig();
34
+ const rawCookies = event.req.headers.cookie || "";
35
+ const apiConfig = {
36
+ ...config,
37
+ cookies: rawCookies
38
+ };
39
+ const page = await flowrixApi.get(`page/${slug}`, apiConfig, {});
40
+ if (config.public.FLOWRIX_CACHE == true) {
41
+ await ensureCacheDir();
42
+ await writeFile(filePath, JSON.stringify(page, null, 2), "utf-8");
43
+ }
43
44
  return page;
44
45
  } catch (error) {
45
46
  throw createError({
@@ -1,8 +1,9 @@
1
- import { defineEventHandler, getQuery, createError, readBody } from "h3";
1
+ import { defineEventHandler, getQuery, createError, readBody, getCookie } from "h3";
2
2
  import { writeFile, mkdir, readFile } from "fs/promises";
3
3
  import { join } from "path";
4
4
  import { flowrixApi } from "../../../middleware/flowrix.js";
5
- const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "products");
5
+ import { useRuntimeConfig } from "#imports";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "products");
6
7
  export const productCache = /* @__PURE__ */ new Map();
7
8
  async function ensureCacheDir() {
8
9
  try {
@@ -13,14 +14,15 @@ async function ensureCacheDir() {
13
14
  }
14
15
  export default defineEventHandler(async (event) => {
15
16
  const slug = event.context.params._;
16
- const query = getQuery(event);
17
+ const customerType = getCookie(event, "customertype") || "";
18
+ let query = getQuery(event);
17
19
  const body = await readBody(event);
18
20
  if (!slug) {
19
21
  throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
20
22
  }
21
23
  const cacheKey = `${slug}-${JSON.stringify(query)}`;
22
24
  const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
23
- const filePath = join(CACHE_DIR, `${fileName}.json`);
25
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
24
26
  try {
25
27
  const fileContent = await readFile(filePath, "utf-8");
26
28
  const product = JSON.parse(fileContent);
@@ -28,11 +30,23 @@ export default defineEventHandler(async (event) => {
28
30
  } catch (error) {
29
31
  }
30
32
  try {
31
- const product = await flowrixApi.post(`product/${slug}`, {
32
- body: JSON.stringify(body)
33
- }, "v2");
34
- await ensureCacheDir();
35
- await writeFile(filePath, JSON.stringify(product, null, 2), "utf-8");
33
+ const config = useRuntimeConfig();
34
+ const rawCookies = event.req.headers.cookie || "";
35
+ const apiConfig = {
36
+ ...config,
37
+ cookies: rawCookies
38
+ };
39
+ query = {
40
+ ...query
41
+ };
42
+ const product = await flowrixApi.post(`product/${slug}`, apiConfig, {
43
+ body: JSON.stringify(body),
44
+ query
45
+ });
46
+ if (config.public.FLOWRIX_CACHE == true) {
47
+ await ensureCacheDir();
48
+ await writeFile(filePath, JSON.stringify(product, null, 2), "utf-8");
49
+ }
36
50
  return product;
37
51
  } catch (error) {
38
52
  throw createError({
@@ -1,3 +1,2 @@
1
- export declare const Page: Map<any, any>;
2
1
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
3
2
  export default _default;
@@ -0,0 +1,17 @@
1
+ import { defineEventHandler, getRouterParam, readBody } from "h3";
2
+ import { flowrixApi } from "../../../middleware/flowrix.js";
3
+ import { useRuntimeConfig } from "#imports";
4
+ export default defineEventHandler(async (event) => {
5
+ const slug = getRouterParam(event, "slug");
6
+ const body = await readBody(event);
7
+ const config = useRuntimeConfig();
8
+ const rawCookies = event.req.headers.cookie || "";
9
+ const apiConfig = {
10
+ ...config,
11
+ cookies: rawCookies
12
+ };
13
+ const quickview = await flowrixApi.post(`quickview/${slug}`, apiConfig, {
14
+ body: JSON.stringify(body)
15
+ });
16
+ return quickview;
17
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
2
+ export default _default;
@@ -0,0 +1,18 @@
1
+ import { defineEventHandler, setResponseStatus } from "h3";
2
+ import { useRuntimeConfig } from "#imports";
3
+ import { flowrixApi } from "../../middleware/flowrix.js";
4
+ export default defineEventHandler(async (event) => {
5
+ try {
6
+ const config = useRuntimeConfig();
7
+ const rawCookies = event.req.headers.cookie || "";
8
+ const apiConfig = {
9
+ ...config,
10
+ cookies: rawCookies
11
+ };
12
+ const reviews = await flowrixApi.get(`reviews`, apiConfig, {});
13
+ return reviews;
14
+ } catch (error) {
15
+ setResponseStatus(event, 500);
16
+ return { success: false, error: error.message };
17
+ }
18
+ });
@@ -0,0 +1,3 @@
1
+ export declare const catelogCache: Map<any, any>;
2
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
3
+ export default _default;
@@ -0,0 +1,50 @@
1
+ import { defineEventHandler, getQuery, createError, getCookie } from "h3";
2
+ import { writeFile, mkdir, readFile } from "fs/promises";
3
+ import { join } from "path";
4
+ import { useRuntimeConfig } from "#imports";
5
+ import { flowrixApi } from "../../middleware/flowrix.js";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
7
+ export const catelogCache = /* @__PURE__ */ new Map();
8
+ async function ensureCacheDir() {
9
+ try {
10
+ await mkdir(CACHE_DIR, { recursive: true });
11
+ } catch (error) {
12
+ console.error("Error creating cache directory:", error);
13
+ }
14
+ }
15
+ export default defineEventHandler(async (event) => {
16
+ let query = getQuery(event);
17
+ const customerType = getCookie(event, "customertype") || "";
18
+ const cacheKey = `samples-${JSON.stringify(query)}`;
19
+ const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
20
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
21
+ try {
22
+ const fileContent = await readFile(filePath, "utf-8");
23
+ const catelog = JSON.parse(fileContent);
24
+ return catelog;
25
+ } catch (error) {
26
+ }
27
+ try {
28
+ const config = useRuntimeConfig();
29
+ const rawCookies = event.req.headers.cookie || "";
30
+ const apiConfig = {
31
+ ...config,
32
+ cookies: rawCookies
33
+ };
34
+ query = {
35
+ ...query
36
+ };
37
+ const samples = await flowrixApi.get(`samples`, apiConfig, { query });
38
+ if (config.public.FLOWRIX_CACHE == true) {
39
+ await ensureCacheDir();
40
+ await writeFile(filePath, JSON.stringify(samples, null, 2), "utf-8");
41
+ }
42
+ return samples;
43
+ } catch (error) {
44
+ throw createError({
45
+ statusCode: 500,
46
+ statusMessage: `Failed to fetch samples`,
47
+ data: error.message
48
+ });
49
+ }
50
+ });
@@ -0,0 +1,3 @@
1
+ export declare const catelogCache: Map<any, any>;
2
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
3
+ export default _default;
@@ -0,0 +1,50 @@
1
+ import { defineEventHandler, getQuery, createError, getCookie } from "h3";
2
+ import { writeFile, mkdir, readFile } from "fs/promises";
3
+ import { join } from "path";
4
+ import { useRuntimeConfig } from "#imports";
5
+ import { flowrixApi } from "../../middleware/flowrix.js";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
7
+ export const catelogCache = /* @__PURE__ */ new Map();
8
+ async function ensureCacheDir() {
9
+ try {
10
+ await mkdir(CACHE_DIR, { recursive: true });
11
+ } catch (error) {
12
+ console.error("Error creating cache directory:", error);
13
+ }
14
+ }
15
+ export default defineEventHandler(async (event) => {
16
+ let query = getQuery(event);
17
+ const customerType = getCookie(event, "customertype") || "";
18
+ const cacheKey = `search-${JSON.stringify(query)}`;
19
+ const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
20
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
21
+ try {
22
+ const fileContent = await readFile(filePath, "utf-8");
23
+ const catelog = JSON.parse(fileContent);
24
+ return catelog;
25
+ } catch (error) {
26
+ }
27
+ try {
28
+ const config = useRuntimeConfig();
29
+ const rawCookies = event.req.headers.cookie || "";
30
+ const apiConfig = {
31
+ ...config,
32
+ cookies: rawCookies
33
+ };
34
+ query = {
35
+ ...query
36
+ };
37
+ const search = await flowrixApi.get(`search`, apiConfig, { query });
38
+ if (config.public.FLOWRIX_CACHE == true) {
39
+ await ensureCacheDir();
40
+ await writeFile(filePath, JSON.stringify(search, null, 2), "utf-8");
41
+ }
42
+ return search;
43
+ } catch (error) {
44
+ throw createError({
45
+ statusCode: 500,
46
+ statusMessage: `Failed to fetch catelog for slug: ${slug}`,
47
+ data: error.message
48
+ });
49
+ }
50
+ });
@@ -1,8 +1,9 @@
1
- import { defineEventHandler, getRouterParam, getQuery, createError, readBody } from "h3";
2
- import { $fetch } from "ofetch";
1
+ import { defineEventHandler, getRouterParam, getQuery, createError, readBody, getCookie } from "h3";
3
2
  import { writeFile, mkdir, readFile } from "fs/promises";
4
3
  import { join } from "path";
5
- const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "services");
4
+ import { useRuntimeConfig } from "#imports";
5
+ import { flowrixApi } from "../../../middleware/flowrix.js";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "services");
6
7
  export const serviceCache = /* @__PURE__ */ new Map();
7
8
  async function ensureCacheDir() {
8
9
  try {
@@ -13,6 +14,7 @@ async function ensureCacheDir() {
13
14
  }
14
15
  export default defineEventHandler(async (event) => {
15
16
  const slug = getRouterParam(event, "slug");
17
+ const customerType = getCookie(event, "customertype") || "";
16
18
  const query = getQuery(event);
17
19
  const body = await readBody(event);
18
20
  if (!slug) {
@@ -23,7 +25,7 @@ export default defineEventHandler(async (event) => {
23
25
  }
24
26
  const cacheKey = `${slug}-${JSON.stringify(query)}`;
25
27
  const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
26
- const filePath = join(CACHE_DIR, `${fileName}.json`);
28
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
27
29
  try {
28
30
  const fileContent = await readFile(filePath, "utf-8");
29
31
  const service = JSON.parse(fileContent);
@@ -31,15 +33,17 @@ export default defineEventHandler(async (event) => {
31
33
  } catch (error) {
32
34
  }
33
35
  try {
34
- const service = await $fetch(`${process.env.FLOWRIX_API_BASE}services/${slug}`, {
35
- headers: {
36
- "x-api-key": process.env.FLOWRIX_API_KEY,
37
- "x-api-secret": process.env.FLOWRIX_API_SECRET,
38
- "Origin": process.env.FLOWRIX_API_ORIGIN
39
- }
40
- });
41
- await ensureCacheDir();
42
- await writeFile(filePath, JSON.stringify(service, null, 2), "utf-8");
36
+ const config = useRuntimeConfig();
37
+ const rawCookies = event.req.headers.cookie || "";
38
+ const apiConfig = {
39
+ ...config,
40
+ cookies: rawCookies
41
+ };
42
+ const service = await flowrixApi.get(`services/${slug}`, apiConfig, {});
43
+ if (config.public.FLOWRIX_CACHE == true) {
44
+ await ensureCacheDir();
45
+ await writeFile(filePath, JSON.stringify(service, null, 2), "utf-8");
46
+ }
43
47
  return service;
44
48
  } catch (error) {
45
49
  throw createError({
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
2
2
  export default _default;
@@ -1,25 +1,23 @@
1
+ import { useRuntimeConfig } from "#imports";
1
2
  import { defineEventHandler, readBody } from "h3";
3
+ import { flowrixApi } from "../../../middleware/flowrix.js";
2
4
  export default defineEventHandler(async (event) => {
3
5
  const body = await readBody(event);
4
6
  try {
5
- const response = await fetch(`${process.env.FLOWRIX_API_BASE}services/availability`, {
6
- method: "POST",
7
- headers: {
8
- "x-api-key": process.env.FLOWRIX_API_KEY || "",
9
- "x-api-secret": process.env.FLOWRIX_API_SECRET || "",
10
- "Origin": process.env.FLOWRIX_API_ORIGIN || "",
11
- "Content-Type": "application/json",
12
- "Accept": "application/json"
13
- },
7
+ const config = useRuntimeConfig();
8
+ const rawCookies = event.req.headers.cookie || "";
9
+ const apiConfig = {
10
+ ...config,
11
+ cookies: rawCookies
12
+ };
13
+ const response = await flowrixApi.post(`services/availability`, apiConfig, {
14
14
  body: JSON.stringify(body)
15
15
  });
16
- const responseData = await response.json();
17
- return responseData;
16
+ return response;
18
17
  } catch (error) {
19
- console.error("Error in service availability:", error);
20
18
  return {
21
19
  status: "Error",
22
- statusCode: 500,
20
+ statusCode: 422,
23
21
  message: "Internal server error",
24
22
  error: error.message || "Unknown error"
25
23
  };
@@ -0,0 +1,3 @@
1
+ export declare const serviceCache: Map<any, any>;
2
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
3
+ export default _default;
@@ -0,0 +1,55 @@
1
+ import { defineEventHandler, getQuery, createError, readBody, getCookie } from "h3";
2
+ import { writeFile, mkdir, readFile } from "fs/promises";
3
+ import { join } from "path";
4
+ import { useRuntimeConfig } from "#imports";
5
+ import { flowrixApi } from "../../../middleware/flowrix.js";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "services");
7
+ export const serviceCache = /* @__PURE__ */ new Map();
8
+ async function ensureCacheDir() {
9
+ try {
10
+ await mkdir(CACHE_DIR, { recursive: true });
11
+ } catch (error) {
12
+ console.error("Error creating cache directory:", error);
13
+ }
14
+ }
15
+ export default defineEventHandler(async (event) => {
16
+ const slug = "all";
17
+ const customerType = getCookie(event, "customertype") || "";
18
+ let query = getQuery(event);
19
+ const body = await readBody(event);
20
+ if (!slug) {
21
+ throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
22
+ }
23
+ if (!/^[a-zA-Z0-9-_]+$/.test(slug)) {
24
+ throw createError({ statusCode: 400, statusMessage: "Invalid slug" });
25
+ }
26
+ const cacheKey = `${slug}-${JSON.stringify(query)}`;
27
+ const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
28
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
29
+ try {
30
+ const fileContent = await readFile(filePath, "utf-8");
31
+ const service = JSON.parse(fileContent);
32
+ return service;
33
+ } catch (error) {
34
+ }
35
+ try {
36
+ const config = useRuntimeConfig();
37
+ const rawCookies = event.req.headers.cookie || "";
38
+ const apiConfig = {
39
+ ...config,
40
+ cookies: rawCookies
41
+ };
42
+ const service = await flowrixApi.get(`services`, apiConfig, {});
43
+ if (config.public.FLOWRIX_CACHE == true) {
44
+ await ensureCacheDir();
45
+ await writeFile(filePath, JSON.stringify(service, null, 2), "utf-8");
46
+ }
47
+ return service;
48
+ } catch (error) {
49
+ throw createError({
50
+ statusCode: 500,
51
+ statusMessage: `Failed to fetch services`,
52
+ data: error.message
53
+ });
54
+ }
55
+ });
@@ -0,0 +1,3 @@
1
+ export declare const catelogCache: Map<any, any>;
2
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
3
+ export default _default;
@@ -0,0 +1,50 @@
1
+ import { defineEventHandler, getQuery, createError, getCookie } from "h3";
2
+ import { writeFile, mkdir, readFile } from "fs/promises";
3
+ import { join } from "path";
4
+ import { useRuntimeConfig } from "#imports";
5
+ import { flowrixApi } from "../../middleware/flowrix.js";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
7
+ export const catelogCache = /* @__PURE__ */ new Map();
8
+ async function ensureCacheDir() {
9
+ try {
10
+ await mkdir(CACHE_DIR, { recursive: true });
11
+ } catch (error) {
12
+ console.error("Error creating cache directory:", error);
13
+ }
14
+ }
15
+ export default defineEventHandler(async (event) => {
16
+ let query = getQuery(event);
17
+ const customerType = getCookie(event, "customertype") || "";
18
+ const cacheKey = `search-${JSON.stringify(query)}`;
19
+ const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
20
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
21
+ try {
22
+ const fileContent = await readFile(filePath, "utf-8");
23
+ const catelog = JSON.parse(fileContent);
24
+ return catelog;
25
+ } catch (error) {
26
+ }
27
+ try {
28
+ const config = useRuntimeConfig();
29
+ const rawCookies = event.req.headers.cookie || "";
30
+ const apiConfig = {
31
+ ...config,
32
+ cookies: rawCookies
33
+ };
34
+ query = {
35
+ ...query
36
+ };
37
+ const search = await flowrixApi.get(`search`, apiConfig, { query });
38
+ if (config.public.FLOWRIX_CACHE == true) {
39
+ await ensureCacheDir();
40
+ await writeFile(filePath, JSON.stringify(search, null, 2), "utf-8");
41
+ }
42
+ return search;
43
+ } catch (error) {
44
+ throw createError({
45
+ statusCode: 500,
46
+ statusMessage: `Failed to fetch catelog for slug: ${slug}`,
47
+ data: error.message
48
+ });
49
+ }
50
+ });
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
2
2
  export default _default;
@@ -1,16 +1,21 @@
1
- import { defineEventHandler, readBody } from "h3";
2
- import { $fetch } from "ofetch";
1
+ import { defineEventHandler, readBody, setResponseStatus } from "h3";
2
+ import { flowrixApi } from "../../middleware/flowrix.js";
3
+ import { useRuntimeConfig } from "#imports";
3
4
  export default defineEventHandler(async (event) => {
4
- const body = await readBody(event);
5
- const subscribe = await $fetch(`${process.env.FLOWRIX_API_BASE}subscribe`, {
6
- method: "POST",
7
- headers: {
8
- "x-api-key": process.env.FLOWRIX_API_KEY,
9
- "x-api-secret": process.env.FLOWRIX_API_SECRET,
10
- "Origin": process.env.FLOWRIX_API_ORIGIN,
11
- "Content-Type": "application/json"
12
- },
13
- body: JSON.stringify(body)
14
- });
15
- return subscribe;
5
+ try {
6
+ const body = await readBody(event);
7
+ const config = useRuntimeConfig();
8
+ const rawCookies = event.req.headers.cookie || "";
9
+ const apiConfig = {
10
+ ...config,
11
+ cookies: rawCookies
12
+ };
13
+ const subscribe = await flowrixApi.post(`subscribe`, apiConfig, {
14
+ body: JSON.stringify(body)
15
+ });
16
+ return subscribe;
17
+ } catch (error) {
18
+ setResponseStatus(event, 500);
19
+ return { success: false, error: error.message };
20
+ }
16
21
  });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
2
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { defineEventHandler } from "h3";
2
+ import { flowrixApi } from "../../../middleware/flowrix.js";
3
+ import { useRuntimeConfig } from "#imports";
4
+ export default defineEventHandler(async (event) => {
5
+ const slug = event.context.params._;
6
+ const config = useRuntimeConfig();
7
+ const rawCookies = event.req.headers.cookie || "";
8
+ const apiConfig = {
9
+ ...config,
10
+ cookies: rawCookies
11
+ };
12
+ const page = await flowrixApi.get(`permalink/${slug}`, apiConfig);
13
+ if (page.status === "Success" && page.data.type === "Redirect") {
14
+ }
15
+ return page;
16
+ });
@@ -0,0 +1,3 @@
1
+ export declare const webfromCache: Map<any, any>;
2
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
3
+ export default _default;