@dyrected/nuxt 2.0.1 → 2.3.1

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.d.mts CHANGED
@@ -13,6 +13,8 @@ interface ModuleOptions extends DyrectedConfig {
13
13
  siteId?: string;
14
14
  /** Optional manual path to the dyrected config file (absolute or relative to root). */
15
15
  configPath?: string;
16
+ /** Base URL for the Dyrected API. Defaults to the host + apiBase. */
17
+ baseUrl?: string;
16
18
  }
17
19
 
18
20
  declare const module: NuxtModule<ModuleOptions>;
package/dist/module.d.ts CHANGED
@@ -13,6 +13,8 @@ interface ModuleOptions extends DyrectedConfig {
13
13
  siteId?: string;
14
14
  /** Optional manual path to the dyrected config file (absolute or relative to root). */
15
15
  configPath?: string;
16
+ /** Base URL for the Dyrected API. Defaults to the host + apiBase. */
17
+ baseUrl?: string;
16
18
  }
17
19
 
18
20
  declare const module: NuxtModule<ModuleOptions>;
package/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@dyrected/nuxt",
3
3
  "configKey": "dyrected",
4
- "version": "2.0.0"
4
+ "version": "2.3.1"
5
5
  }
package/dist/module.mjs CHANGED
@@ -65,17 +65,46 @@ const module = defineNuxtModule({
65
65
  });
66
66
  }
67
67
  nuxt.options.runtimeConfig.dyrected = runtimeConfig;
68
+ const apiBase = options.apiBase || "/dyrected";
69
+ let baseUrl = process.env.NUXT_PUBLIC_DYRECTED_URL || options.baseUrl || apiBase;
70
+ if (baseUrl.startsWith("http") && apiBase.startsWith("/") && !baseUrl.endsWith(apiBase)) {
71
+ baseUrl = baseUrl.replace(/\/$/, "") + apiBase;
72
+ }
68
73
  nuxt.options.runtimeConfig.public.dyrected = {
69
- baseUrl: process.env.NUXT_PUBLIC_DYRECTED_URL || options.apiBase,
70
- apiKey: process.env.NUXT_PUBLIC_DYRECTED_API_KEY || options.apiKey,
71
- siteId: options.siteId
74
+ baseUrl,
75
+ apiKey: process.env.NUXT_PUBLIC_DYRECTED_API_KEY || options.apiKey || "local-dev",
76
+ siteId: process.env.NUXT_PUBLIC_DYRECTED_SITE_ID || options.siteId || "default"
72
77
  };
73
- nuxt.options.build.transpile.push("@dyrected/admin");
74
- nuxt.options.vite.optimizeDeps = nuxt.options.vite.optimizeDeps || {};
75
- nuxt.options.vite.optimizeDeps.include = nuxt.options.vite.optimizeDeps.include || [];
76
- if (!nuxt.options.vite.optimizeDeps.include.includes("@dyrected/admin")) {
77
- nuxt.options.vite.optimizeDeps.include.push("@dyrected/admin");
78
+ if (nuxt.options.vite) {
79
+ nuxt.options.vite = nuxt.options.vite || {};
80
+ nuxt.options.vite.optimizeDeps = nuxt.options.vite.optimizeDeps || {};
81
+ nuxt.options.vite.optimizeDeps.exclude = nuxt.options.vite.optimizeDeps.exclude || [];
82
+ if (!nuxt.options.vite.optimizeDeps.exclude.includes("@dyrected/admin")) {
83
+ nuxt.options.vite.optimizeDeps.exclude.push("@dyrected/admin");
84
+ }
78
85
  }
86
+ nuxt.hook("vite:extendConfig", (config) => {
87
+ const plugins = config.plugins ?? [];
88
+ const unctxPlugin = plugins.find((p) => p && typeof p === "object" && p.name === "unctx:transform");
89
+ if (!unctxPlugin)
90
+ return;
91
+ const isAdminFile = (id) => id.includes("@dyrected/admin") || id.includes("/packages/admin/dist/");
92
+ if (typeof unctxPlugin.transform === "function") {
93
+ const original = unctxPlugin.transform;
94
+ unctxPlugin.transform = function(code, id, ...rest) {
95
+ if (isAdminFile(id))
96
+ return null;
97
+ return original.call(this, code, id, ...rest);
98
+ };
99
+ } else if (unctxPlugin.transform && typeof unctxPlugin.transform.handler === "function") {
100
+ const originalHandler = unctxPlugin.transform.handler;
101
+ unctxPlugin.transform.handler = function(code, id, ...rest) {
102
+ if (isAdminFile(id))
103
+ return null;
104
+ return originalHandler.call(this, code, id, ...rest);
105
+ };
106
+ }
107
+ });
79
108
  }
80
109
  });
81
110
 
@@ -5,7 +5,10 @@ let app;
5
5
  export default defineEventHandler(async (event) => {
6
6
  const config = useRuntimeConfig().dyrected;
7
7
  if (!app) {
8
- const dyrectedConfig = { ...config };
8
+ let dyrectedConfig = { ...config };
9
+ if (globalThis.__dyrected_config) {
10
+ dyrectedConfig = { ...dyrectedConfig, ...globalThis.__dyrected_config };
11
+ }
9
12
  if (!dyrectedConfig.db || typeof dyrectedConfig.db.find !== "function") {
10
13
  dyrectedConfig.db = globalThis.__dyrected_db;
11
14
  }
@@ -7,13 +7,16 @@ export default defineNitroPlugin(async (nitroApp) => {
7
7
  const configPath = runtimeConfig.configPath;
8
8
  const { pathToFileURL } = await import("url");
9
9
  const { default: userConfig } = await import(pathToFileURL(configPath).href);
10
- if (userConfig && userConfig.db) {
11
- globalThis.__dyrected_db = userConfig.db;
12
- console.log("[dyrected/nuxt] Database re-attached to global context");
13
- }
14
- if (userConfig && userConfig.storage) {
15
- globalThis.__dyrected_storage = userConfig.storage;
16
- console.log("[dyrected/nuxt] Storage adapter re-attached to global context");
10
+ if (userConfig) {
11
+ globalThis.__dyrected_config = userConfig;
12
+ if (userConfig.db) {
13
+ globalThis.__dyrected_db = userConfig.db;
14
+ console.log("[dyrected/nuxt] Database re-attached to global context");
15
+ }
16
+ if (userConfig.storage) {
17
+ globalThis.__dyrected_storage = userConfig.storage;
18
+ console.log("[dyrected/nuxt] Storage adapter re-attached to global context");
19
+ }
17
20
  }
18
21
  } catch (err) {
19
22
  console.error("[dyrected/nuxt] Failed to re-attach database:", err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyrected/nuxt",
3
- "version": "2.0.1",
3
+ "version": "2.3.1",
4
4
  "type": "module",
5
5
  "main": "./dist/module.mjs",
6
6
  "types": "./dist/module.d.ts",
@@ -10,9 +10,9 @@
10
10
  "dependencies": {
11
11
  "@nuxt/kit": "^3.11.2",
12
12
  "h3": "^1.15.0",
13
- "@dyrected/admin": "2.0.1",
14
- "@dyrected/core": "2.1.0",
15
- "@dyrected/sdk": "2.0.0"
13
+ "@dyrected/admin": "2.4.0",
14
+ "@dyrected/core": "2.4.0",
15
+ "@dyrected/sdk": "2.4.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "nuxt": "^3.0.0",