nuxt-directus-sdk 4.0.5 → 5.0.0-beta.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/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.mjs +298 -0
- package/dist/module.d.mts +39 -12
- package/dist/module.d.ts +166 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +55 -40
- package/dist/rules/index.d.mts +1443 -0
- package/dist/rules/index.d.ts +1443 -0
- package/dist/rules/index.mjs +774 -0
- package/dist/runtime/components/directus-visual-editor.d.vue.ts +11 -6
- package/dist/runtime/components/directus-visual-editor.vue +12 -3
- package/dist/runtime/components/directus-visual-editor.vue.d.ts +11 -6
- package/dist/runtime/composables/auth.d.ts +9 -8
- package/dist/runtime/composables/auth.js +18 -4
- package/dist/runtime/composables/directus.js +23 -4
- package/dist/runtime/composables/files.d.ts +3 -2
- package/dist/runtime/plugin.js +9 -2
- package/dist/runtime/server/services/directus.js +2 -1
- package/dist/runtime/server/services/index.d.ts +1 -1
- package/dist/runtime/server/services/index.js +1 -1
- package/dist/runtime/types/generate.d.ts +2 -2
- package/dist/runtime/types/generate.js +34 -189
- package/dist/runtime/types/index.d.ts +0 -1
- package/dist/runtime/types/index.js +0 -1
- package/dist/runtime/types/types.d.ts +0 -14
- package/dist/runtime/utils/index.d.ts +1 -0
- package/dist/runtime/utils/index.js +3 -0
- package/dist/runtime/utils/slot.js +4 -0
- package/dist/shared/nuxt-directus-sdk.BpCtdNcG.mjs +1412 -0
- package/package.json +16 -8
package/dist/module.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { useLogger, defineNuxtModule, createResolver, addServerHandler,
|
|
1
|
+
import { useLogger, defineNuxtModule, createResolver, addServerHandler, addPlugin, addRouteMiddleware, addImportsDir, addComponentsDir, addImportsSources, addTypeTemplate, hasNuxtModule, installModule } from '@nuxt/kit';
|
|
2
|
+
import { colors } from 'consola/utils';
|
|
2
3
|
import { defu } from 'defu';
|
|
3
4
|
import { joinURL } from 'ufo';
|
|
4
5
|
import { generateTypes } from '../dist/runtime/types/index.js';
|
|
5
6
|
import { useUrl } from '../dist/runtime/utils/index.js';
|
|
6
7
|
|
|
7
8
|
const name = "nuxt-directus-sdk";
|
|
8
|
-
const version = "
|
|
9
|
+
const version = "5.0.0-beta.1";
|
|
9
10
|
|
|
10
11
|
const configKey = "directus";
|
|
11
12
|
const logger = useLogger("nuxt-directus-sdk");
|
|
@@ -25,6 +26,7 @@ const module = defineNuxtModule({
|
|
|
25
26
|
adminToken: import.meta.env.DIRECTUS_ADMIN_TOKEN ?? "",
|
|
26
27
|
devtools: true,
|
|
27
28
|
visualEditor: true,
|
|
29
|
+
image: true,
|
|
28
30
|
types: {
|
|
29
31
|
enabled: true,
|
|
30
32
|
prefix: ""
|
|
@@ -38,7 +40,7 @@ const module = defineNuxtModule({
|
|
|
38
40
|
readMeFields: [],
|
|
39
41
|
redirect: {
|
|
40
42
|
home: "/",
|
|
41
|
-
login: "/
|
|
43
|
+
login: "/auth/login",
|
|
42
44
|
logout: "/"
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -49,26 +51,24 @@ const module = defineNuxtModule({
|
|
|
49
51
|
return;
|
|
50
52
|
}
|
|
51
53
|
const resolver = createResolver(import.meta.url);
|
|
54
|
+
async function registerModule(name2, key, moduleOptions) {
|
|
55
|
+
if (!hasNuxtModule(name2)) {
|
|
56
|
+
await installModule(name2, defu(nuxtApp.options[key], moduleOptions));
|
|
57
|
+
} else {
|
|
58
|
+
nuxtApp.options[key] = defu(nuxtApp.options[key], moduleOptions);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
52
61
|
const devProxyConfig = typeof options.devProxy === "boolean" ? { enabled: options.devProxy } : { ...options.devProxy };
|
|
62
|
+
const directusUrl = options.url;
|
|
53
63
|
const devProxyEnabled = devProxyConfig.enabled ?? nuxtApp.options.dev;
|
|
54
64
|
const devProxyPath = devProxyConfig.path ?? "/directus";
|
|
55
|
-
const
|
|
56
|
-
|
|
65
|
+
const wsProxyPath = devProxyConfig.wsPath ?? `${devProxyPath}-ws`;
|
|
66
|
+
const wsTarget = joinURL(directusUrl, "websocket");
|
|
67
|
+
const loggerMessage = [];
|
|
57
68
|
if (devProxyEnabled && nuxtApp.options.dev) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const proxyUrl = `${baseUrl}${devProxyPath}/`;
|
|
62
|
-
const wsProxyPath = `${devProxyPath}-ws`;
|
|
63
|
-
const wsTarget = joinURL(directusUrl, "websocket");
|
|
64
|
-
logger.info(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
|
|
65
|
-
logger.info(`\u{1F504} Directus Development Proxy Enabled`);
|
|
66
|
-
logger.info(` Proxy path: ${devProxyPath}`);
|
|
67
|
-
logger.info(` Forwarding to: ${directusUrl}`);
|
|
68
|
-
logger.info(` Local URL: ${proxyUrl}`);
|
|
69
|
-
logger.info(` WebSocket proxy path: ${wsProxyPath}`);
|
|
70
|
-
logger.info(` WebSocket target: ${wsTarget}`);
|
|
71
|
-
logger.info(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
|
|
69
|
+
loggerMessage.push(`\u{1F310} Development mode:`);
|
|
70
|
+
loggerMessage.push(`URL${colors.dim(` ${devProxyPath}`)} proxies ${colors.underline(colors.green(`${directusUrl}`))}`);
|
|
71
|
+
loggerMessage.push(`WS URL${colors.dim(` ${wsProxyPath}`)} proxies ${colors.underline(colors.green(`${wsTarget}`))}`);
|
|
72
72
|
nuxtApp.options.nitro = nuxtApp.options.nitro || {};
|
|
73
73
|
nuxtApp.options.nitro.devProxy = nuxtApp.options.nitro.devProxy || {};
|
|
74
74
|
nuxtApp.options.nitro.devProxy[wsProxyPath] = {
|
|
@@ -121,21 +121,35 @@ const module = defineNuxtModule({
|
|
|
121
121
|
route: `${devProxyPath}/**`,
|
|
122
122
|
handler: resolver.resolve("./runtime/server/routes/directus")
|
|
123
123
|
});
|
|
124
|
-
options.
|
|
125
|
-
|
|
124
|
+
options.devProxy = {
|
|
125
|
+
enabled: true,
|
|
126
|
+
path: devProxyPath,
|
|
127
|
+
wsPath: wsProxyPath
|
|
128
|
+
};
|
|
126
129
|
} else if (!nuxtApp.options.dev) {
|
|
127
|
-
|
|
130
|
+
loggerMessage.push(`\u{1F310} Production mode:`, ` SDK connects directly to ${colors.dim(`${directusUrl}`)}`);
|
|
131
|
+
options.devProxy = false;
|
|
128
132
|
}
|
|
129
133
|
options.directusUrl = directusUrl;
|
|
130
134
|
nuxtApp.options.runtimeConfig[configKey] = options;
|
|
131
135
|
nuxtApp.options.runtimeConfig.public = nuxtApp.options.runtimeConfig.public || {};
|
|
132
136
|
nuxtApp.options.runtimeConfig.public[configKey] = defu(nuxtApp.options.runtimeConfig.public[configKey], options);
|
|
133
137
|
delete nuxtApp.options.runtimeConfig.public[configKey].adminToken;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
138
|
+
const imageConfig = typeof options.image === "boolean" ? { enabled: options.image } : options.image;
|
|
139
|
+
const imageEnabled = imageConfig?.enabled ?? true;
|
|
140
|
+
if (imageEnabled) {
|
|
141
|
+
const { setDefaultProvider, modifiers } = imageConfig || {};
|
|
142
|
+
const imageBaseUrl = devProxyEnabled ? `${devProxyPath}/assets` : useUrl(options.url, "assets");
|
|
143
|
+
await registerModule("@nuxt/image", "image", {
|
|
144
|
+
// Set default provider if requested
|
|
145
|
+
...setDefaultProvider && { provider: "directus" },
|
|
146
|
+
// Configure Directus provider
|
|
147
|
+
directus: {
|
|
148
|
+
baseURL: imageBaseUrl,
|
|
149
|
+
modifiers
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
139
153
|
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
140
154
|
addRouteMiddleware({
|
|
141
155
|
name: "auth",
|
|
@@ -227,9 +241,9 @@ const module = defineNuxtModule({
|
|
|
227
241
|
]
|
|
228
242
|
});
|
|
229
243
|
});
|
|
244
|
+
loggerMessage.push(``);
|
|
230
245
|
if (options.devtools) {
|
|
231
|
-
|
|
232
|
-
logger.info(`Directus Admin URL: ${adminUrl}`);
|
|
246
|
+
loggerMessage.push(`Directus Admin added to Nuxt DevTools`);
|
|
233
247
|
nuxtApp.hook("devtools:customTabs", (iframeTabs) => {
|
|
234
248
|
iframeTabs.push({
|
|
235
249
|
name: "directus",
|
|
@@ -237,40 +251,41 @@ const module = defineNuxtModule({
|
|
|
237
251
|
icon: "simple-icons:directus",
|
|
238
252
|
view: {
|
|
239
253
|
type: "iframe",
|
|
240
|
-
src:
|
|
254
|
+
src: useUrl(directusUrl, "admin")
|
|
241
255
|
}
|
|
242
256
|
});
|
|
243
257
|
});
|
|
244
258
|
} else {
|
|
245
|
-
|
|
259
|
+
loggerMessage.push(`${colors.dim(` Directus Admin was not added to Nuxt DevTools`)}`);
|
|
246
260
|
}
|
|
247
|
-
|
|
261
|
+
const typesEnabled = typeof options.types === "boolean" && options.types || options.types && options.types.enabled === true;
|
|
262
|
+
const typesPrefix = typeof options.types === "object" ? options.types.prefix ?? "" : "";
|
|
263
|
+
if (typesEnabled) {
|
|
248
264
|
if (!options.adminToken) {
|
|
249
|
-
|
|
265
|
+
loggerMessage.push(``, `${colors.bgRedBright(`${colors.red("\u2691 ERROR:")} Unable to generate Types`)}`, ` Fix: Set adminToken in config or DIRECTUS_ADMIN_TOKEN in .env`);
|
|
250
266
|
} else {
|
|
251
267
|
try {
|
|
252
268
|
let cachedTypes = null;
|
|
253
|
-
|
|
269
|
+
addTypeTemplate({
|
|
254
270
|
filename: `types/${configKey}.d.ts`,
|
|
255
271
|
async getContents() {
|
|
256
272
|
if (!cachedTypes) {
|
|
257
273
|
cachedTypes = await generateTypes({
|
|
258
|
-
url:
|
|
274
|
+
url: directusUrl,
|
|
259
275
|
token: options.adminToken,
|
|
260
|
-
prefix:
|
|
276
|
+
prefix: typesPrefix
|
|
261
277
|
});
|
|
262
278
|
}
|
|
263
279
|
return cachedTypes;
|
|
264
280
|
}
|
|
265
|
-
}, { nitro: true, nuxt: true })
|
|
266
|
-
|
|
267
|
-
options2.references.push({ path: typesPath });
|
|
268
|
-
});
|
|
281
|
+
}, { nitro: true, nuxt: true });
|
|
282
|
+
loggerMessage.push(`${colors.dim(` Directus Types saved successfully to #build/types/${configKey}.d.ts`)}`);
|
|
269
283
|
} catch (error) {
|
|
270
284
|
logger.error(error.message);
|
|
271
285
|
}
|
|
272
286
|
}
|
|
273
287
|
}
|
|
288
|
+
logger.box({ message: loggerMessage.join("\n"), title: `${colors.magenta(`Nuxt Directus SDK Version: ${colors.magentaBright(`${version}`)}`)}`, style: { padding: 3, borderColor: "magenta", borderStyle: "double-single-rounded" } });
|
|
274
289
|
}
|
|
275
290
|
});
|
|
276
291
|
|