flowrix 1.0.1-beta.2 → 1.0.1-beta.21

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.2",
4
+ "version": "1.0.1-beta.21",
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, addImportsDir, addPlugin, addImports } from '@nuxt/kit';
2
2
 
3
3
  const module = defineNuxtModule({
4
4
  meta: {
@@ -7,28 +7,35 @@ const module = defineNuxtModule({
7
7
  },
8
8
  defaults: {},
9
9
  async setup(_options, nuxt) {
10
- nuxt.options.runtimeConfig = {
11
- ...nuxt.options.runtimeConfig,
12
- // Server-only key
13
- FLOWRIX_API_KEY: nuxt.options.runtimeConfig.FLOWRIX_API_KEY || process.env.FLOWRIX_API_KEY || "",
14
- FLOWRIX_API_SECRET: nuxt.options.runtimeConfig.FLOWRIX_API_SECRET || process.env.FLOWRIX_API_SECRET || "",
15
- FLOWRIX_API_ORIGIN: nuxt.options.runtimeConfig.FLOWRIX_API_ORIGIN || process.env.FLOWRIX_API_ORIGIN || "",
16
- FLOWRIX_API_BASE: nuxt.options.runtimeConfig.FLOWRIX_API_BASE || process.env.FLOWRIX_API_BASE || "",
17
- FLOWRIX_API_BASE_V2: nuxt.options.runtimeConfig.FLOWRIX_API_BASE_V2 || process.env.FLOWRIX_API_BASE_V2 || "",
18
- public: {
19
- ...nuxt.options.runtimeConfig.public,
20
- // Client-exposed key
21
- FLOWRIX_API_KEY: nuxt.options.runtimeConfig.public?.FLOWRIX_API_KEY || process.env.FLOWRIX_API_KEY || "",
22
- FLOWRIX_API_SECRET: nuxt.options.runtimeConfig.public?.FLOWRIX_API_SECRET || process.env.FLOWRIX_API_SECRET || "",
23
- FLOWRIX_API_ORIGIN: nuxt.options.runtimeConfig.public?.FLOWRIX_API_ORIGIN || process.env.FLOWRIX_API_ORIGIN || "",
24
- FLOWRIX_API_BASE: nuxt.options.runtimeConfig.public?.FLOWRIX_API_BASE || process.env.FLOWRIX_API_BASE || "",
25
- FLOWRIX_API_BASE_V2: nuxt.options.runtimeConfig.public?.FLOWRIX_API_BASE_V2 || process.env.FLOWRIX_API_BASE_V2 || ""
26
- }
27
- };
10
+ const env = process.env;
11
+ const runtimeConfig = nuxt.options.runtimeConfig;
12
+ if (!runtimeConfig.public) {
13
+ runtimeConfig.public = {};
14
+ }
15
+ runtimeConfig.FLOWRIX_API_KEY ||= env.FLOWRIX_API_KEY || "";
16
+ runtimeConfig.FLOWRIX_API_SECRET ||= env.FLOWRIX_API_SECRET || "";
17
+ runtimeConfig.FLOWRIX_API_ORIGIN ||= env.FLOWRIX_API_ORIGIN || "";
18
+ runtimeConfig.FLOWRIX_API_BASE ||= env.FLOWRIX_API_BASE || "";
19
+ runtimeConfig.FLOWRIX_API_BASE_V2 ||= env.FLOWRIX_API_BASE_V2 || "";
20
+ Object.assign(runtimeConfig.public, {
21
+ FLOWRIX_API_KEY: runtimeConfig.public.FLOWRIX_API_KEY || env.FLOWRIX_API_KEY || "",
22
+ FLOWRIX_API_SECRET: runtimeConfig.public.FLOWRIX_API_SECRET || env.FLOWRIX_API_SECRET || "",
23
+ FLOWRIX_API_ORIGIN: runtimeConfig.public.FLOWRIX_API_ORIGIN || env.FLOWRIX_API_ORIGIN || "",
24
+ FLOWRIX_API_BASE: runtimeConfig.public.FLOWRIX_API_BASE || env.FLOWRIX_API_BASE || "",
25
+ FLOWRIX_API_BASE_V2: runtimeConfig.public.FLOWRIX_API_BASE_V2 || env.FLOWRIX_API_BASE_V2 || ""
26
+ });
27
+ console.info("\u2705 Flowrix runtime config loaded:", {
28
+ apiKey: runtimeConfig.public.FLOWRIX_API_KEY,
29
+ apiBase: runtimeConfig.public.FLOWRIX_API_BASE
30
+ });
28
31
  const resolver = createResolver(import.meta.url);
29
32
  await installModule("@pinia/nuxt");
30
- addImportsDir(resolver.resolve("./runtime/composables"));
33
+ addServerHandler({
34
+ middleware: true,
35
+ handler: resolver.resolve("./runtime/utils/htmlCache")
36
+ });
31
37
  addImportsDir(resolver.resolve("./runtime/stores"));
38
+ addImportsDir(resolver.resolve("./runtime/composables"));
32
39
  addPlugin({
33
40
  src: resolver.resolve("./runtime/plugin"),
34
41
  mode: "all"
@@ -265,6 +272,14 @@ const module = defineNuxtModule({
265
272
  route: "/api/v2/**",
266
273
  handler: resolver.resolve("./runtime/server/api/v2/[...slug]")
267
274
  });
275
+ addServerHandler({
276
+ route: "/api/cache/clean",
277
+ handler: resolver.resolve("./runtime/server/api/cache/clean.get")
278
+ });
279
+ addServerHandler({
280
+ route: "/api/cache/**",
281
+ handler: resolver.resolve("./runtime/server/api/cache/[...slug].delete")
282
+ });
268
283
  }
269
284
  });
270
285
 
@@ -1,6 +1,6 @@
1
1
  export default function (): {
2
- router: any;
3
- route: any;
2
+ router: import("vue-router").Router;
3
+ route: import("vue-router").RouteLocationNormalizedLoadedGeneric;
4
4
  form_error: import("vue").Ref<string, string>;
5
5
  inputData: import("vue").Ref<{
6
6
  passwordStrengthValue: number;
@@ -1,4 +1,6 @@
1
1
  import { ref } from "vue";
2
+ import { useRouter, useRoute } from "#vue-router";
3
+ import { useAuth } from "../useAuth.js";
2
4
  export default function() {
3
5
  const router = useRouter();
4
6
  const route = useRoute();
@@ -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("");
@@ -1,6 +1,6 @@
1
1
  import { ref, computed, watch, onMounted } from "vue";
2
2
  import { useRoute } from "#imports";
3
- import { useSearchStore } from "../stores/search";
3
+ import { useSearchStore } from "../stores/Search.js";
4
4
  export function useSearch() {
5
5
  const route = useRoute();
6
6
  const searchStore = useSearchStore();
@@ -1,6 +1,6 @@
1
1
  export declare const flowrixApi: {
2
- get: (endpoint: any, options?: {}, apiversion?: string) => Promise<unknown>;
3
- post: (endpoint: any, options?: {}, apiversion?: string) => Promise<unknown>;
4
- put: (endpoint: any, options?: {}, apiversion?: string) => Promise<unknown>;
5
- delete: (endpoint: any, options?: {}, apiversion?: string) => Promise<unknown>;
2
+ get: (endpoint: string, options?: {}, apiversion?: string) => Promise<unknown>;
3
+ post: (endpoint: string, options?: {}, apiversion?: string) => Promise<unknown>;
4
+ put: (endpoint: string, options?: {}, apiversion?: string) => Promise<unknown>;
5
+ delete: (endpoint: string, options?: {}, apiversion?: string) => Promise<unknown>;
6
6
  };
@@ -1,23 +1,35 @@
1
+ let getRuntimeConfig = null;
2
+ try {
3
+ const nuxtApp = require("#app");
4
+ if (nuxtApp?.useRuntimeConfig) {
5
+ getRuntimeConfig = nuxtApp.useRuntimeConfig;
6
+ }
7
+ } catch (_) {
8
+ }
1
9
  const isServer = typeof process !== "undefined" && process.server;
2
10
  function getEnv(key) {
3
- if (typeof useRuntimeConfig === "function") {
4
- const config = useRuntimeConfig();
11
+ if (getRuntimeConfig) {
12
+ const config = getRuntimeConfig();
5
13
  return config.public?.[key] || config[key];
6
14
  }
7
15
  return process.env[key];
8
16
  }
9
- async function request(method, endpoint, options = {}, apiversion) {
17
+ async function request(method, endpoint, options = {}, apiversion = "v1") {
18
+ if (getRuntimeConfig) {
19
+ const config = getRuntimeConfig();
20
+ console.log(config);
21
+ }
10
22
  const FLOWRIX_API_KEY = getEnv("FLOWRIX_API_KEY");
11
23
  const FLOWRIX_API_SECRET = getEnv("FLOWRIX_API_SECRET");
12
24
  const FLOWRIX_API_ORIGIN = getEnv("FLOWRIX_API_ORIGIN");
13
25
  let FLOWRIX_API_BASE = getEnv("FLOWRIX_API_BASE");
14
- if (apiversion == "v2") {
26
+ if (apiversion === "v2") {
15
27
  FLOWRIX_API_BASE = getEnv("FLOWRIX_API_BASE_V2");
16
28
  }
17
29
  const headers = {
18
30
  "x-api-key": FLOWRIX_API_KEY,
19
31
  "x-api-secret": FLOWRIX_API_SECRET,
20
- "Origin": FLOWRIX_API_ORIGIN,
32
+ Origin: FLOWRIX_API_ORIGIN,
21
33
  ...options.headers
22
34
  };
23
35
  try {
@@ -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(process.cwd(), ".nuxt", "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(process.cwd(), ".nuxt", "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
+ });
@@ -31,7 +31,6 @@ export const useCartStore = defineStore("cart", {
31
31
  return { attribute_id, fraction };
32
32
  },
33
33
  async addToCart(product, qty, data, productId = "", service = []) {
34
- const { post } = useApi();
35
34
  const checkoutSession = useCheckoutStore().checkoutSession;
36
35
  let formData = {
37
36
  cart: void 0,
@@ -65,9 +64,8 @@ export const useCartStore = defineStore("cart", {
65
64
  apiUrl = `cart/service/${service.slug}/add`;
66
65
  }
67
66
  try {
68
- const response = await flowrixApi.post(apiUrl, {
69
- body: formData
70
- });
67
+ console.log(apiUrl);
68
+ const response = await flowrixApi.post(apiUrl, { body: formData });
71
69
  if (response?.status == "Success") {
72
70
  this.addedResponse = "success";
73
71
  this.cart = {
@@ -0,0 +1,5 @@
1
+ export declare const useSearchStore: import("pinia").StoreDefinition<"SearchStore", {
2
+ data: any[];
3
+ }, {}, {
4
+ fetchSearchData(query: string): Promise<any[]>;
5
+ }>;
@@ -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(/[^a-zA-Z0-9-_]/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.2",
3
+ "version": "1.0.1-beta.21",
4
4
  "description": "lug-and-play Nuxt eCommerce cart powered by FLOWRiX. Subscription required.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,7 +19,8 @@
19
19
  }
20
20
  },
21
21
  "files": [
22
- "dist"
22
+ "dist",
23
+ "runtime/stores"
23
24
  ],
24
25
  "scripts": {
25
26
  "prepack": "nuxt-module-build build",
@@ -33,24 +34,24 @@
33
34
  "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
34
35
  },
35
36
  "dependencies": {
36
- "@nuxt/kit": "^4.1.3",
37
- "@pinia/nuxt": "^0.7.0",
38
- "@stripe/stripe-js": "^8.2.0",
39
- "pinia": "^2.1.7",
40
- "pinia-plugin-persistedstate": "^3.2.0"
37
+ "@nuxt/kit": "4.2.0",
38
+ "@pinia/nuxt": "0.7.0",
39
+ "@stripe/stripe-js": "8.2.0",
40
+ "pinia": "2.3.1",
41
+ "pinia-plugin-persistedstate": "3.2.3"
41
42
  },
42
43
  "devDependencies": {
43
- "@nuxt/devtools": "^2.6.5",
44
- "@nuxt/eslint-config": "^1.9.0",
45
- "@nuxt/module-builder": "^1.0.2",
46
- "@nuxt/schema": "^4.1.3",
47
- "@nuxt/test-utils": "^3.19.2",
48
- "@types/node": "latest",
49
- "changelogen": "^0.6.2",
50
- "eslint": "^9.38.0",
51
- "nuxt": "^4.1.3",
52
- "typescript": "~5.9.3",
53
- "vitest": "^3.2.4",
54
- "vue-tsc": "^3.1.1"
44
+ "@nuxt/devtools": "2.6.5",
45
+ "@nuxt/eslint-config": "1.9.0",
46
+ "@nuxt/module-builder": "1.0.2",
47
+ "@nuxt/schema": "4.2.0",
48
+ "@nuxt/test-utils": "3.19.2",
49
+ "@types/node": "24.9.1",
50
+ "changelogen": "0.6.2",
51
+ "eslint": "9.38.0",
52
+ "nuxt": "4.2.0",
53
+ "typescript": "5.9.3",
54
+ "vitest": "3.2.4",
55
+ "vue-tsc": "3.1.1"
55
56
  }
56
57
  }