flowrix 1.0.1-beta.89 → 1.0.1-beta.91

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 (67) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/server/api/albums.d.ts +1 -0
  3. package/dist/runtime/server/api/albums.js +38 -12
  4. package/dist/runtime/server/api/banners.js +11 -10
  5. package/dist/runtime/server/api/brand/[...slug].js +7 -12
  6. package/dist/runtime/server/api/brand/index.d.ts +1 -0
  7. package/dist/runtime/server/api/brand/index.js +40 -14
  8. package/dist/runtime/server/api/cart/[slug]/add.d.ts +1 -1
  9. package/dist/runtime/server/api/cart/[slug]/add.js +11 -11
  10. package/dist/runtime/server/api/cart/[slug]/update.d.ts +1 -1
  11. package/dist/runtime/server/api/cart/[slug]/update.js +11 -11
  12. package/dist/runtime/server/api/cart/service/[slug]/add.d.ts +1 -1
  13. package/dist/runtime/server/api/cart/service/[slug]/add.js +12 -12
  14. package/dist/runtime/server/api/catalog/brands.d.ts +3 -0
  15. package/dist/runtime/server/api/catalog/brands.js +49 -0
  16. package/dist/runtime/server/api/catalog/categories.js +13 -12
  17. package/dist/runtime/server/api/catalog/categoriesall.js +15 -12
  18. package/dist/runtime/server/api/catalog/featured.js +16 -11
  19. package/dist/runtime/server/api/catalog/posts.d.ts +3 -0
  20. package/dist/runtime/server/api/catalog/posts.js +49 -0
  21. package/dist/runtime/server/api/catalog/samples.js +15 -12
  22. package/dist/runtime/server/api/catalog/search.js +14 -11
  23. package/dist/runtime/server/api/category/[...slug].js +1 -1
  24. package/dist/runtime/server/api/checkout/applyCoupon.d.ts +1 -1
  25. package/dist/runtime/server/api/checkout/applyCoupon.js +13 -13
  26. package/dist/runtime/server/api/checkout/configs.js +2 -1
  27. package/dist/runtime/server/api/checkout/countries.d.ts +1 -1
  28. package/dist/runtime/server/api/checkout/countries.js +5 -9
  29. package/dist/runtime/server/api/checkout/paymentmethod.d.ts +1 -1
  30. package/dist/runtime/server/api/checkout/paymentmethod.js +17 -12
  31. package/dist/runtime/server/api/cmspost/[...slug].js +9 -10
  32. package/dist/runtime/server/api/cmspost/all.d.ts +1 -1
  33. package/dist/runtime/server/api/cmspost/all.js +47 -15
  34. package/dist/runtime/server/api/contact-center/webforms/[id]/details.d.ts +1 -1
  35. package/dist/runtime/server/api/contact-center/webforms/[id]/details.js +48 -15
  36. package/dist/runtime/server/api/contact-center/webforms/create.d.ts +1 -1
  37. package/dist/runtime/server/api/contact-center/webforms/create.js +10 -10
  38. package/dist/runtime/server/api/countries.js +7 -2
  39. package/dist/runtime/server/api/featured.d.ts +2 -1
  40. package/dist/runtime/server/api/featured.js +44 -11
  41. package/dist/runtime/server/api/location.d.ts +1 -1
  42. package/dist/runtime/server/api/location.js +20 -12
  43. package/dist/runtime/server/api/nav/[id]/links.d.ts +1 -0
  44. package/dist/runtime/server/api/nav/[id]/links.js +48 -14
  45. package/dist/runtime/server/api/page/[...slug].js +8 -9
  46. package/dist/runtime/server/api/product/[...slug].js +12 -3
  47. package/dist/runtime/server/api/quickview/[slug].d.ts +1 -1
  48. package/dist/runtime/server/api/quickview/[slug].js +11 -10
  49. package/dist/runtime/server/api/reviews.d.ts +1 -1
  50. package/dist/runtime/server/api/reviews.js +9 -9
  51. package/dist/runtime/server/api/samples.d.ts +1 -1
  52. package/dist/runtime/server/api/samples.js +46 -16
  53. package/dist/runtime/server/api/search.d.ts +1 -1
  54. package/dist/runtime/server/api/search.js +48 -13
  55. package/dist/runtime/server/api/service/[slug].js +10 -9
  56. package/dist/runtime/server/api/service/availability.d.ts +1 -1
  57. package/dist/runtime/server/api/service/availability.js +11 -13
  58. package/dist/runtime/server/api/service/getall.js +11 -10
  59. package/dist/runtime/server/api/shop.d.ts +1 -1
  60. package/dist/runtime/server/api/shop.js +48 -13
  61. package/dist/runtime/server/api/subscribe.d.ts +1 -1
  62. package/dist/runtime/server/api/subscribe.js +19 -14
  63. package/dist/runtime/server/api/v2/[...slug].get.js +6 -2
  64. package/dist/runtime/server/api/webform.d.ts +1 -1
  65. package/dist/runtime/server/api/webform.js +50 -14
  66. package/dist/runtime/utils/htmlCache.js +1 -1
  67. package/package.json +1 -4
@@ -1,16 +1,52 @@
1
- import { defineEventHandler, getRouterParam } from "h3";
2
- import { $fetch } from "ofetch";
3
- export const Page = /* @__PURE__ */ new Map();
1
+ import { defineEventHandler, getRouterParam, 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", "webfroms");
7
+ export const webfromCache = /* @__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
+ }
4
15
  export default defineEventHandler(async (event) => {
5
- const slug = getRouterParam(event, "slug");
6
- const query = getQuery(event);
7
- const page = await $fetch(`${process.env.FLOWRIX_API_BASE}contact-center/webforms/${query.id}/details`, {
8
- headers: {
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
- },
13
- query
14
- });
15
- return page;
16
+ const slug = getRouterParam(event, "id");
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
+ const cacheKey = `${slug}-${JSON.stringify(query)}`;
24
+ const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
25
+ const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
26
+ try {
27
+ const fileContent = await readFile(filePath, "utf-8");
28
+ const webfrom = JSON.parse(fileContent);
29
+ return webfrom;
30
+ } catch (error) {
31
+ }
32
+ try {
33
+ const config = useRuntimeConfig();
34
+ const rawCookies = event.req.headers.cookie || "";
35
+ const apiConfig = {
36
+ ...config,
37
+ cookies: rawCookies
38
+ };
39
+ const webfrom = await flowrixApi.get(`contact-center/webforms/${slug}/details`, apiConfig, {});
40
+ if (config.public.FLOWRIX_CACHE == true) {
41
+ await ensureCacheDir();
42
+ await writeFile(filePath, JSON.stringify(webfrom, null, 2), "utf-8");
43
+ }
44
+ return webfrom;
45
+ } catch (error) {
46
+ throw createError({
47
+ statusCode: 500,
48
+ statusMessage: `Failed to fetch webfrom for id: ${slug}`,
49
+ data: error.message
50
+ });
51
+ }
16
52
  });
@@ -54,7 +54,7 @@ export default defineEventHandler(async (event) => {
54
54
  if (chunk) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
55
55
  const html = Buffer.concat(chunks).toString("utf-8");
56
56
  if (event.node.res.statusCode === 200 && html.includes("<!DOCTYPE html>")) {
57
- if (process.env.FLOWRIX_CACHE == true) {
57
+ if (config.public.FLOWRIX_CACHE == true) {
58
58
  writeCache(url, html, customerType);
59
59
  }
60
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowrix",
3
- "version": "1.0.1-beta.89",
3
+ "version": "1.0.1-beta.91",
4
4
  "description": "Plug-and-play Nuxt eCommerce cart powered by FLOWRiX. Subscription required.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -40,13 +40,10 @@
40
40
  "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
41
41
  },
42
42
  "dependencies": {
43
- "@nuxt/image": "1.11.0",
44
43
  "@nuxt/kit": "4.2.0",
45
- "@nuxtjs/seo": "3.2.2",
46
44
  "@pinia/nuxt": "0.7.0",
47
45
  "@stripe/stripe-js": "8.2.0",
48
46
  "@vueuse/nuxt": "14.0.0",
49
- "nuxt-gtag": "4.1.0",
50
47
  "nuxt-swiper": "2.0.1",
51
48
  "nuxt-toast": "1.4.0",
52
49
  "pinia": "2.3.1",