flowrix 1.0.1-beta.8 → 1.0.1-beta.80

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 (192) hide show
  1. package/dist/module.d.mts +1 -6
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +94 -29
  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 +36 -28
  18. package/dist/runtime/composables/Checkout/{useBillingAddress.d.ts → useCheckoutBillingAddress.d.ts} +6 -6
  19. package/dist/runtime/composables/Checkout/{useBillingAddress.js → useCheckoutBillingAddress.js} +6 -1
  20. package/dist/runtime/composables/Checkout/{useShippingAddress.d.ts → useCheckoutShippingAddress.d.ts} +1 -1
  21. package/dist/runtime/composables/Checkout/{useShippingAddress.js → useCheckoutShippingAddress.js} +7 -2
  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 +118 -11
  39. package/dist/runtime/composables/Customer/useRegister.js +236 -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} +5 -18
  47. package/dist/runtime/composables/{useWishlists.js → Customer/useWishlists.js} +19 -28
  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/useSteps.d.ts +1 -1
  53. package/dist/runtime/composables/Product/useProductSlug.d.ts +8 -1
  54. package/dist/runtime/composables/Product/useQuickView.d.ts +8 -0
  55. package/dist/runtime/composables/Product/useQuickView.js +27 -0
  56. package/dist/runtime/composables/Product/useService.d.ts +1 -1
  57. package/dist/runtime/composables/Product/useService.js +0 -3
  58. package/dist/runtime/composables/SideBar/Filters/useFilters.d.ts +2 -2
  59. package/dist/runtime/composables/SideBar/Filters/useSorting.d.ts +2 -2
  60. package/dist/runtime/composables/index.d.ts +15 -12
  61. package/dist/runtime/composables/index.js +15 -12
  62. package/dist/runtime/composables/useAddresses.js +6 -6
  63. package/dist/runtime/composables/useCards.js +2 -2
  64. package/dist/runtime/composables/useLocation.d.ts +2 -12
  65. package/dist/runtime/composables/useQuotationCheckout.d.ts +78 -0
  66. package/dist/runtime/composables/useQuotationCheckout.js +138 -0
  67. package/dist/runtime/middleware/flowrix.d.ts +5 -4
  68. package/dist/runtime/middleware/flowrix.js +41 -21
  69. package/dist/runtime/plugin.d.ts +1 -1
  70. package/dist/runtime/server/api/albums.js +1 -1
  71. package/dist/runtime/server/api/auth/forgot.js +1 -1
  72. package/dist/runtime/server/api/auth/login.js +5 -6
  73. package/dist/runtime/server/api/auth/logout.js +1 -1
  74. package/dist/runtime/server/api/auth/register.js +1 -1
  75. package/dist/runtime/server/api/auth/session.get.js +1 -1
  76. package/dist/runtime/server/api/auth/user/reset-password.js +1 -1
  77. package/dist/runtime/server/api/auth/user/session.js +1 -1
  78. package/dist/runtime/server/api/auth/user/verify-token.js +1 -1
  79. package/dist/runtime/server/api/banners.js +2 -2
  80. package/dist/runtime/server/api/brand/{[slug].js → [...slug].js} +17 -17
  81. package/dist/runtime/server/api/brand/index.d.ts +2 -0
  82. package/dist/runtime/server/api/brand/index.js +23 -0
  83. package/dist/runtime/server/api/cache/[...slug].delete.d.ts +2 -0
  84. package/dist/runtime/server/api/cache/[...slug].delete.js +40 -0
  85. package/dist/runtime/server/api/cache/clean.get.d.ts +5 -0
  86. package/dist/runtime/server/api/cache/clean.get.js +16 -0
  87. package/dist/runtime/server/api/cart/[slug]/add.js +1 -1
  88. package/dist/runtime/server/api/cart/[slug]/update.js +1 -1
  89. package/dist/runtime/server/api/cart/related.d.ts +2 -0
  90. package/dist/runtime/server/api/cart/related.js +21 -0
  91. package/dist/runtime/server/api/cart/remove.js +1 -1
  92. package/dist/runtime/server/api/cart/service/[slug]/add.js +1 -1
  93. package/dist/runtime/server/api/catalog/categories.js +5 -4
  94. package/dist/runtime/server/api/catalog/categoriesall.d.ts +3 -0
  95. package/dist/runtime/server/api/catalog/categoriesall.js +44 -0
  96. package/dist/runtime/server/api/catalog/featured.js +5 -4
  97. package/dist/runtime/server/api/catalog/samples.js +5 -4
  98. package/dist/runtime/server/api/catalog/search.js +5 -4
  99. package/dist/runtime/server/api/category/[...slug].js +18 -14
  100. package/dist/runtime/server/api/checkout/applyCoupon.js +1 -1
  101. package/dist/runtime/server/api/checkout/configs.d.ts +1 -1
  102. package/dist/runtime/server/api/checkout/configs.js +10 -11
  103. package/dist/runtime/server/api/checkout/countries.js +1 -1
  104. package/dist/runtime/server/api/checkout/paymentmethod.js +7 -7
  105. package/dist/runtime/server/api/checkout/quotation/[slug].d.ts +2 -0
  106. package/dist/runtime/server/api/checkout/quotation/[slug].js +21 -0
  107. package/dist/runtime/server/api/checkout/quotation/guest/[slug].d.ts +2 -0
  108. package/dist/runtime/server/api/checkout/quotation/guest/[slug].js +37 -0
  109. package/dist/runtime/server/api/checkout/quotation/guest/customer.d.ts +2 -0
  110. package/dist/runtime/server/api/checkout/quotation/guest/customer.js +21 -0
  111. package/dist/runtime/server/api/checkout/quotation/submit/[slug].d.ts +2 -0
  112. package/dist/runtime/server/api/checkout/quotation/submit/[slug].js +23 -0
  113. package/dist/runtime/server/api/{blog/[slug].js → cmspost/[...slug].js} +7 -9
  114. package/dist/runtime/server/api/{blog/blog.js → cmspost/all.js} +2 -2
  115. package/dist/runtime/server/api/company/profile.d.ts +1 -1
  116. package/dist/runtime/server/api/company/profile.js +9 -9
  117. package/dist/runtime/server/api/contact-center/webforms/[id]/details.js +1 -1
  118. package/dist/runtime/server/api/contact-center/webforms/create.js +1 -1
  119. package/dist/runtime/server/api/countries.d.ts +2 -0
  120. package/dist/runtime/server/api/countries.js +35 -0
  121. package/dist/runtime/server/api/customer/address/add.js +1 -1
  122. package/dist/runtime/server/api/customer/address/delete.js +2 -2
  123. package/dist/runtime/server/api/customer/address/setshipping.js +1 -1
  124. package/dist/runtime/server/api/customer/address/update.js +1 -1
  125. package/dist/runtime/server/api/customer/cards/delete.js +2 -2
  126. package/dist/runtime/server/api/customer/cards/get.js +2 -2
  127. package/dist/runtime/server/api/customer/change-password.js +2 -2
  128. package/dist/runtime/server/api/customer/checkout.js +1 -1
  129. package/dist/runtime/server/api/customer/orders.js +2 -2
  130. package/dist/runtime/server/api/customer/profile/update.js +1 -1
  131. package/dist/runtime/server/api/customer/quotations.js +2 -2
  132. package/dist/runtime/server/api/customer/search.js +1 -1
  133. package/dist/runtime/server/api/customer/tax-invoice.js +1 -1
  134. package/dist/runtime/server/api/customer/wishlist/add.js +1 -1
  135. package/dist/runtime/server/api/customer/wishlist/createWishList.js +1 -1
  136. package/dist/runtime/server/api/customer/wishlist/deleteFromWishList.js +1 -1
  137. package/dist/runtime/server/api/customer/wishlist/deleteWishList.js +1 -1
  138. package/dist/runtime/server/api/customer/wishlist/get.js +2 -2
  139. package/dist/runtime/server/api/customer/wishlist/getWishListItems.js +1 -1
  140. package/dist/runtime/server/api/customer/wishlist/updateWishList.js +2 -2
  141. package/dist/runtime/server/api/featured.d.ts +2 -0
  142. package/dist/runtime/server/api/featured.js +16 -0
  143. package/dist/runtime/server/api/location.js +1 -1
  144. package/dist/runtime/server/api/nav/[id]/links.js +1 -1
  145. package/dist/runtime/server/api/page/{[slug].js → [...slug].js} +6 -8
  146. package/dist/runtime/server/api/product/[...slug].js +8 -5
  147. package/dist/runtime/server/api/quickview/[slug].d.ts +2 -0
  148. package/dist/runtime/server/api/quickview/[slug].js +16 -0
  149. package/dist/runtime/server/api/samples.d.ts +3 -0
  150. package/dist/runtime/server/api/samples.js +20 -0
  151. package/dist/runtime/server/api/search.d.ts +3 -0
  152. package/dist/runtime/server/api/search.js +15 -0
  153. package/dist/runtime/server/api/service/[slug].js +5 -4
  154. package/dist/runtime/server/api/service/availability.js +1 -1
  155. package/dist/runtime/server/api/service/getall.d.ts +3 -0
  156. package/dist/runtime/server/api/service/getall.js +52 -0
  157. package/dist/runtime/server/api/shop.d.ts +3 -0
  158. package/dist/runtime/server/api/shop.js +15 -0
  159. package/dist/runtime/server/api/subscribe.js +1 -1
  160. package/dist/runtime/server/api/v2/[...slug].js +3 -1
  161. package/dist/runtime/server/api/webform.d.ts +3 -0
  162. package/dist/runtime/server/api/webform.js +16 -0
  163. package/dist/runtime/stores/Cart.d.ts +12 -0
  164. package/dist/runtime/stores/Cart.js +50 -16
  165. package/dist/runtime/stores/Checkout.d.ts +9 -15
  166. package/dist/runtime/stores/Checkout.js +19 -5
  167. package/dist/runtime/stores/Search.d.ts +1 -1
  168. package/dist/runtime/stores/Services.js +2 -2
  169. package/dist/runtime/stores/auth.d.ts +8 -11
  170. package/dist/runtime/stores/auth.js +390 -8
  171. package/dist/runtime/stores/countries.d.ts +1 -3
  172. package/dist/runtime/stores/countries.js +4 -8
  173. package/dist/runtime/stores/product/slug.d.ts +1 -17
  174. package/dist/runtime/stores/wishlists.d.ts +105 -5
  175. package/dist/runtime/stores/wishlists.js +200 -9
  176. package/dist/runtime/utils/api.js +9 -13
  177. package/dist/runtime/utils/htmlCache.d.ts +5 -0
  178. package/dist/runtime/utils/htmlCache.js +60 -0
  179. package/dist/types.d.mts +6 -2
  180. package/package.json +32 -20
  181. package/dist/runtime/composables/useAuth.d.ts +0 -45
  182. package/dist/runtime/composables/useAuth.js +0 -180
  183. package/dist/runtime/composables/useCountries.d.ts +0 -12
  184. package/dist/runtime/composables/useCountries.js +0 -50
  185. package/dist/runtime/composables/useOrders.d.ts +0 -21
  186. package/dist/runtime/composables/useOrders.js +0 -82
  187. package/dist/runtime/composables/useQuotations.d.ts +0 -14
  188. package/dist/runtime/composables/useQuotations.js +0 -50
  189. /package/dist/runtime/server/api/brand/{[slug].d.ts → [...slug].d.ts} +0 -0
  190. /package/dist/runtime/server/api/{blog/[slug].d.ts → cmspost/[...slug].d.ts} +0 -0
  191. /package/dist/runtime/server/api/{blog/blog.d.ts → cmspost/all.d.ts} +0 -0
  192. /package/dist/runtime/server/api/page/{[slug].d.ts → [...slug].d.ts} +0 -0
@@ -1,8 +1,9 @@
1
- import { defineEventHandler, getRouterParam, getQuery, createError, readBody } from "h3";
1
+ import { defineEventHandler, getQuery, createError } from "h3";
2
2
  import { $fetch } from "ofetch";
3
3
  import { writeFile, mkdir, readFile } from "fs/promises";
4
4
  import { join } from "path";
5
- const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "brands");
5
+ import { useRuntimeConfig } from "#imports";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "brands");
6
7
  export const brandCache = /* @__PURE__ */ new Map();
7
8
  async function ensureCacheDir() {
8
9
  try {
@@ -12,38 +13,37 @@ 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._;
16
17
  const query = getQuery(event);
17
- const body = await readBody(event);
18
- const isclearcashe = query.clearcache || false;
19
- delete query.clearcache;
20
18
  if (!slug) {
21
19
  throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
22
20
  }
23
21
  if (!/^[a-zA-Z0-9-_]+$/.test(slug)) {
24
- throw createError({ statusCode: 400, statusMessage: "Invalid slug" });
25
22
  }
26
23
  const cacheKey = `${slug}-${JSON.stringify(query)}`;
27
24
  const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
28
25
  const filePath = join(CACHE_DIR, `${fileName}.json`);
29
- if (!isclearcashe) {
30
- try {
31
- const fileContent = await readFile(filePath, "utf-8");
32
- const brand = JSON.parse(fileContent);
33
- return brand;
34
- } catch (error) {
35
- }
26
+ try {
27
+ const fileContent = await readFile(filePath, "utf-8");
28
+ const brand = JSON.parse(fileContent);
29
+ return brand;
30
+ } catch (error) {
36
31
  }
37
32
  try {
33
+ const config = useRuntimeConfig();
34
+ const rawCookies = event.req.headers.cookie || "";
35
+ const apiConfig = {
36
+ ...config,
37
+ cookies: rawCookies
38
+ };
38
39
  const brand = await $fetch(`${process.env.FLOWRIX_API_BASE}brands/${slug}`, {
39
40
  query,
40
41
  method: "get",
41
42
  headers: {
42
- "x-api-key": process.env.FLOWRIX_API_KEY,
43
+ "x-public-key": process.env.FLOWRIX_API_KEY,
43
44
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
44
45
  "Origin": process.env.FLOWRIX_API_ORIGIN
45
- },
46
- body: JSON.stringify(body)
46
+ }
47
47
  });
48
48
  await ensureCacheDir();
49
49
  await writeFile(filePath, JSON.stringify(brand, null, 2), "utf-8");
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
+ export default _default;
@@ -0,0 +1,23 @@
1
+ import { defineEventHandler, getQuery, createError } from "h3";
2
+ import { $fetch } from "ofetch";
3
+ export default defineEventHandler(async (event) => {
4
+ const query = getQuery(event);
5
+ try {
6
+ const brand = await $fetch(`${process.env.FLOWRIX_API_BASE}brands`, {
7
+ query,
8
+ method: "get",
9
+ headers: {
10
+ "x-public-key": process.env.FLOWRIX_API_KEY,
11
+ "x-api-secret": process.env.FLOWRIX_API_SECRET,
12
+ "Origin": process.env.FLOWRIX_API_ORIGIN
13
+ }
14
+ });
15
+ return brand;
16
+ } catch (error) {
17
+ throw createError({
18
+ statusCode: 500,
19
+ statusMessage: `Failed to fetch brands`,
20
+ data: error.message
21
+ });
22
+ }
23
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<string[]>>;
2
+ export default _default;
@@ -0,0 +1,40 @@
1
+ import { defineEventHandler, getQuery, createError } from "h3";
2
+ import { join } from "path";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ const CACHE_DIR = join("/tmp", ".cache");
6
+ export default defineEventHandler(async (event) => {
7
+ const slug = event.context.params._;
8
+ try {
9
+ let deleteMatchingFiles = function(dir) {
10
+ const files = fs.readdirSync(dir);
11
+ for (const file of files) {
12
+ const filePath = path.join(dir, file);
13
+ const stat = fs.statSync(filePath);
14
+ if (stat.isDirectory()) {
15
+ deleteMatchingFiles(filePath);
16
+ } else if (file.startsWith(prefix)) {
17
+ fs.unlinkSync(filePath);
18
+ deletedFiles.push(filePath);
19
+ } else if (file.startsWith(`_${prefix}`)) {
20
+ fs.unlinkSync(filePath);
21
+ deletedFiles.push(filePath);
22
+ }
23
+ }
24
+ };
25
+ const query = getQuery(event);
26
+ const cacheKey = `${slug}-${JSON.stringify(query)}`;
27
+ const prefix = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
28
+ const deletedFiles = [];
29
+ if (fs.existsSync(CACHE_DIR)) {
30
+ deleteMatchingFiles(CACHE_DIR);
31
+ }
32
+ return deletedFiles;
33
+ } catch (error) {
34
+ throw createError({
35
+ statusCode: 500,
36
+ statusMessage: `Cache not clear for slug: ${slug}`,
37
+ data: error.message
38
+ });
39
+ }
40
+ });
@@ -0,0 +1,5 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
+ success: boolean;
3
+ message: string;
4
+ }>>;
5
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { defineEventHandler, createError } from "h3";
2
+ import { join } from "path";
3
+ import { rm } from "fs/promises";
4
+ const CACHE_DIR = join("/tmp", ".cache");
5
+ export default defineEventHandler(async (event) => {
6
+ try {
7
+ await rm(CACHE_DIR, { recursive: true, force: true });
8
+ return { success: true, message: "Cache deleted successfully" };
9
+ } catch (error) {
10
+ throw createError({
11
+ statusCode: 500,
12
+ statusMessage: `Cache not cleared`,
13
+ data: error.message
14
+ });
15
+ }
16
+ });
@@ -7,7 +7,7 @@ export default defineEventHandler(async (event) => {
7
7
  const productResponse = await $fetch(`${process.env.FLOWRIX_API_BASE}cart/${slug}/add`, {
8
8
  method: "POST",
9
9
  headers: {
10
- "x-api-key": process.env.FLOWRIX_API_KEY,
10
+ "x-public-key": process.env.FLOWRIX_API_KEY,
11
11
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
12
12
  "Origin": process.env.FLOWRIX_API_ORIGIN
13
13
  },
@@ -7,7 +7,7 @@ export default defineEventHandler(async (event) => {
7
7
  const productResponse = await $fetch(`${process.env.FLOWRIX_API_BASE}cart/${slug}/update`, {
8
8
  method: "POST",
9
9
  headers: {
10
- "x-api-key": process.env.FLOWRIX_API_KEY,
10
+ "x-public-key": process.env.FLOWRIX_API_KEY,
11
11
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
12
12
  "Origin": process.env.FLOWRIX_API_ORIGIN
13
13
  },
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { defineEventHandler, getRouterParam, setResponseStatus, readBody } from "h3";
2
+ import { $fetch } from "ofetch";
3
+ export default defineEventHandler(async (event) => {
4
+ const slug = getRouterParam(event, "slug");
5
+ const body = await readBody(event);
6
+ try {
7
+ const productResponse = await $fetch(`${process.env.FLOWRIX_API_BASE}cart/relatedproducts`, {
8
+ method: "POST",
9
+ headers: {
10
+ "x-public-key": process.env.FLOWRIX_API_KEY,
11
+ "x-api-secret": process.env.FLOWRIX_API_SECRET,
12
+ "Origin": process.env.FLOWRIX_API_ORIGIN
13
+ },
14
+ body
15
+ });
16
+ return productResponse;
17
+ } catch (error) {
18
+ setResponseStatus(event, 500);
19
+ return { success: false, error: error.message };
20
+ }
21
+ });
@@ -7,7 +7,7 @@ export default defineEventHandler(async (event) => {
7
7
  const productResponse = await $fetch(`${process.env.FLOWRIX_API_BASE}cart/remove`, {
8
8
  method: "POST",
9
9
  headers: {
10
- "x-api-key": process.env.FLOWRIX_API_KEY,
10
+ "x-public-key": process.env.FLOWRIX_API_KEY,
11
11
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
12
12
  "Origin": process.env.FLOWRIX_API_ORIGIN
13
13
  },
@@ -6,7 +6,7 @@ export default defineEventHandler(async (event) => {
6
6
  const services = await $fetch(`${process.env.FLOWRIX_API_BASE}cart/service/${slug}/add`, {
7
7
  method: "POST",
8
8
  headers: {
9
- "x-api-key": process.env.FLOWRIX_API_KEY,
9
+ "x-public-key": process.env.FLOWRIX_API_KEY,
10
10
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
11
11
  "Origin": process.env.FLOWRIX_API_ORIGIN
12
12
  },
@@ -1,8 +1,8 @@
1
- import { defineEventHandler, getQuery, createError } from "h3";
1
+ import { defineEventHandler, getQuery, createError, getCookie } from "h3";
2
2
  import { $fetch } from "ofetch";
3
3
  import { writeFile, mkdir, readFile } from "fs/promises";
4
4
  import { join } from "path";
5
- const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "catalog");
5
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
6
6
  export const catelogCache = /* @__PURE__ */ new Map();
7
7
  async function ensureCacheDir() {
8
8
  try {
@@ -13,8 +13,9 @@ async function ensureCacheDir() {
13
13
  }
14
14
  export default defineEventHandler(async (event) => {
15
15
  const query = getQuery(event);
16
+ const customerType = getCookie(event, "customertype") || "";
16
17
  const fileName = "categories";
17
- const filePath = join(CACHE_DIR, `${fileName}.json`);
18
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
18
19
  try {
19
20
  const fileContent = await readFile(filePath, "utf-8");
20
21
  const catelog = JSON.parse(fileContent);
@@ -25,7 +26,7 @@ export default defineEventHandler(async (event) => {
25
26
  const categories = await $fetch(`${process.env.FLOWRIX_API_BASE}categories`, {
26
27
  query,
27
28
  headers: {
28
- "x-api-key": process.env.FLOWRIX_API_KEY,
29
+ "x-public-key": process.env.FLOWRIX_API_KEY,
29
30
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
30
31
  "Origin": process.env.FLOWRIX_API_ORIGIN
31
32
  }
@@ -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,44 @@
1
+ import { defineEventHandler, getQuery, createError, getCookie } from "h3";
2
+ import { $fetch } from "ofetch";
3
+ import { writeFile, mkdir, readFile } from "fs/promises";
4
+ import { join } from "path";
5
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
6
+ export const catelogCache = /* @__PURE__ */ new Map();
7
+ async function ensureCacheDir() {
8
+ try {
9
+ await mkdir(CACHE_DIR, { recursive: true });
10
+ } catch (error) {
11
+ console.error("Error creating cache directory:", error);
12
+ }
13
+ }
14
+ export default defineEventHandler(async (event) => {
15
+ const query = getQuery(event);
16
+ const customerType = getCookie(event, "customertype") || "";
17
+ const fileName = "categoriesall";
18
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
19
+ try {
20
+ const fileContent = await readFile(filePath, "utf-8");
21
+ const catelog = JSON.parse(fileContent);
22
+ return catelog;
23
+ } catch (error) {
24
+ }
25
+ try {
26
+ const categories = await $fetch(`${process.env.FLOWRIX_API_BASE}categories/all`, {
27
+ query,
28
+ headers: {
29
+ "x-public-key": process.env.FLOWRIX_API_KEY,
30
+ "x-api-secret": process.env.FLOWRIX_API_SECRET,
31
+ "Origin": process.env.FLOWRIX_API_ORIGIN
32
+ }
33
+ });
34
+ await ensureCacheDir();
35
+ await writeFile(filePath, JSON.stringify(categories, null, 2), "utf-8");
36
+ return categories;
37
+ } catch (error) {
38
+ throw createError({
39
+ statusCode: 500,
40
+ statusMessage: `Failed to fetch catelog for slug: ${slug}`,
41
+ data: error.message
42
+ });
43
+ }
44
+ });
@@ -1,8 +1,8 @@
1
- import { defineEventHandler, createError } from "h3";
1
+ import { defineEventHandler, createError, getCookie } from "h3";
2
2
  import { $fetch } from "ofetch";
3
3
  import { writeFile, mkdir, readFile } from "fs/promises";
4
4
  import { join } from "path";
5
- const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "catalog");
5
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
6
6
  export const catelogCache = /* @__PURE__ */ new Map();
7
7
  async function ensureCacheDir() {
8
8
  try {
@@ -12,8 +12,9 @@ async function ensureCacheDir() {
12
12
  }
13
13
  }
14
14
  export default defineEventHandler(async (event) => {
15
+ const customerType = getCookie(event, "customertype") || "";
15
16
  const fileName = "featured";
16
- const filePath = join(CACHE_DIR, `${fileName}.json`);
17
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
17
18
  try {
18
19
  const fileContent = await readFile(filePath, "utf-8");
19
20
  const catelog = JSON.parse(fileContent);
@@ -23,7 +24,7 @@ export default defineEventHandler(async (event) => {
23
24
  try {
24
25
  const featured = await $fetch(`${process.env.FLOWRIX_API_BASE}products/featured`, {
25
26
  headers: {
26
- "x-api-key": process.env.FLOWRIX_API_KEY,
27
+ "x-public-key": process.env.FLOWRIX_API_KEY,
27
28
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
28
29
  "Origin": process.env.FLOWRIX_API_ORIGIN
29
30
  }
@@ -1,8 +1,8 @@
1
- import { defineEventHandler, getQuery, createError } from "h3";
1
+ import { defineEventHandler, getQuery, createError, getCookie } from "h3";
2
2
  import { $fetch } from "ofetch";
3
3
  import { writeFile, mkdir, readFile } from "fs/promises";
4
4
  import { join } from "path";
5
- const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "catalog");
5
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
6
6
  export const catelogCache = /* @__PURE__ */ new Map();
7
7
  async function ensureCacheDir() {
8
8
  try {
@@ -13,9 +13,10 @@ async function ensureCacheDir() {
13
13
  }
14
14
  export default defineEventHandler(async (event) => {
15
15
  const query = getQuery(event);
16
+ const customerType = getCookie(event, "customertype") || "";
16
17
  const cacheKey = `samples-${JSON.stringify(query)}`;
17
18
  const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
18
- const filePath = join(CACHE_DIR, `${fileName}.json`);
19
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
19
20
  try {
20
21
  const fileContent = await readFile(filePath, "utf-8");
21
22
  const catelog = JSON.parse(fileContent);
@@ -26,7 +27,7 @@ export default defineEventHandler(async (event) => {
26
27
  const samples = await $fetch(`${process.env.FLOWRIX_API_BASE}samples`, {
27
28
  query,
28
29
  headers: {
29
- "x-api-key": process.env.FLOWRIX_API_KEY,
30
+ "x-public-key": process.env.FLOWRIX_API_KEY,
30
31
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
31
32
  "Origin": process.env.FLOWRIX_API_ORIGIN
32
33
  }
@@ -1,8 +1,8 @@
1
- import { defineEventHandler, getQuery, createError } from "h3";
1
+ import { defineEventHandler, getQuery, createError, getCookie } from "h3";
2
2
  import { $fetch } from "ofetch";
3
3
  import { writeFile, mkdir, readFile } from "fs/promises";
4
4
  import { join } from "path";
5
- const CACHE_DIR = join(process.cwd(), ".nuxt", "cache", "nitro", "catalog");
5
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
6
6
  export const catelogCache = /* @__PURE__ */ new Map();
7
7
  async function ensureCacheDir() {
8
8
  try {
@@ -13,9 +13,10 @@ async function ensureCacheDir() {
13
13
  }
14
14
  export default defineEventHandler(async (event) => {
15
15
  const query = getQuery(event);
16
+ const customerType = getCookie(event, "customertype") || "";
16
17
  const cacheKey = `search-${JSON.stringify(query)}`;
17
18
  const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
18
- const filePath = join(CACHE_DIR, `${fileName}.json`);
19
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
19
20
  try {
20
21
  const fileContent = await readFile(filePath, "utf-8");
21
22
  const catelog = JSON.parse(fileContent);
@@ -26,7 +27,7 @@ export default defineEventHandler(async (event) => {
26
27
  const search = await $fetch(`${process.env.FLOWRIX_API_BASE}search`, {
27
28
  query,
28
29
  headers: {
29
- "x-api-key": process.env.FLOWRIX_API_KEY,
30
+ "x-public-key": process.env.FLOWRIX_API_KEY,
30
31
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
31
32
  "Origin": process.env.FLOWRIX_API_ORIGIN
32
33
  }
@@ -1,8 +1,9 @@
1
- import { defineEventHandler, getQuery, createError } from "h3";
2
- import { $fetch } from "ofetch";
1
+ import { defineEventHandler, getQuery, createError, 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", "categories");
4
+ import { flowrixApi } from "../../../middleware/flowrix.js";
5
+ import { useRuntimeConfig } from "#imports";
6
+ const CACHE_DIR = join("/tmp", ".cache", "nitro", "categories");
6
7
  export const categoryCache = /* @__PURE__ */ new Map();
7
8
  async function ensureCacheDir() {
8
9
  try {
@@ -13,7 +14,8 @@ 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
  if (!slug) {
18
20
  throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
19
21
  }
@@ -21,7 +23,7 @@ export default defineEventHandler(async (event) => {
21
23
  }
22
24
  const cacheKey = `${slug}-${JSON.stringify(query)}`;
23
25
  const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
24
- const filePath = join(CACHE_DIR, `${fileName}.json`);
26
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
25
27
  try {
26
28
  const fileContent = await readFile(filePath, "utf-8");
27
29
  const category = JSON.parse(fileContent);
@@ -29,15 +31,17 @@ export default defineEventHandler(async (event) => {
29
31
  } catch (error) {
30
32
  }
31
33
  try {
32
- const category = await $fetch(`${process.env.FLOWRIX_API_BASE}categories/${slug}`, {
33
- query,
34
- method: "get",
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
- });
34
+ const config = useRuntimeConfig();
35
+ const rawCookies = event.req.headers.cookie || "";
36
+ const apiConfig = {
37
+ ...config,
38
+ cookies: rawCookies
39
+ };
40
+ query = {
41
+ ...query,
42
+ "scope[withchildren]": "true"
43
+ };
44
+ const category = await flowrixApi.get(`categories/${slug}`, apiConfig, { query });
41
45
  await ensureCacheDir();
42
46
  await writeFile(filePath, JSON.stringify(category, null, 2), "utf-8");
43
47
  return category;
@@ -6,7 +6,7 @@ export default defineEventHandler(async (event) => {
6
6
  const productResponse = await $fetch(`${process.env.FLOWRIX_API_BASE}checkout/applyCoupon`, {
7
7
  method: "POST",
8
8
  headers: {
9
- "x-api-key": process.env.FLOWRIX_API_KEY,
9
+ "x-public-key": process.env.FLOWRIX_API_KEY,
10
10
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
11
11
  "Origin": process.env.FLOWRIX_API_ORIGIN
12
12
  },
@@ -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,18 +1,17 @@
1
1
  import { defineEventHandler, setResponseStatus, readBody } from "h3";
2
- import { $fetch } from "ofetch";
2
+ import { flowrixApi } from "../../../middleware/flowrix.js";
3
3
  export default defineEventHandler(async (event) => {
4
4
  const body = await readBody(event);
5
5
  try {
6
- const productResponse = await $fetch(`${process.env.FLOWRIX_API_BASE}checkout/configs`, {
7
- method: "POST",
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
- body
14
- });
15
- return productResponse;
6
+ const config = useRuntimeConfig();
7
+ const response = await flowrixApi.post(
8
+ "checkout/configs",
9
+ config,
10
+ {
11
+ body
12
+ }
13
+ );
14
+ return response;
16
15
  } catch (error) {
17
16
  setResponseStatus(event, 500);
18
17
  return { success: false, error: error.message };
@@ -4,7 +4,7 @@ export default defineEventHandler(async (event) => {
4
4
  try {
5
5
  const countriesResponse = await $fetch(`${process.env.FLOWRIX_API_BASE}countries`, {
6
6
  headers: {
7
- "x-api-key": process.env.FLOWRIX_API_KEY,
7
+ "x-public-key": process.env.FLOWRIX_API_KEY,
8
8
  "x-api-secret": process.env.FLOWRIX_API_SECRET,
9
9
  "Origin": process.env.FLOWRIX_API_ORIGIN
10
10
  }
@@ -3,18 +3,18 @@ import { $fetch } from "ofetch";
3
3
  export default defineEventHandler(async (event) => {
4
4
  const body = await readBody(event);
5
5
  try {
6
- const productResponse = await $fetch(`${process.env.FLOWRIX_API_BASE}checkout/paymentmethod`, {
6
+ const response = await $fetch(`${process.env.FLOWRIX_API_BASE}checkout/paymentmethod`, {
7
7
  method: "POST",
8
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
9
+ "x-public-key": process.env.FLOWRIX_API_KEY || "",
10
+ "x-api-secret": process.env.FLOWRIX_API_SECRET || "",
11
+ "Origin": process.env.FLOWRIX_API_ORIGIN || ""
12
12
  },
13
13
  body
14
14
  });
15
- return productResponse;
15
+ return response;
16
16
  } catch (error) {
17
- setResponseStatus(event, 500);
18
- return { success: false, error: error.message };
17
+ setResponseStatus(event, error.statusCode || 500);
18
+ return { success: false, error: error.message, data: error.data };
19
19
  }
20
20
  });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { defineEventHandler, setResponseStatus, getRouterParam, getCookie } from "h3";
2
+ import { $fetch } from "ofetch";
3
+ export default defineEventHandler(async (event) => {
4
+ const slug = getRouterParam(event, "slug");
5
+ const accessTok = getCookie(event, "authToken");
6
+ try {
7
+ const response = await $fetch(`${process.env.FLOWRIX_API_BASE}mystore/customer/quotations/${slug}`, {
8
+ method: "GET",
9
+ headers: {
10
+ "x-public-key": process.env.FLOWRIX_API_KEY || "",
11
+ "x-api-secret": process.env.FLOWRIX_API_SECRET || "",
12
+ "Origin": process.env.FLOWRIX_API_ORIGIN || "",
13
+ "Authorization": `Bearer ${accessTok || ""}`
14
+ }
15
+ });
16
+ return response;
17
+ } catch (error) {
18
+ setResponseStatus(event, error.statusCode || 500);
19
+ return { success: false, error: error.message, data: error.data };
20
+ }
21
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
+ export default _default;
@@ -0,0 +1,37 @@
1
+ import { defineEventHandler, setResponseStatus, getRouterParam, readBody, getMethod, getQuery } from "h3";
2
+ import { $fetch } from "ofetch";
3
+ export default defineEventHandler(async (event) => {
4
+ const slug = getRouterParam(event, "slug");
5
+ const method = getMethod(event);
6
+ const query = getQuery(event);
7
+ try {
8
+ if (method === "GET") {
9
+ const response = await $fetch(`${process.env.FLOWRIX_API_BASE}quotations/${slug}`, {
10
+ method: "GET",
11
+ headers: {
12
+ "x-public-key": process.env.FLOWRIX_API_KEY || "",
13
+ "x-api-secret": process.env.FLOWRIX_API_SECRET || "",
14
+ "Origin": process.env.FLOWRIX_API_ORIGIN || ""
15
+ },
16
+ query
17
+ });
18
+ return response;
19
+ } else if (method === "POST") {
20
+ const body = await readBody(event);
21
+ const response = await $fetch(`${process.env.FLOWRIX_API_BASE}quotations/${slug}`, {
22
+ method: "POST",
23
+ headers: {
24
+ "x-public-key": process.env.FLOWRIX_API_KEY || "",
25
+ "x-api-secret": process.env.FLOWRIX_API_SECRET || "",
26
+ "Origin": process.env.FLOWRIX_API_ORIGIN || ""
27
+ },
28
+ body,
29
+ query
30
+ });
31
+ return response;
32
+ }
33
+ } catch (error) {
34
+ setResponseStatus(event, error.statusCode || 500);
35
+ return { success: false, error: error.message, data: error.data };
36
+ }
37
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { defineEventHandler, setResponseStatus, readBody, getMethod } from "h3";
2
+ import { $fetch } from "ofetch";
3
+ export default defineEventHandler(async (event) => {
4
+ const method = getMethod(event);
5
+ const body = method === "POST" ? await readBody(event) : void 0;
6
+ try {
7
+ const response = await $fetch(`${process.env.FLOWRIX_API_BASE}checkout/quotation/customer`, {
8
+ method,
9
+ headers: {
10
+ "x-public-key": process.env.FLOWRIX_API_KEY,
11
+ "x-api-secret": process.env.FLOWRIX_API_SECRET,
12
+ "Origin": process.env.FLOWRIX_API_ORIGIN
13
+ },
14
+ body
15
+ });
16
+ return response;
17
+ } catch (error) {
18
+ setResponseStatus(event, 500);
19
+ return { success: false, error: error.message };
20
+ }
21
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
+ export default _default;