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
package/dist/module.json
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
1
|
-
import { defineEventHandler,
|
|
2
|
-
import {
|
|
1
|
+
import { defineEventHandler, createError } 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", "extra");
|
|
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
|
+
}
|
|
3
15
|
export default defineEventHandler(async (event) => {
|
|
16
|
+
const fileName = "albums";
|
|
17
|
+
const filePath = join(CACHE_DIR, `${fileName}.json`);
|
|
4
18
|
try {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
20
|
+
const catelog = JSON.parse(fileContent);
|
|
21
|
+
return catelog;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const config = useRuntimeConfig();
|
|
26
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
27
|
+
const apiConfig = {
|
|
28
|
+
...config,
|
|
29
|
+
cookies: rawCookies
|
|
30
|
+
};
|
|
31
|
+
const albums = await flowrixApi.get(`albums`, apiConfig);
|
|
32
|
+
if (config.public.FLOWRIX_CACHE == true) {
|
|
33
|
+
await ensureCacheDir();
|
|
34
|
+
await writeFile(filePath, JSON.stringify(albums, null, 2), "utf-8");
|
|
35
|
+
}
|
|
13
36
|
return albums;
|
|
14
37
|
} catch (error) {
|
|
15
|
-
|
|
16
|
-
|
|
38
|
+
throw createError({
|
|
39
|
+
statusCode: 500,
|
|
40
|
+
statusMessage: `Failed to fetch albums`,
|
|
41
|
+
data: error.message
|
|
42
|
+
});
|
|
17
43
|
}
|
|
18
44
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineEventHandler, createError } 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", "extra");
|
|
6
7
|
export const catelogCache = /* @__PURE__ */ new Map();
|
|
7
8
|
async function ensureCacheDir() {
|
|
@@ -21,14 +22,14 @@ export default defineEventHandler(async (event) => {
|
|
|
21
22
|
} catch (error) {
|
|
22
23
|
}
|
|
23
24
|
try {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
25
|
+
const config = useRuntimeConfig();
|
|
26
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
27
|
+
const apiConfig = {
|
|
28
|
+
...config,
|
|
29
|
+
cookies: rawCookies
|
|
30
|
+
};
|
|
31
|
+
const banners = await flowrixApi.get(`banners`, apiConfig);
|
|
32
|
+
if (config.public.FLOWRIX_CACHE == true) {
|
|
32
33
|
await ensureCacheDir();
|
|
33
34
|
await writeFile(filePath, JSON.stringify(banners, null, 2), "utf-8");
|
|
34
35
|
}
|
|
@@ -36,7 +37,7 @@ export default defineEventHandler(async (event) => {
|
|
|
36
37
|
} catch (error) {
|
|
37
38
|
throw createError({
|
|
38
39
|
statusCode: 500,
|
|
39
|
-
statusMessage: `Failed to fetch
|
|
40
|
+
statusMessage: `Failed to fetch banners`,
|
|
40
41
|
data: error.message
|
|
41
42
|
});
|
|
42
43
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError } from "h3";
|
|
2
|
-
import { $fetch } from "ofetch";
|
|
3
2
|
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
4
3
|
import { join } from "path";
|
|
4
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
5
5
|
import { useRuntimeConfig } from "#imports";
|
|
6
6
|
const CACHE_DIR = join("/tmp", ".cache", "nitro", "brands");
|
|
7
7
|
export const brandCache = /* @__PURE__ */ new Map();
|
|
@@ -14,7 +14,7 @@ async function ensureCacheDir() {
|
|
|
14
14
|
}
|
|
15
15
|
export default defineEventHandler(async (event) => {
|
|
16
16
|
const slug = event.context.params._;
|
|
17
|
-
|
|
17
|
+
let query = getQuery(event);
|
|
18
18
|
if (!slug) {
|
|
19
19
|
throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
|
|
20
20
|
}
|
|
@@ -36,16 +36,11 @@ export default defineEventHandler(async (event) => {
|
|
|
36
36
|
...config,
|
|
37
37
|
cookies: rawCookies
|
|
38
38
|
};
|
|
39
|
-
|
|
40
|
-
query
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"x-api-secret": process.env.FLOWRIX_API_SECRET,
|
|
45
|
-
"Origin": process.env.FLOWRIX_API_ORIGIN
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
if (process.env.FLOWRIX_CACHE == true) {
|
|
39
|
+
query = {
|
|
40
|
+
...query
|
|
41
|
+
};
|
|
42
|
+
const brand = await flowrixApi.get(`brands/${slug}`, apiConfig, { query });
|
|
43
|
+
if (config.public.FLOWRIX_CACHE == true) {
|
|
49
44
|
await ensureCacheDir();
|
|
50
45
|
await writeFile(filePath, JSON.stringify(brand, null, 2), "utf-8");
|
|
51
46
|
}
|
|
@@ -1,22 +1,48 @@
|
|
|
1
|
-
import { defineEventHandler, getQuery, createError } from "h3";
|
|
2
|
-
import {
|
|
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
|
+
}
|
|
3
15
|
export default defineEventHandler(async (event) => {
|
|
4
|
-
|
|
16
|
+
let query = getQuery(event);
|
|
17
|
+
const customerType = getCookie(event, "customertype") || "";
|
|
18
|
+
const fileName = "brands";
|
|
19
|
+
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
5
20
|
try {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
22
|
+
const catelog = JSON.parse(fileContent);
|
|
23
|
+
return catelog;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const config = useRuntimeConfig();
|
|
28
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
29
|
+
const apiConfig = {
|
|
30
|
+
...config,
|
|
31
|
+
cookies: rawCookies
|
|
32
|
+
};
|
|
33
|
+
query = {
|
|
34
|
+
...query
|
|
35
|
+
};
|
|
36
|
+
const brands = await flowrixApi.get(`brands`, apiConfig, { query });
|
|
37
|
+
if (config.public.FLOWRIX_CACHE == true) {
|
|
38
|
+
await ensureCacheDir();
|
|
39
|
+
await writeFile(filePath, JSON.stringify(brands, null, 2), "utf-8");
|
|
40
|
+
}
|
|
41
|
+
return brands;
|
|
16
42
|
} catch (error) {
|
|
17
43
|
throw createError({
|
|
18
44
|
statusCode: 500,
|
|
19
|
-
statusMessage: `Failed to fetch
|
|
45
|
+
statusMessage: `Failed to fetch Brands`,
|
|
20
46
|
data: error.message
|
|
21
47
|
});
|
|
22
48
|
}
|
|
@@ -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,19 +1,19 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#imports";
|
|
1
2
|
import { defineEventHandler, getRouterParam, setResponseStatus, readBody } from "h3";
|
|
2
|
-
import {
|
|
3
|
+
import { flowrixApi } from "../../../../middleware/flowrix.js";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
const slug = getRouterParam(event, "slug");
|
|
5
6
|
const body = await readBody(event);
|
|
6
7
|
try {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return productResponse;
|
|
8
|
+
const config = useRuntimeConfig();
|
|
9
|
+
const response = await flowrixApi.post(
|
|
10
|
+
`cart/${slug}/add`,
|
|
11
|
+
config,
|
|
12
|
+
{
|
|
13
|
+
body
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
return response;
|
|
17
17
|
} catch (error) {
|
|
18
18
|
setResponseStatus(event, 500);
|
|
19
19
|
return { success: false, error: error.message };
|
|
@@ -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,19 +1,19 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam, setResponseStatus, 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
7
|
try {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return productResponse;
|
|
8
|
+
const config = useRuntimeConfig();
|
|
9
|
+
const response = await flowrixApi.post(
|
|
10
|
+
`cart/${slug}/update`,
|
|
11
|
+
config,
|
|
12
|
+
{
|
|
13
|
+
body
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
return response;
|
|
17
17
|
} catch (error) {
|
|
18
18
|
setResponseStatus(event, 500);
|
|
19
19
|
return { success: false, error: error.message };
|
|
@@ -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,16 @@
|
|
|
1
|
-
import { defineEventHandler } from "h3";
|
|
2
|
-
import {
|
|
1
|
+
import { defineEventHandler, getRouterParam, readBody } from "h3";
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
return services;
|
|
7
|
+
const config = useRuntimeConfig();
|
|
8
|
+
const response = await flowrixApi.post(
|
|
9
|
+
`cart/service/${slug}/add`,
|
|
10
|
+
config,
|
|
11
|
+
{
|
|
12
|
+
body
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
return response;
|
|
16
16
|
});
|
|
@@ -0,0 +1,49 @@
|
|
|
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 fileName = "brands";
|
|
19
|
+
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
20
|
+
try {
|
|
21
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
22
|
+
const catelog = JSON.parse(fileContent);
|
|
23
|
+
return catelog;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const config = useRuntimeConfig();
|
|
28
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
29
|
+
const apiConfig = {
|
|
30
|
+
...config,
|
|
31
|
+
cookies: rawCookies
|
|
32
|
+
};
|
|
33
|
+
query = {
|
|
34
|
+
...query
|
|
35
|
+
};
|
|
36
|
+
const brands = await flowrixApi.get(`brands`, apiConfig, { query });
|
|
37
|
+
if (config.public.FLOWRIX_CACHE == true) {
|
|
38
|
+
await ensureCacheDir();
|
|
39
|
+
await writeFile(filePath, JSON.stringify(brands, null, 2), "utf-8");
|
|
40
|
+
}
|
|
41
|
+
return brands;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw createError({
|
|
44
|
+
statusCode: 500,
|
|
45
|
+
statusMessage: `Failed to fetch Brands`,
|
|
46
|
+
data: error.message
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError, 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", "catalog");
|
|
7
7
|
export const catelogCache = /* @__PURE__ */ new Map();
|
|
8
8
|
async function ensureCacheDir() {
|
|
@@ -13,7 +13,7 @@ async function ensureCacheDir() {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export default defineEventHandler(async (event) => {
|
|
16
|
-
|
|
16
|
+
let query = getQuery(event);
|
|
17
17
|
const customerType = getCookie(event, "customertype") || "";
|
|
18
18
|
const fileName = "categories";
|
|
19
19
|
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
@@ -25,15 +25,16 @@ export default defineEventHandler(async (event) => {
|
|
|
25
25
|
}
|
|
26
26
|
try {
|
|
27
27
|
const config = useRuntimeConfig();
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
28
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
29
|
+
const apiConfig = {
|
|
30
|
+
...config,
|
|
31
|
+
cookies: rawCookies
|
|
32
|
+
};
|
|
33
|
+
query = {
|
|
34
|
+
...query
|
|
35
|
+
};
|
|
36
|
+
const categories = await flowrixApi.get(`categories`, apiConfig, { query });
|
|
37
|
+
if (config.public.FLOWRIX_CACHE == true) {
|
|
37
38
|
await ensureCacheDir();
|
|
38
39
|
await writeFile(filePath, JSON.stringify(categories, null, 2), "utf-8");
|
|
39
40
|
}
|
|
@@ -41,7 +42,7 @@ export default defineEventHandler(async (event) => {
|
|
|
41
42
|
} catch (error) {
|
|
42
43
|
throw createError({
|
|
43
44
|
statusCode: 500,
|
|
44
|
-
statusMessage: `Failed to fetch
|
|
45
|
+
statusMessage: `Failed to fetch categories`,
|
|
45
46
|
data: error.message
|
|
46
47
|
});
|
|
47
48
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError, 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", "catalog");
|
|
6
7
|
export const catelogCache = /* @__PURE__ */ new Map();
|
|
7
8
|
async function ensureCacheDir() {
|
|
@@ -12,7 +13,7 @@ async function ensureCacheDir() {
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
export default defineEventHandler(async (event) => {
|
|
15
|
-
|
|
16
|
+
let query = getQuery(event);
|
|
16
17
|
const customerType = getCookie(event, "customertype") || "";
|
|
17
18
|
const fileName = "categoriesall";
|
|
18
19
|
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
@@ -23,15 +24,17 @@ export default defineEventHandler(async (event) => {
|
|
|
23
24
|
} catch (error) {
|
|
24
25
|
}
|
|
25
26
|
try {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
const config = useRuntimeConfig();
|
|
28
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
29
|
+
const apiConfig = {
|
|
30
|
+
...config,
|
|
31
|
+
cookies: rawCookies
|
|
32
|
+
};
|
|
33
|
+
query = {
|
|
34
|
+
...query
|
|
35
|
+
};
|
|
36
|
+
const categories = await flowrixApi.get(`categories/all`, apiConfig, { query });
|
|
37
|
+
if (config.public.FLOWRIX_CACHE == true) {
|
|
35
38
|
await ensureCacheDir();
|
|
36
39
|
await writeFile(filePath, JSON.stringify(categories, null, 2), "utf-8");
|
|
37
40
|
}
|
|
@@ -39,7 +42,7 @@ export default defineEventHandler(async (event) => {
|
|
|
39
42
|
} catch (error) {
|
|
40
43
|
throw createError({
|
|
41
44
|
statusCode: 500,
|
|
42
|
-
statusMessage: `Failed to fetch
|
|
45
|
+
statusMessage: `Failed to fetch categories`,
|
|
43
46
|
data: error.message
|
|
44
47
|
});
|
|
45
48
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { defineEventHandler, createError, getCookie } 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";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
5
6
|
const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
|
|
6
7
|
export const catelogCache = /* @__PURE__ */ new Map();
|
|
7
8
|
async function ensureCacheDir() {
|
|
@@ -12,6 +13,7 @@ async function ensureCacheDir() {
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
export default defineEventHandler(async (event) => {
|
|
16
|
+
let query = getQuery(event);
|
|
15
17
|
const customerType = getCookie(event, "customertype") || "";
|
|
16
18
|
const fileName = "featured";
|
|
17
19
|
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
@@ -22,14 +24,17 @@ export default defineEventHandler(async (event) => {
|
|
|
22
24
|
} catch (error) {
|
|
23
25
|
}
|
|
24
26
|
try {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const config = useRuntimeConfig();
|
|
28
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
29
|
+
const apiConfig = {
|
|
30
|
+
...config,
|
|
31
|
+
cookies: rawCookies
|
|
32
|
+
};
|
|
33
|
+
query = {
|
|
34
|
+
...query
|
|
35
|
+
};
|
|
36
|
+
const featured = await flowrixApi.get(`products/featured`, apiConfig, { query });
|
|
37
|
+
if (config.public.FLOWRIX_CACHE == true) {
|
|
33
38
|
await ensureCacheDir();
|
|
34
39
|
await writeFile(filePath, JSON.stringify(featured, null, 2), "utf-8");
|
|
35
40
|
}
|
|
@@ -37,7 +42,7 @@ export default defineEventHandler(async (event) => {
|
|
|
37
42
|
} catch (error) {
|
|
38
43
|
throw createError({
|
|
39
44
|
statusCode: 500,
|
|
40
|
-
statusMessage: `Failed to fetch catelog for
|
|
45
|
+
statusMessage: `Failed to fetch catelog for featured`,
|
|
41
46
|
data: error.message
|
|
42
47
|
});
|
|
43
48
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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 fileName = "posts";
|
|
19
|
+
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
20
|
+
try {
|
|
21
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
22
|
+
const catelog = JSON.parse(fileContent);
|
|
23
|
+
return catelog;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const config = useRuntimeConfig();
|
|
28
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
29
|
+
const apiConfig = {
|
|
30
|
+
...config,
|
|
31
|
+
cookies: rawCookies
|
|
32
|
+
};
|
|
33
|
+
query = {
|
|
34
|
+
...query
|
|
35
|
+
};
|
|
36
|
+
const posts = await flowrixApi.post(`posts`, apiConfig, { query });
|
|
37
|
+
if (config.public.FLOWRIX_CACHE == true) {
|
|
38
|
+
await ensureCacheDir();
|
|
39
|
+
await writeFile(filePath, JSON.stringify(posts, null, 2), "utf-8");
|
|
40
|
+
}
|
|
41
|
+
return posts;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw createError({
|
|
44
|
+
statusCode: 500,
|
|
45
|
+
statusMessage: `Failed to fetch Brands`,
|
|
46
|
+
data: error.message
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|