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.
- package/dist/module.json +1 -1
- package/dist/runtime/server/api/albums.d.ts +1 -0
- package/dist/runtime/server/api/albums.js +38 -12
- package/dist/runtime/server/api/banners.js +11 -10
- package/dist/runtime/server/api/brand/[...slug].js +7 -12
- package/dist/runtime/server/api/brand/index.d.ts +1 -0
- package/dist/runtime/server/api/brand/index.js +40 -14
- package/dist/runtime/server/api/cart/[slug]/add.d.ts +1 -1
- package/dist/runtime/server/api/cart/[slug]/add.js +11 -11
- package/dist/runtime/server/api/cart/[slug]/update.d.ts +1 -1
- package/dist/runtime/server/api/cart/[slug]/update.js +11 -11
- package/dist/runtime/server/api/cart/service/[slug]/add.d.ts +1 -1
- package/dist/runtime/server/api/cart/service/[slug]/add.js +12 -12
- package/dist/runtime/server/api/catalog/brands.d.ts +3 -0
- package/dist/runtime/server/api/catalog/brands.js +49 -0
- package/dist/runtime/server/api/catalog/categories.js +13 -12
- package/dist/runtime/server/api/catalog/categoriesall.js +15 -12
- package/dist/runtime/server/api/catalog/featured.js +16 -11
- package/dist/runtime/server/api/catalog/posts.d.ts +3 -0
- package/dist/runtime/server/api/catalog/posts.js +49 -0
- package/dist/runtime/server/api/catalog/samples.js +15 -12
- package/dist/runtime/server/api/catalog/search.js +14 -11
- package/dist/runtime/server/api/category/[...slug].js +1 -1
- package/dist/runtime/server/api/checkout/applyCoupon.d.ts +1 -1
- package/dist/runtime/server/api/checkout/applyCoupon.js +13 -13
- package/dist/runtime/server/api/checkout/configs.js +2 -1
- package/dist/runtime/server/api/checkout/countries.d.ts +1 -1
- package/dist/runtime/server/api/checkout/countries.js +5 -9
- package/dist/runtime/server/api/checkout/paymentmethod.d.ts +1 -1
- package/dist/runtime/server/api/checkout/paymentmethod.js +17 -12
- package/dist/runtime/server/api/cmspost/[...slug].js +9 -10
- package/dist/runtime/server/api/cmspost/all.d.ts +1 -1
- package/dist/runtime/server/api/cmspost/all.js +47 -15
- package/dist/runtime/server/api/contact-center/webforms/[id]/details.d.ts +1 -1
- package/dist/runtime/server/api/contact-center/webforms/[id]/details.js +48 -15
- package/dist/runtime/server/api/contact-center/webforms/create.d.ts +1 -1
- package/dist/runtime/server/api/contact-center/webforms/create.js +10 -10
- package/dist/runtime/server/api/countries.js +7 -2
- package/dist/runtime/server/api/featured.d.ts +2 -1
- package/dist/runtime/server/api/featured.js +44 -11
- package/dist/runtime/server/api/location.d.ts +1 -1
- package/dist/runtime/server/api/location.js +20 -12
- package/dist/runtime/server/api/nav/[id]/links.d.ts +1 -0
- package/dist/runtime/server/api/nav/[id]/links.js +48 -14
- package/dist/runtime/server/api/page/[...slug].js +8 -9
- package/dist/runtime/server/api/product/[...slug].js +12 -3
- package/dist/runtime/server/api/quickview/[slug].d.ts +1 -1
- package/dist/runtime/server/api/quickview/[slug].js +11 -10
- package/dist/runtime/server/api/reviews.d.ts +1 -1
- package/dist/runtime/server/api/reviews.js +9 -9
- package/dist/runtime/server/api/samples.d.ts +1 -1
- package/dist/runtime/server/api/samples.js +46 -16
- package/dist/runtime/server/api/search.d.ts +1 -1
- package/dist/runtime/server/api/search.js +48 -13
- package/dist/runtime/server/api/service/[slug].js +10 -9
- package/dist/runtime/server/api/service/availability.d.ts +1 -1
- package/dist/runtime/server/api/service/availability.js +11 -13
- package/dist/runtime/server/api/service/getall.js +11 -10
- package/dist/runtime/server/api/shop.d.ts +1 -1
- package/dist/runtime/server/api/shop.js +48 -13
- package/dist/runtime/server/api/subscribe.d.ts +1 -1
- package/dist/runtime/server/api/subscribe.js +19 -14
- package/dist/runtime/server/api/v2/[...slug].get.js +6 -2
- package/dist/runtime/server/api/webform.d.ts +1 -1
- package/dist/runtime/server/api/webform.js +50 -14
- package/dist/runtime/utils/htmlCache.js +1 -1
- package/package.json +1 -4
|
@@ -1,19 +1,53 @@
|
|
|
1
|
-
import { defineEventHandler,
|
|
2
|
-
import {
|
|
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
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
});
|
|
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
|
-
|
|
17
|
-
|
|
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,8 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError, readBody, getCookie } from "h3";
|
|
2
|
-
import { $fetch } from "ofetch";
|
|
3
2
|
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
4
3
|
import { join } from "path";
|
|
5
4
|
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
6
6
|
const CACHE_DIR = join("/tmp", ".cache", "nitro", "pages");
|
|
7
7
|
export const pageCache = /* @__PURE__ */ new Map();
|
|
8
8
|
async function ensureCacheDir() {
|
|
@@ -31,14 +31,13 @@ export default defineEventHandler(async (event) => {
|
|
|
31
31
|
}
|
|
32
32
|
try {
|
|
33
33
|
const config = useRuntimeConfig();
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (process.env.FLOWRIX_CACHE == true) {
|
|
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) {
|
|
42
41
|
await ensureCacheDir();
|
|
43
42
|
await writeFile(filePath, JSON.stringify(page, null, 2), "utf-8");
|
|
44
43
|
}
|
|
@@ -15,7 +15,7 @@ async function ensureCacheDir() {
|
|
|
15
15
|
export default defineEventHandler(async (event) => {
|
|
16
16
|
const slug = event.context.params._;
|
|
17
17
|
const customerType = getCookie(event, "customertype") || "";
|
|
18
|
-
|
|
18
|
+
let query = getQuery(event);
|
|
19
19
|
const body = await readBody(event);
|
|
20
20
|
if (!slug) {
|
|
21
21
|
throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
|
|
@@ -31,8 +31,17 @@ export default defineEventHandler(async (event) => {
|
|
|
31
31
|
}
|
|
32
32
|
try {
|
|
33
33
|
const config = useRuntimeConfig();
|
|
34
|
-
const
|
|
35
|
-
|
|
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
|
|
36
45
|
});
|
|
37
46
|
if (config.public.FLOWRIX_CACHE == true) {
|
|
38
47
|
await ensureCacheDir();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam, readBody } from "h3";
|
|
2
|
-
import {
|
|
2
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
const slug = getRouterParam(event, "slug");
|
|
5
6
|
const body = await readBody(event);
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
body
|
|
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)
|
|
14
15
|
});
|
|
15
|
-
return
|
|
16
|
+
return quickview;
|
|
16
17
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { defineEventHandler, setResponseStatus } from "h3";
|
|
2
|
-
import {
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import { flowrixApi } from "../../middleware/flowrix.js";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
try {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
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
13
|
return reviews;
|
|
14
14
|
} catch (error) {
|
|
15
15
|
setResponseStatus(event, 500);
|
|
@@ -1,20 +1,50 @@
|
|
|
1
|
-
import { defineEventHandler, getQuery } from "h3";
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
+
}
|
|
4
15
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
|
|
16
|
+
let query = getQuery(event);
|
|
17
|
+
const customerType = getCookie(event, "customertype") || "";
|
|
6
18
|
const cacheKey = `samples-${JSON.stringify(query)}`;
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
});
|
|
9
49
|
}
|
|
10
|
-
const samples = await $fetch(`${process.env.FLOWRIX_API_BASE}samples`, {
|
|
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
|
-
params: query
|
|
17
|
-
});
|
|
18
|
-
SamplesCache.set(cacheKey, samples);
|
|
19
|
-
return samples;
|
|
20
50
|
});
|
|
@@ -1,15 +1,50 @@
|
|
|
1
|
-
import { defineEventHandler, getQuery } from "h3";
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
+
}
|
|
4
15
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
}
|
|
15
50
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam, getQuery, createError, readBody, getCookie } from "h3";
|
|
2
|
-
import { $fetch } from "ofetch";
|
|
3
2
|
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
4
3
|
import { join } from "path";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
5
6
|
const CACHE_DIR = join("/tmp", ".cache", "nitro", "services");
|
|
6
7
|
export const serviceCache = /* @__PURE__ */ new Map();
|
|
7
8
|
async function ensureCacheDir() {
|
|
@@ -32,14 +33,14 @@ export default defineEventHandler(async (event) => {
|
|
|
32
33
|
} catch (error) {
|
|
33
34
|
}
|
|
34
35
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
if (
|
|
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) {
|
|
43
44
|
await ensureCacheDir();
|
|
44
45
|
await writeFile(filePath, JSON.stringify(service, null, 2), "utf-8");
|
|
45
46
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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:
|
|
20
|
+
statusCode: 422,
|
|
23
21
|
message: "Internal server error",
|
|
24
22
|
error: error.message || "Unknown error"
|
|
25
23
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError, readBody, getCookie } from "h3";
|
|
2
|
-
import { $fetch } from "ofetch";
|
|
3
2
|
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
4
3
|
import { join } from "path";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
5
6
|
const CACHE_DIR = join("/tmp", ".cache", "nitro", "services");
|
|
6
7
|
export const serviceCache = /* @__PURE__ */ new Map();
|
|
7
8
|
async function ensureCacheDir() {
|
|
@@ -14,7 +15,7 @@ async function ensureCacheDir() {
|
|
|
14
15
|
export default defineEventHandler(async (event) => {
|
|
15
16
|
const slug = "all";
|
|
16
17
|
const customerType = getCookie(event, "customertype") || "";
|
|
17
|
-
|
|
18
|
+
let query = getQuery(event);
|
|
18
19
|
const body = await readBody(event);
|
|
19
20
|
if (!slug) {
|
|
20
21
|
throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
|
|
@@ -32,14 +33,14 @@ export default defineEventHandler(async (event) => {
|
|
|
32
33
|
} catch (error) {
|
|
33
34
|
}
|
|
34
35
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
if (
|
|
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) {
|
|
43
44
|
await ensureCacheDir();
|
|
44
45
|
await writeFile(filePath, JSON.stringify(service, null, 2), "utf-8");
|
|
45
46
|
}
|
|
@@ -1,15 +1,50 @@
|
|
|
1
|
-
import { defineEventHandler, getQuery } from "h3";
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
+
}
|
|
4
15
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
}
|
|
15
50
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
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 {
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
headers
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
});
|
|
@@ -4,8 +4,12 @@ import { useRuntimeConfig } from "#imports";
|
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const slug = event.context.params._;
|
|
6
6
|
const config = useRuntimeConfig();
|
|
7
|
-
|
|
8
|
-
const
|
|
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);
|
|
9
13
|
if (page.status === "Success" && page.data.type === "Redirect") {
|
|
10
14
|
}
|
|
11
15
|
return page;
|