@dyrected/nuxt 2.0.0 → 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 +2 -0
- package/dist/module.d.ts +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +38 -3
- package/dist/runtime/server/handler.mjs +4 -1
- package/dist/runtime/server/plugins/db.mjs +12 -8
- package/package.json +8 -4
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
package/dist/module.mjs
CHANGED
|
@@ -65,11 +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
|
|
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
|
};
|
|
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
|
+
}
|
|
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
|
+
});
|
|
73
108
|
}
|
|
74
109
|
});
|
|
75
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
|
-
|
|
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
|
}
|
|
@@ -5,14 +5,18 @@ export default defineNitroPlugin(async (nitroApp) => {
|
|
|
5
5
|
if (runtimeConfig?.configPath) {
|
|
6
6
|
try {
|
|
7
7
|
const configPath = runtimeConfig.configPath;
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
const { pathToFileURL } = await import("url");
|
|
9
|
+
const { default: userConfig } = await import(pathToFileURL(configPath).href);
|
|
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
|
+
}
|
|
16
20
|
}
|
|
17
21
|
} catch (err) {
|
|
18
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.
|
|
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,13 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@nuxt/kit": "^3.11.2",
|
|
12
12
|
"h3": "^1.15.0",
|
|
13
|
-
"@dyrected/
|
|
14
|
-
"@dyrected/
|
|
15
|
-
"@dyrected/sdk": "2.
|
|
13
|
+
"@dyrected/admin": "2.4.0",
|
|
14
|
+
"@dyrected/core": "2.4.0",
|
|
15
|
+
"@dyrected/sdk": "2.4.0"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"nuxt": "^3.0.0",
|
|
19
|
+
"vue": "^3.0.0"
|
|
16
20
|
},
|
|
17
21
|
"devDependencies": {
|
|
18
22
|
"@nuxt/module-builder": "^0.5.5",
|