flowrix 1.0.1-beta.7 → 1.0.1-beta.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "flowrix",
3
3
  "configKey": "flowrix",
4
- "version": "1.0.1-beta.7",
4
+ "version": "1.0.1-beta.9",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { defineNuxtModule, createResolver, installModule, addImportsDir, addPlugin, addImports, addServerHandler } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, installModule, addServerHandler, addPlugin, addImportsDir, addImports } from '@nuxt/kit';
2
2
 
3
3
  const module = defineNuxtModule({
4
4
  meta: {
@@ -27,6 +27,14 @@ const module = defineNuxtModule({
27
27
  };
28
28
  const resolver = createResolver(import.meta.url);
29
29
  await installModule("@pinia/nuxt");
30
+ addServerHandler({
31
+ middleware: true,
32
+ handler: resolver.resolve("./runtime/utils/htmlCache")
33
+ });
34
+ addPlugin({
35
+ src: resolver.resolve("./runtime/plugins/fullReload.client"),
36
+ mode: "client"
37
+ });
30
38
  addImportsDir(resolver.resolve("./runtime/stores"));
31
39
  addImportsDir(resolver.resolve("./runtime/composables"));
32
40
  addPlugin({
@@ -1,5 +1,5 @@
1
1
  export default function (): {
2
- NavMenu: import("pinia").Store<"NavMenu", import("../../stores/index.js").NavMenuState, {}, {
2
+ NavMenu: import("pinia").Store<"NavMenu", import("#imports").NavMenuState, {}, {
3
3
  navMenu(id: number, location?: string): Promise<void>;
4
4
  }>;
5
5
  companyProfile: import("vue").ComputedRef<null>;
@@ -1,6 +1,6 @@
1
1
  import { ref } from "vue";
2
2
  import { useRoute } from "#imports";
3
- import { useCartStore } from "../stores/cart";
3
+ import { useCartStore } from "../stores/Cart.js";
4
4
  export const useAddToCart = () => {
5
5
  const showError = ref(false);
6
6
  const ErrorMessage = ref("");
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import { useRouter } from "vue-router";
2
+ export default defineNuxtPlugin(() => {
3
+ const router = useRouter();
4
+ router.beforeEach((to, from) => {
5
+ if (to.fullPath !== from.fullPath) {
6
+ window.location.href = to.fullPath;
7
+ return false;
8
+ }
9
+ });
10
+ });
@@ -0,0 +1,5 @@
1
+ export declare function readCache(pathname: string): Promise<string | null>;
2
+ export declare function writeCache(pathname: string, html: string): Promise<void>;
3
+ export declare function clearCache(): Promise<void>;
4
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<string | undefined>>;
5
+ export default _default;
@@ -0,0 +1,54 @@
1
+ import { promises as fs } from "fs";
2
+ import { join } from "path";
3
+ import { getRequestURL } from "h3";
4
+ import { defineEventHandler } from "h3";
5
+ const cacheDir = join(process.cwd(), ".nuxt", "cache", "html");
6
+ async function ensureDir() {
7
+ await fs.mkdir(cacheDir, { recursive: true });
8
+ }
9
+ function getCacheFilePath(pathname) {
10
+ const safeName = pathname.replace(/[\/\\:?<>|"]/g, "_") || "index";
11
+ return join(cacheDir, `${safeName}.html`);
12
+ }
13
+ export async function readCache(pathname) {
14
+ try {
15
+ const filePath = getCacheFilePath(pathname);
16
+ const html = await fs.readFile(filePath, "utf8");
17
+ return html;
18
+ } catch {
19
+ return null;
20
+ }
21
+ }
22
+ export async function writeCache(pathname, html) {
23
+ await ensureDir();
24
+ const filePath = getCacheFilePath(pathname);
25
+ await fs.writeFile(filePath, html, "utf8");
26
+ }
27
+ export async function clearCache() {
28
+ try {
29
+ await fs.rm(cacheDir, { recursive: true, force: true });
30
+ await ensureDir();
31
+ } catch {
32
+ }
33
+ }
34
+ export default defineEventHandler(async (event) => {
35
+ const url = getRequestURL(event);
36
+ const pathname = url.pathname;
37
+ if (event.method !== "GET" || !event.headers.get("accept")?.includes("text/html")) return;
38
+ const cached = await readCache(pathname);
39
+ if (cached) {
40
+ event.node.res.setHeader("x-cache", "HIT");
41
+ return cached;
42
+ }
43
+ const originalEnd = event.node.res.end;
44
+ let chunks = [];
45
+ event.node.res.end = function(chunk) {
46
+ if (chunk) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
47
+ const html = Buffer.concat(chunks).toString("utf-8");
48
+ if (event.node.res.statusCode === 200 && html.includes("<!DOCTYPE html>")) {
49
+ writeCache(pathname, html);
50
+ }
51
+ return originalEnd.apply(this, arguments);
52
+ };
53
+ return;
54
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowrix",
3
- "version": "1.0.1-beta.7",
3
+ "version": "1.0.1-beta.9",
4
4
  "description": "lug-and-play Nuxt eCommerce cart powered by FLOWRiX. Subscription required.",
5
5
  "license": "MIT",
6
6
  "type": "module",