nuxt-directus-sdk 6.0.0-beta.1 → 6.0.0-beta.3
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/README.md +5 -4
- package/dist/cli/index.mjs +1 -1
- package/dist/module.d.mts +22 -2
- package/dist/module.d.ts +22 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +86 -74
- package/dist/rules/index.d.mts +12 -14
- package/dist/rules/index.d.ts +12 -14
- package/dist/rules/index.mjs +2 -2
- package/dist/runtime/composables/auth.d.ts +18 -6
- package/dist/runtime/composables/auth.js +4 -2
- package/dist/runtime/composables/directus.js +0 -1
- package/dist/runtime/composables/files.d.ts +4 -5
- package/dist/runtime/composables/files.js +5 -2
- package/dist/runtime/composables/storage.d.ts +2 -2
- package/dist/runtime/composables/storage.js +4 -6
- package/dist/runtime/middleware/auth.d.ts +1 -1
- package/dist/runtime/middleware/guest.d.ts +1 -1
- package/dist/runtime/plugin.d.ts +1 -1
- package/dist/runtime/plugins/visual-editor.client.d.ts +2 -2
- package/dist/runtime/server/services/directus.js +1 -1
- package/dist/runtime/types/fallback.d.ts +30 -4
- package/dist/runtime/types/generate.d.ts +1 -2
- package/dist/runtime/types/generate.js +5 -5
- package/dist/runtime/types/index.d.ts +1 -1
- package/dist/runtime/types/index.js +1 -1
- package/dist/runtime/types/modules.d.ts +2 -2
- package/dist/runtime/utils/index.d.ts +1 -1
- package/dist/shared/{nuxt-directus-sdk.1qEbZAZ_.mjs → nuxt-directus-sdk.CtcY1peN.mjs} +30 -39
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
> A Nuxt module for Directus with built-in authentication, realtime, file management, type generation, and visual editor support.
|
|
11
11
|
|
|
12
12
|
- [✨ Release Notes](https://github.com/rolleyio/nuxt-directus-sdk/releases)
|
|
13
|
-
- [📚 Documentation](https://nuxt-directus-sdk.
|
|
13
|
+
- [📚 Documentation](https://www.nuxt-directus-sdk.com)
|
|
14
|
+
- [🛝 Live Playground](https://playground.nuxt-directus-sdk.com)
|
|
14
15
|
|
|
15
16
|
## Features
|
|
16
17
|
|
|
@@ -63,11 +64,11 @@ DIRECTUS_URL=https://your-directus-url.com
|
|
|
63
64
|
DIRECTUS_ADMIN_TOKEN=your_admin_token # Optional: required for type generation
|
|
64
65
|
```
|
|
65
66
|
|
|
66
|
-
4. **Configure your Directus backend** for cross-domain authentication (see the [Authentication Guide](https://nuxt-directus-sdk.
|
|
67
|
+
4. **Configure your Directus backend** for cross-domain authentication (see the [Authentication Guide](https://www.nuxt-directus-sdk.com/guide/authentication.html))
|
|
67
68
|
|
|
68
69
|
That's it! You can now use Directus within your Nuxt app ✨
|
|
69
70
|
|
|
70
|
-
For cross-domain setups (e.g. `app.example.com` and `api.example.com`), see the [Authentication Guide](https://nuxt-directus-sdk.
|
|
71
|
+
For cross-domain setups (e.g. `app.example.com` and `api.example.com`), see the [Authentication Guide](https://www.nuxt-directus-sdk.com/guide/authentication.html).
|
|
71
72
|
|
|
72
73
|
## CLI
|
|
73
74
|
|
|
@@ -84,7 +85,7 @@ npx nuxt-directus-sdk rules:pull -o rules.json
|
|
|
84
85
|
npx nuxt-directus-sdk --help
|
|
85
86
|
```
|
|
86
87
|
|
|
87
|
-
See the [CLI documentation](https://nuxt-directus-sdk.
|
|
88
|
+
See the [CLI documentation](https://www.nuxt-directus-sdk.com/api/configuration/module#types) for flags and examples.
|
|
88
89
|
|
|
89
90
|
## Development
|
|
90
91
|
|
package/dist/cli/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
|
3
3
|
import { resolve, dirname } from 'node:path';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
5
|
import { createDirectus, staticToken, rest } from '@directus/sdk';
|
|
6
|
-
import { d as diffRemoteRules, e as formatDiff, c as compareRulesPayloads, f as fetchRemoteRules, k as loadRulesFromPayload, o as pushRules, g as formatPushResult, b as fetchRemoteRulesAsJson } from '../shared/nuxt-directus-sdk.
|
|
6
|
+
import { d as diffRemoteRules, e as formatDiff, c as compareRulesPayloads, f as fetchRemoteRules, k as loadRulesFromPayload, o as pushRules, g as formatPushResult, b as fetchRemoteRulesAsJson } from '../shared/nuxt-directus-sdk.CtcY1peN.mjs';
|
|
7
7
|
import { generateTypesFromDirectus } from '../../dist/runtime/types/generate.js';
|
|
8
8
|
|
|
9
9
|
function parseCsv(raw) {
|
package/dist/module.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { Query } from '@directus/sdk';
|
|
2
|
+
import { Query, DirectusUser } from '@directus/sdk';
|
|
3
3
|
import { ImageProviders, ImageModifiers } from '@nuxt/image';
|
|
4
4
|
|
|
5
5
|
type DirectusUrl = string | {
|
|
6
6
|
client: string;
|
|
7
7
|
server: string;
|
|
8
8
|
};
|
|
9
|
-
type ReadMeFields = Query<DirectusSchema, DirectusSchema['
|
|
9
|
+
type ReadMeFields = Query<DirectusSchema, DirectusUser<DirectusSchema>>['fields'];
|
|
10
10
|
interface ModuleOptions {
|
|
11
11
|
/**
|
|
12
12
|
* Directus API URL
|
|
@@ -189,6 +189,26 @@ interface ModuleOptions {
|
|
|
189
189
|
*/
|
|
190
190
|
verbose?: boolean;
|
|
191
191
|
};
|
|
192
|
+
/**
|
|
193
|
+
* Auto-import functions from `@directus/sdk`.
|
|
194
|
+
*
|
|
195
|
+
* - `true` (default) — auto-imports every SDK function except those wrapped by
|
|
196
|
+
* this module (e.g. `createDirectus`, `rest`, `authentication`) or explicitly
|
|
197
|
+
* unsupported (e.g. `graphql`, `readGraphqlSdl`).
|
|
198
|
+
* - `false` — disables auto-imports entirely. You import from `@directus/sdk`
|
|
199
|
+
* manually wherever you use SDK functions.
|
|
200
|
+
* - `{ exclude: [...] }` — auto-imports with additional functions excluded.
|
|
201
|
+
* Useful if an SDK function name collides with something else in your app.
|
|
202
|
+
*
|
|
203
|
+
* @default true
|
|
204
|
+
*/
|
|
205
|
+
autoImportSdk?: boolean | {
|
|
206
|
+
/**
|
|
207
|
+
* Additional SDK function names to exclude from auto-import.
|
|
208
|
+
* Added on top of the module's built-in exclusions.
|
|
209
|
+
*/
|
|
210
|
+
exclude?: string[];
|
|
211
|
+
};
|
|
192
212
|
}
|
|
193
213
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
194
214
|
|
package/dist/module.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { Query } from '@directus/sdk';
|
|
2
|
+
import { Query, DirectusUser } from '@directus/sdk';
|
|
3
3
|
import { ImageProviders, ImageModifiers } from '@nuxt/image';
|
|
4
4
|
|
|
5
5
|
type DirectusUrl = string | {
|
|
6
6
|
client: string;
|
|
7
7
|
server: string;
|
|
8
8
|
};
|
|
9
|
-
type ReadMeFields = Query<DirectusSchema, DirectusSchema['
|
|
9
|
+
type ReadMeFields = Query<DirectusSchema, DirectusUser<DirectusSchema>>['fields'];
|
|
10
10
|
interface ModuleOptions {
|
|
11
11
|
/**
|
|
12
12
|
* Directus API URL
|
|
@@ -189,6 +189,26 @@ interface ModuleOptions {
|
|
|
189
189
|
*/
|
|
190
190
|
verbose?: boolean;
|
|
191
191
|
};
|
|
192
|
+
/**
|
|
193
|
+
* Auto-import functions from `@directus/sdk`.
|
|
194
|
+
*
|
|
195
|
+
* - `true` (default) — auto-imports every SDK function except those wrapped by
|
|
196
|
+
* this module (e.g. `createDirectus`, `rest`, `authentication`) or explicitly
|
|
197
|
+
* unsupported (e.g. `graphql`, `readGraphqlSdl`).
|
|
198
|
+
* - `false` — disables auto-imports entirely. You import from `@directus/sdk`
|
|
199
|
+
* manually wherever you use SDK functions.
|
|
200
|
+
* - `{ exclude: [...] }` — auto-imports with additional functions excluded.
|
|
201
|
+
* Useful if an SDK function name collides with something else in your app.
|
|
202
|
+
*
|
|
203
|
+
* @default true
|
|
204
|
+
*/
|
|
205
|
+
autoImportSdk?: boolean | {
|
|
206
|
+
/**
|
|
207
|
+
* Additional SDK function names to exclude from auto-import.
|
|
208
|
+
* Added on top of the module's built-in exclusions.
|
|
209
|
+
*/
|
|
210
|
+
exclude?: string[];
|
|
211
|
+
};
|
|
192
212
|
}
|
|
193
213
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
194
214
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,12 +1,59 @@
|
|
|
1
|
+
import * as directusSdk from '@directus/sdk';
|
|
1
2
|
import { useLogger, defineNuxtModule, createResolver, addServerHandler, hasNuxtModule, tryResolveModule, addPlugin, addComponentsDir, addRouteMiddleware, addImportsDir, addImportsSources, addTypeTemplate, installModule } from '@nuxt/kit';
|
|
2
3
|
import { colors } from 'consola/utils';
|
|
3
4
|
import { defu } from 'defu';
|
|
4
5
|
import { joinURL } from 'ufo';
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
5
7
|
import { generateTypesFromDirectus } from '../dist/runtime/types/index.js';
|
|
6
8
|
import { useUrl } from '../dist/runtime/utils/index.js';
|
|
7
9
|
|
|
8
10
|
const name = "nuxt-directus-sdk";
|
|
9
|
-
const version = "6.0.0-beta.
|
|
11
|
+
const version = "6.0.0-beta.3";
|
|
12
|
+
|
|
13
|
+
const SDK_CLIENT_FACTORIES = /* @__PURE__ */ new Set([
|
|
14
|
+
"createDirectus",
|
|
15
|
+
"rest",
|
|
16
|
+
"graphql",
|
|
17
|
+
"authentication",
|
|
18
|
+
"staticToken",
|
|
19
|
+
"realtime",
|
|
20
|
+
"memoryStorage",
|
|
21
|
+
"readGraphqlSdl"
|
|
22
|
+
]);
|
|
23
|
+
const SDK_REALTIME_INTERNALS = /* @__PURE__ */ new Set([
|
|
24
|
+
"auth",
|
|
25
|
+
"pong",
|
|
26
|
+
"sleep",
|
|
27
|
+
"messageCallback"
|
|
28
|
+
]);
|
|
29
|
+
const SDK_INTERNALS = /* @__PURE__ */ new Set([
|
|
30
|
+
"throwIfEmpty",
|
|
31
|
+
"throwIfCoreCollection",
|
|
32
|
+
"getAuthEndpoint",
|
|
33
|
+
"formatFields",
|
|
34
|
+
"queryToParams"
|
|
35
|
+
]);
|
|
36
|
+
const SDK_COMPOSABLE_WRAPPED = /* @__PURE__ */ new Set([
|
|
37
|
+
"readMe",
|
|
38
|
+
"updateMe",
|
|
39
|
+
"createUser",
|
|
40
|
+
"inviteUser",
|
|
41
|
+
"acceptUserInvite",
|
|
42
|
+
"passwordRequest",
|
|
43
|
+
"passwordReset",
|
|
44
|
+
"uploadFiles"
|
|
45
|
+
]);
|
|
46
|
+
const SDK_DENYLIST = /* @__PURE__ */ new Set([
|
|
47
|
+
...SDK_CLIENT_FACTORIES,
|
|
48
|
+
...SDK_REALTIME_INTERNALS,
|
|
49
|
+
...SDK_INTERNALS,
|
|
50
|
+
...SDK_COMPOSABLE_WRAPPED
|
|
51
|
+
]);
|
|
52
|
+
function discoverSdkImports(sdkModule, userExclude = /* @__PURE__ */ new Set()) {
|
|
53
|
+
return Object.keys(sdkModule).filter(
|
|
54
|
+
(key) => typeof sdkModule[key] === "function" && !SDK_DENYLIST.has(key) && !userExclude.has(key)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
10
57
|
|
|
11
58
|
const configKey = "directus";
|
|
12
59
|
const logger = useLogger("nuxt-directus-sdk");
|
|
@@ -31,6 +78,7 @@ const module$1 = defineNuxtModule({
|
|
|
31
78
|
enabled: true,
|
|
32
79
|
prefix: ""
|
|
33
80
|
},
|
|
81
|
+
autoImportSdk: true,
|
|
34
82
|
auth: {
|
|
35
83
|
enabled: true,
|
|
36
84
|
enableGlobalAuthMiddleware: false,
|
|
@@ -46,12 +94,14 @@ const module$1 = defineNuxtModule({
|
|
|
46
94
|
}
|
|
47
95
|
},
|
|
48
96
|
async setup(options, nuxtApp) {
|
|
97
|
+
const loggerMessage = [];
|
|
49
98
|
const clientUrl = typeof options.url === "string" ? options.url : options.url?.client;
|
|
50
99
|
const serverUrl = typeof options.url === "string" ? options.url : options.url?.server;
|
|
51
100
|
if (!clientUrl) {
|
|
52
|
-
|
|
101
|
+
loggerMessage.push(`\u26A0\uFE0F No Directus URL found at build time:`, ` - Set it in config options, .env file as DIRECTUS_URL or at runtime via NUXT_PUBLIC_DIRECTUS_URL.`, "");
|
|
53
102
|
}
|
|
54
103
|
const resolver = createResolver(import.meta.url);
|
|
104
|
+
const fallbackTypeContent = readFileSync(resolver.resolve("./runtime/types/fallback.d.ts"), "utf-8");
|
|
55
105
|
async function registerModule(name2, key, moduleOptions) {
|
|
56
106
|
if (!hasNuxtModule(name2)) {
|
|
57
107
|
await installModule(name2, defu(nuxtApp.options[key], moduleOptions));
|
|
@@ -59,7 +109,6 @@ const module$1 = defineNuxtModule({
|
|
|
59
109
|
nuxtApp.options[key] = defu(nuxtApp.options[key], moduleOptions);
|
|
60
110
|
}
|
|
61
111
|
}
|
|
62
|
-
const loggerMessage = [];
|
|
63
112
|
const devProxyConfig = typeof options.devProxy === "boolean" ? { enabled: options.devProxy } : { ...options.devProxy };
|
|
64
113
|
const directusUrl = serverUrl || clientUrl;
|
|
65
114
|
const devProxyEnabled = devProxyConfig.enabled ?? nuxtApp.options.dev;
|
|
@@ -104,8 +153,8 @@ const module$1 = defineNuxtModule({
|
|
|
104
153
|
if (req.url?.startsWith(wsProxyPath)) {
|
|
105
154
|
try {
|
|
106
155
|
proxy.ws(req, socket, head);
|
|
107
|
-
} catch (
|
|
108
|
-
logger.error("WebSocket proxy error:",
|
|
156
|
+
} catch (error) {
|
|
157
|
+
logger.error("WebSocket proxy error:", error instanceof Error ? error.message : String(error));
|
|
109
158
|
if (!socket.destroyed) {
|
|
110
159
|
socket.destroy();
|
|
111
160
|
}
|
|
@@ -127,7 +176,7 @@ const module$1 = defineNuxtModule({
|
|
|
127
176
|
path: devProxyPath,
|
|
128
177
|
wsPath: wsProxyPath
|
|
129
178
|
};
|
|
130
|
-
} else if (!nuxtApp.options.dev) {
|
|
179
|
+
} else if (!nuxtApp.options.dev && directusUrl) {
|
|
131
180
|
loggerMessage.push(`\u{1F310} Production Mode:`, ` - SDK connects directly to ${colors.dim(`${directusUrl}`)}`, "");
|
|
132
181
|
options.devProxy = false;
|
|
133
182
|
}
|
|
@@ -165,7 +214,7 @@ const module$1 = defineNuxtModule({
|
|
|
165
214
|
prefix: "",
|
|
166
215
|
global: true
|
|
167
216
|
});
|
|
168
|
-
loggerMessage.push("\u{1F4DD} Visual Editor
|
|
217
|
+
loggerMessage.push("\u{1F4DD} Visual Editor Component Added", "");
|
|
169
218
|
}
|
|
170
219
|
if (options.auth?.enableGlobalAuthMiddleware) {
|
|
171
220
|
loggerMessage.push("\u{1F512} Auth middleware installed globally.", "");
|
|
@@ -180,69 +229,24 @@ const module$1 = defineNuxtModule({
|
|
|
180
229
|
path: resolver.resolve("./runtime/middleware/guest")
|
|
181
230
|
});
|
|
182
231
|
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
183
|
-
const
|
|
232
|
+
const autoImportSdk = options.autoImportSdk ?? true;
|
|
233
|
+
const userExclude = new Set(
|
|
234
|
+
typeof autoImportSdk === "object" && autoImportSdk?.exclude ? autoImportSdk.exclude : []
|
|
235
|
+
);
|
|
236
|
+
const directusSdkImports = autoImportSdk === false ? null : {
|
|
184
237
|
from: "@directus/sdk",
|
|
185
|
-
imports:
|
|
186
|
-
"aggregate",
|
|
187
|
-
"generateUid",
|
|
188
|
-
"createComment",
|
|
189
|
-
"updateComment",
|
|
190
|
-
"deleteComment",
|
|
191
|
-
"createField",
|
|
192
|
-
"createItem",
|
|
193
|
-
"createItems",
|
|
194
|
-
"deleteField",
|
|
195
|
-
"deleteFile",
|
|
196
|
-
"deleteFiles",
|
|
197
|
-
"readActivities",
|
|
198
|
-
"readActivity",
|
|
199
|
-
"deleteItem",
|
|
200
|
-
"deleteItems",
|
|
201
|
-
"deleteUser",
|
|
202
|
-
"deleteUsers",
|
|
203
|
-
"importFile",
|
|
204
|
-
"readCollection",
|
|
205
|
-
"readCollections",
|
|
206
|
-
"createCollection",
|
|
207
|
-
"updateCollection",
|
|
208
|
-
"deleteCollection",
|
|
209
|
-
"readField",
|
|
210
|
-
"readFieldsByCollection",
|
|
211
|
-
"readFields",
|
|
212
|
-
"readFile",
|
|
213
|
-
"readFiles",
|
|
214
|
-
"readItem",
|
|
215
|
-
"readItems",
|
|
216
|
-
"readSingleton",
|
|
217
|
-
"readMe",
|
|
218
|
-
"createUser",
|
|
219
|
-
"createUsers",
|
|
220
|
-
"readUser",
|
|
221
|
-
"readUsers",
|
|
222
|
-
"readProviders",
|
|
223
|
-
"readFolder",
|
|
224
|
-
"readFolders",
|
|
225
|
-
"uploadFiles",
|
|
226
|
-
"updateField",
|
|
227
|
-
"updateFile",
|
|
228
|
-
"updateFiles",
|
|
229
|
-
"updateFolder",
|
|
230
|
-
"updateFolders",
|
|
231
|
-
"updateItem",
|
|
232
|
-
"updateItems",
|
|
233
|
-
"updateSingleton",
|
|
234
|
-
"updateMe",
|
|
235
|
-
"updateUser",
|
|
236
|
-
"updateUsers",
|
|
237
|
-
"withToken"
|
|
238
|
-
]
|
|
238
|
+
imports: discoverSdkImports(directusSdk, userExclude)
|
|
239
239
|
};
|
|
240
|
-
|
|
240
|
+
if (directusSdkImports) {
|
|
241
|
+
addImportsSources(directusSdkImports);
|
|
242
|
+
}
|
|
241
243
|
nuxtApp.hook("nitro:config", (nitroConfig) => {
|
|
242
244
|
nitroConfig.alias = nitroConfig.alias || {};
|
|
243
245
|
nitroConfig.imports = nitroConfig.imports || {};
|
|
244
246
|
nitroConfig.imports.presets = nitroConfig.imports.presets || [];
|
|
245
|
-
|
|
247
|
+
if (directusSdkImports) {
|
|
248
|
+
nitroConfig.imports.presets.push(directusSdkImports);
|
|
249
|
+
}
|
|
246
250
|
nitroConfig.imports.presets.push({
|
|
247
251
|
from: resolver.resolve("./runtime/server/services"),
|
|
248
252
|
imports: [
|
|
@@ -274,34 +278,42 @@ const module$1 = defineNuxtModule({
|
|
|
274
278
|
const typesExpandReferences = typeof options.types === "object" ? options.types.expandReferences ?? true : true;
|
|
275
279
|
const typesExclude = typeof options.types === "object" ? options.types.exclude ?? [] : [];
|
|
276
280
|
const typesVerbose = typeof options.types === "object" ? options.types.verbose ?? false : false;
|
|
281
|
+
let typeString = fallbackTypeContent;
|
|
277
282
|
if (typesEnabled) {
|
|
278
283
|
loggerMessage.push("\u{1F4CB} Directus Type Generator Enabled");
|
|
279
284
|
if (!options.adminToken) {
|
|
280
|
-
loggerMessage.push(` ${colors.bgRedBright(`${colors.red("\u2691 ERROR:")} Unable to generate Types`)}`, ` Fix: Set adminToken in config or DIRECTUS_ADMIN_TOKEN in .env`);
|
|
285
|
+
loggerMessage.push(` ${colors.bgRedBright(`${colors.red("\u2691 ERROR:")} Unable to generate Types`)}`, ` Fix: Set adminToken in config or DIRECTUS_ADMIN_TOKEN in .env`, ` - Fallback DirectusSchema is being used ${colors.dim("(not recommended)")}`);
|
|
281
286
|
} else {
|
|
282
287
|
try {
|
|
283
|
-
const { typeString, logs } = await generateTypesFromDirectus(directusUrl, options.adminToken, typesPrefix, {
|
|
288
|
+
const { typeString: generated, logs } = await generateTypesFromDirectus(directusUrl, options.adminToken, typesPrefix, {
|
|
284
289
|
include: typesInclude,
|
|
285
290
|
expandReferences: typesExpandReferences,
|
|
286
291
|
exclude: typesExclude,
|
|
287
292
|
verbose: typesVerbose
|
|
288
293
|
});
|
|
289
294
|
loggerMessage.push(...logs);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
295
|
+
if (generated !== null) {
|
|
296
|
+
typeString = generated;
|
|
297
|
+
if (!logs.some((log) => log.toLowerCase().includes("error"))) {
|
|
298
|
+
loggerMessage.push(` - Directus Types saved successfully to ${colors.dim(`#build/types/${configKey}.d.ts`)}`);
|
|
299
|
+
} else {
|
|
300
|
+
throw new Error(` ${colors.bgRedBright(`${colors.red("\u2691 ERROR:")} TypeGenerator returned an error`)}`);
|
|
294
301
|
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
throw new Error(` ${colors.bgRedBright(`${colors.red("\u2691 ERROR:")} TypeGenerator returned an error`)}`);
|
|
302
|
+
} else {
|
|
303
|
+
loggerMessage.push(` - Fallback DirectusSchema is being used ${colors.dim("(not recommended)")}`);
|
|
298
304
|
}
|
|
299
|
-
loggerMessage.push(` - Directus Types saved successfully to ${colors.dim(`#build/types/${configKey}.d.ts`)}`);
|
|
300
305
|
} catch (error) {
|
|
306
|
+
typeString = fallbackTypeContent;
|
|
301
307
|
loggerMessage.push(`${error instanceof Error ? error.message : String(error)}`, ` - Fallback DirectusSchema is being used ${colors.dim("(not recommended)")}`);
|
|
302
308
|
}
|
|
303
309
|
}
|
|
304
310
|
}
|
|
311
|
+
addTypeTemplate({
|
|
312
|
+
filename: `types/${configKey}.d.ts`,
|
|
313
|
+
getContents() {
|
|
314
|
+
return typeString;
|
|
315
|
+
}
|
|
316
|
+
}, { nitro: true, nuxt: true });
|
|
305
317
|
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" } });
|
|
306
318
|
}
|
|
307
319
|
});
|
package/dist/rules/index.d.mts
CHANGED
|
@@ -98,8 +98,8 @@ interface PermissionConfig<Schema, Collection extends keyof Schema> {
|
|
|
98
98
|
fields?: '*' | (keyof CollectionItem<Schema, Collection>)[];
|
|
99
99
|
/** Filter that restricts which items can be accessed */
|
|
100
100
|
filter?: QueryFilter<Schema, CollectionItem<Schema, Collection>>;
|
|
101
|
-
/** Default values applied when creating/updating items */
|
|
102
|
-
presets?: Partial<CollectionItem<Schema, Collection
|
|
101
|
+
/** Default values applied when creating/updating items. Accepts schema-typed values or Directus Dynamic Variables (e.g. `$CURRENT_USER`) */
|
|
102
|
+
presets?: Partial<CollectionItem<Schema, Collection>> | Record<string, unknown>;
|
|
103
103
|
/** Validation rules using Standard Schema or Directus format */
|
|
104
104
|
validation?: StandardSchemaV1<Partial<CollectionItem<Schema, Collection>>> | DirectusValidation;
|
|
105
105
|
}
|
|
@@ -301,8 +301,8 @@ interface PermissionConfigInput<Schema, K extends keyof Schema> {
|
|
|
301
301
|
fields?: '*' | (keyof CollectionItem<Schema, K>)[];
|
|
302
302
|
/** Filter that restricts which items can be accessed */
|
|
303
303
|
filter?: QueryFilter<Schema, CollectionItem<Schema, K>>;
|
|
304
|
-
/** Default values applied when creating/updating items */
|
|
305
|
-
presets?: Partial<CollectionItem<Schema, K
|
|
304
|
+
/** Default values applied when creating/updating items. Accepts schema-typed values or Directus Dynamic Variables (e.g. `$CURRENT_USER`) */
|
|
305
|
+
presets?: Partial<CollectionItem<Schema, K>> | Record<string, unknown>;
|
|
306
306
|
/** Validation rules using Standard Schema or Directus format */
|
|
307
307
|
validation?: StandardSchemaV1<Partial<CollectionItem<Schema, K>>> | DirectusValidation;
|
|
308
308
|
}
|
|
@@ -605,11 +605,9 @@ interface DiffChange<T> {
|
|
|
605
605
|
remote?: T;
|
|
606
606
|
}
|
|
607
607
|
/** Role diff change */
|
|
608
|
-
|
|
609
|
-
}
|
|
608
|
+
type RoleDiffChange = DiffChange<DirectusRolePayload>;
|
|
610
609
|
/** Policy diff change */
|
|
611
|
-
|
|
612
|
-
}
|
|
610
|
+
type PolicyDiffChange = DiffChange<DirectusPolicyPayload>;
|
|
613
611
|
/** Permission diff change */
|
|
614
612
|
interface PermissionDiffChange extends DiffChange<DirectusPermissionPayload> {
|
|
615
613
|
collection: string;
|
|
@@ -935,7 +933,7 @@ declare function evaluateFilter<T extends Record<string, unknown>>(filter: Recor
|
|
|
935
933
|
* @param collection - The collection name
|
|
936
934
|
* @returns Array of accessible field names, '*' for all, or empty array for none
|
|
937
935
|
*/
|
|
938
|
-
declare function getAccessibleFields<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
936
|
+
declare function getAccessibleFields<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K): (keyof CollectionItem<Schema, K>)[] | '*';
|
|
939
937
|
/**
|
|
940
938
|
* Check if a role/policy grants access to a specific field
|
|
941
939
|
*
|
|
@@ -946,7 +944,7 @@ declare function getAccessibleFields<Schema>(rules: RulesConfig<Schema>, roleOrP
|
|
|
946
944
|
* @param field - The field to check
|
|
947
945
|
* @returns true if the field is accessible
|
|
948
946
|
*/
|
|
949
|
-
declare function canAccessField<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
947
|
+
declare function canAccessField<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof CollectionItem<Schema, K>): boolean;
|
|
950
948
|
/**
|
|
951
949
|
* Get presets for a permission
|
|
952
950
|
*
|
|
@@ -956,7 +954,7 @@ declare function canAccessField<Schema>(rules: RulesConfig<Schema>, roleOrPolicy
|
|
|
956
954
|
* @param collection - The collection name
|
|
957
955
|
* @returns The presets object or null
|
|
958
956
|
*/
|
|
959
|
-
declare function getPresets<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
957
|
+
declare function getPresets<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K): Partial<CollectionItem<Schema, K>> | null;
|
|
960
958
|
|
|
961
959
|
/**
|
|
962
960
|
* Rules tester - main testing interface
|
|
@@ -1006,15 +1004,15 @@ interface RulesTester<Schema> {
|
|
|
1006
1004
|
/**
|
|
1007
1005
|
* Get accessible fields for a permission
|
|
1008
1006
|
*/
|
|
1009
|
-
getAccessibleFields: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => (keyof Schema
|
|
1007
|
+
getAccessibleFields: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => (keyof CollectionItem<Schema, K>)[] | '*';
|
|
1010
1008
|
/**
|
|
1011
1009
|
* Check if a specific field is accessible
|
|
1012
1010
|
*/
|
|
1013
|
-
canAccessField: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof Schema
|
|
1011
|
+
canAccessField: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof CollectionItem<Schema, K>) => boolean;
|
|
1014
1012
|
/**
|
|
1015
1013
|
* Get presets for a permission
|
|
1016
1014
|
*/
|
|
1017
|
-
getPresets: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => Partial<Schema
|
|
1015
|
+
getPresets: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => Partial<CollectionItem<Schema, K>> | null;
|
|
1018
1016
|
/**
|
|
1019
1017
|
* Validate an item against permission validation rules
|
|
1020
1018
|
*/
|
package/dist/rules/index.d.ts
CHANGED
|
@@ -98,8 +98,8 @@ interface PermissionConfig<Schema, Collection extends keyof Schema> {
|
|
|
98
98
|
fields?: '*' | (keyof CollectionItem<Schema, Collection>)[];
|
|
99
99
|
/** Filter that restricts which items can be accessed */
|
|
100
100
|
filter?: QueryFilter<Schema, CollectionItem<Schema, Collection>>;
|
|
101
|
-
/** Default values applied when creating/updating items */
|
|
102
|
-
presets?: Partial<CollectionItem<Schema, Collection
|
|
101
|
+
/** Default values applied when creating/updating items. Accepts schema-typed values or Directus Dynamic Variables (e.g. `$CURRENT_USER`) */
|
|
102
|
+
presets?: Partial<CollectionItem<Schema, Collection>> | Record<string, unknown>;
|
|
103
103
|
/** Validation rules using Standard Schema or Directus format */
|
|
104
104
|
validation?: StandardSchemaV1<Partial<CollectionItem<Schema, Collection>>> | DirectusValidation;
|
|
105
105
|
}
|
|
@@ -301,8 +301,8 @@ interface PermissionConfigInput<Schema, K extends keyof Schema> {
|
|
|
301
301
|
fields?: '*' | (keyof CollectionItem<Schema, K>)[];
|
|
302
302
|
/** Filter that restricts which items can be accessed */
|
|
303
303
|
filter?: QueryFilter<Schema, CollectionItem<Schema, K>>;
|
|
304
|
-
/** Default values applied when creating/updating items */
|
|
305
|
-
presets?: Partial<CollectionItem<Schema, K
|
|
304
|
+
/** Default values applied when creating/updating items. Accepts schema-typed values or Directus Dynamic Variables (e.g. `$CURRENT_USER`) */
|
|
305
|
+
presets?: Partial<CollectionItem<Schema, K>> | Record<string, unknown>;
|
|
306
306
|
/** Validation rules using Standard Schema or Directus format */
|
|
307
307
|
validation?: StandardSchemaV1<Partial<CollectionItem<Schema, K>>> | DirectusValidation;
|
|
308
308
|
}
|
|
@@ -605,11 +605,9 @@ interface DiffChange<T> {
|
|
|
605
605
|
remote?: T;
|
|
606
606
|
}
|
|
607
607
|
/** Role diff change */
|
|
608
|
-
|
|
609
|
-
}
|
|
608
|
+
type RoleDiffChange = DiffChange<DirectusRolePayload>;
|
|
610
609
|
/** Policy diff change */
|
|
611
|
-
|
|
612
|
-
}
|
|
610
|
+
type PolicyDiffChange = DiffChange<DirectusPolicyPayload>;
|
|
613
611
|
/** Permission diff change */
|
|
614
612
|
interface PermissionDiffChange extends DiffChange<DirectusPermissionPayload> {
|
|
615
613
|
collection: string;
|
|
@@ -935,7 +933,7 @@ declare function evaluateFilter<T extends Record<string, unknown>>(filter: Recor
|
|
|
935
933
|
* @param collection - The collection name
|
|
936
934
|
* @returns Array of accessible field names, '*' for all, or empty array for none
|
|
937
935
|
*/
|
|
938
|
-
declare function getAccessibleFields<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
936
|
+
declare function getAccessibleFields<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K): (keyof CollectionItem<Schema, K>)[] | '*';
|
|
939
937
|
/**
|
|
940
938
|
* Check if a role/policy grants access to a specific field
|
|
941
939
|
*
|
|
@@ -946,7 +944,7 @@ declare function getAccessibleFields<Schema>(rules: RulesConfig<Schema>, roleOrP
|
|
|
946
944
|
* @param field - The field to check
|
|
947
945
|
* @returns true if the field is accessible
|
|
948
946
|
*/
|
|
949
|
-
declare function canAccessField<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
947
|
+
declare function canAccessField<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof CollectionItem<Schema, K>): boolean;
|
|
950
948
|
/**
|
|
951
949
|
* Get presets for a permission
|
|
952
950
|
*
|
|
@@ -956,7 +954,7 @@ declare function canAccessField<Schema>(rules: RulesConfig<Schema>, roleOrPolicy
|
|
|
956
954
|
* @param collection - The collection name
|
|
957
955
|
* @returns The presets object or null
|
|
958
956
|
*/
|
|
959
|
-
declare function getPresets<Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection:
|
|
957
|
+
declare function getPresets<Schema, K extends keyof Schema>(rules: RulesConfig<Schema>, roleOrPolicy: string, action: PermissionAction, collection: K): Partial<CollectionItem<Schema, K>> | null;
|
|
960
958
|
|
|
961
959
|
/**
|
|
962
960
|
* Rules tester - main testing interface
|
|
@@ -1006,15 +1004,15 @@ interface RulesTester<Schema> {
|
|
|
1006
1004
|
/**
|
|
1007
1005
|
* Get accessible fields for a permission
|
|
1008
1006
|
*/
|
|
1009
|
-
getAccessibleFields: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => (keyof Schema
|
|
1007
|
+
getAccessibleFields: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => (keyof CollectionItem<Schema, K>)[] | '*';
|
|
1010
1008
|
/**
|
|
1011
1009
|
* Check if a specific field is accessible
|
|
1012
1010
|
*/
|
|
1013
|
-
canAccessField: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof Schema
|
|
1011
|
+
canAccessField: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K, field: keyof CollectionItem<Schema, K>) => boolean;
|
|
1014
1012
|
/**
|
|
1015
1013
|
* Get presets for a permission
|
|
1016
1014
|
*/
|
|
1017
|
-
getPresets: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => Partial<Schema
|
|
1015
|
+
getPresets: <K extends keyof Schema>(roleOrPolicy: string, action: PermissionAction, collection: K) => Partial<CollectionItem<Schema, K>> | null;
|
|
1018
1016
|
/**
|
|
1019
1017
|
* Validate an item against permission validation rules
|
|
1020
1018
|
*/
|
package/dist/rules/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as isStandardSchema } from '../shared/nuxt-directus-sdk.
|
|
2
|
-
export { c as compareRulesPayloads, d as diffRemoteRules, a as diffRules, f as fetchRemoteRules, b as fetchRemoteRulesAsJson, e as formatDiff, g as formatPushResult, h as isValidationStandardSchema, l as loadRulesFromJson, j as loadRulesFromJsonFile, k as loadRulesFromPayload, m as loadRulesFromPayloadFile, n as normalizeRules, p as pullRules, o as pushRules, r as rulesToJson, s as serializeToDirectusApi, q as serializeToJson, t as toDirectusValidation } from '../shared/nuxt-directus-sdk.
|
|
1
|
+
import { i as isStandardSchema } from '../shared/nuxt-directus-sdk.CtcY1peN.mjs';
|
|
2
|
+
export { c as compareRulesPayloads, d as diffRemoteRules, a as diffRules, f as fetchRemoteRules, b as fetchRemoteRulesAsJson, e as formatDiff, g as formatPushResult, h as isValidationStandardSchema, l as loadRulesFromJson, j as loadRulesFromJsonFile, k as loadRulesFromPayload, m as loadRulesFromPayloadFile, n as normalizeRules, p as pullRules, o as pushRules, r as rulesToJson, s as serializeToDirectusApi, q as serializeToJson, t as toDirectusValidation } from '../shared/nuxt-directus-sdk.CtcY1peN.mjs';
|
|
3
3
|
import '@directus/sdk';
|
|
4
4
|
|
|
5
5
|
function isPolicyReference(input) {
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import type { ComputedRef, Ref } from '#imports';
|
|
2
2
|
import type { RouteLocationRaw } from '#vue-router';
|
|
3
|
-
import type { LoginOptions } from '@directus/sdk';
|
|
4
|
-
import type {
|
|
3
|
+
import type { DirectusUser as DirectusUserSDK, NestedPartial, LoginOptions } from '@directus/sdk';
|
|
4
|
+
import type { RegisterUserInput } from '@directus/types';
|
|
5
|
+
/**
|
|
6
|
+
* Fields that can be passed to {@link useDirectusAuth.updateMe}.
|
|
7
|
+
*
|
|
8
|
+
* `role` and `policies` are intentionally excluded — users cannot elevate their
|
|
9
|
+
* own privileges via this composable.
|
|
10
|
+
*
|
|
11
|
+
* `avatar` accepts a pre-uploaded file ID (`string`). To change a user's avatar,
|
|
12
|
+
* first upload the file via the files endpoint to get its ID, then pass that ID here.
|
|
13
|
+
*/
|
|
14
|
+
export type UpdateMeInput = Omit<NestedPartial<DirectusUserSDK<DirectusSchema>>, 'id' | 'role' | 'policies' | 'avatar'> & {
|
|
15
|
+
avatar?: string | null;
|
|
16
|
+
};
|
|
5
17
|
export interface DirectusAuth {
|
|
6
18
|
user: Ref<DirectusUser | null>;
|
|
7
19
|
loggedIn: ComputedRef<boolean>;
|
|
8
|
-
readMe: () => Promise<DirectusUser |
|
|
9
|
-
updateMe: (data:
|
|
20
|
+
readMe: () => Promise<DirectusUser | null>;
|
|
21
|
+
updateMe: (data: UpdateMeInput) => Promise<DirectusUser>;
|
|
10
22
|
login: (email: string, password: string, options?: LoginOptions & {
|
|
11
23
|
redirect?: boolean | RouteLocationRaw;
|
|
12
24
|
}) => Promise<DirectusUser | null>;
|
|
13
25
|
loginWithProvider: (provider: string, redirectOnLogin?: boolean | string) => Promise<void>;
|
|
14
26
|
logout: (redirect?: boolean | RouteLocationRaw) => Promise<void>;
|
|
15
|
-
createUser: (data: RegisterUserInput
|
|
16
|
-
register: (data: RegisterUserInput
|
|
27
|
+
createUser: (data: RegisterUserInput) => Promise<DirectusUser>;
|
|
28
|
+
register: (data: RegisterUserInput) => Promise<DirectusUser>;
|
|
17
29
|
inviteUser: (email: string, role: string, inviteUrl?: string | undefined) => Promise<void>;
|
|
18
30
|
acceptUserInvite: (token: string, password: string) => Promise<void>;
|
|
19
31
|
passwordRequest: (email: string, resetUrl?: string | undefined) => Promise<void>;
|
|
@@ -30,7 +30,8 @@ export function useDirectusAuth() {
|
|
|
30
30
|
}
|
|
31
31
|
loading.value = true;
|
|
32
32
|
try {
|
|
33
|
-
const
|
|
33
|
+
const fields = config.public.directus.auth?.readMeFields;
|
|
34
|
+
const response = await directus.request(directusReadMe(fields?.length ? { fields } : void 0));
|
|
34
35
|
if (!response.id) {
|
|
35
36
|
console.warn("Directus is not configured to return the 'id' field for DirectusUsers.");
|
|
36
37
|
}
|
|
@@ -47,7 +48,8 @@ export function useDirectusAuth() {
|
|
|
47
48
|
const currentUser = user.value;
|
|
48
49
|
if (!currentUser?.id)
|
|
49
50
|
throw new Error("No user available");
|
|
50
|
-
const
|
|
51
|
+
const fields = config.public.directus.auth?.readMeFields;
|
|
52
|
+
const response = await directus.request(directusUpdateMe(data, fields?.length ? { fields } : void 0));
|
|
51
53
|
user.value = response;
|
|
52
54
|
return user.value;
|
|
53
55
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { DirectusFile,
|
|
2
|
-
import type { Query } from '@directus/sdk';
|
|
1
|
+
import type { DirectusFile as DirectusSdkFile, Query } from '@directus/sdk';
|
|
3
2
|
interface DirectusFileUpload {
|
|
4
3
|
file: File;
|
|
5
|
-
data?: Record<keyof DirectusFile, string
|
|
4
|
+
data?: Partial<Record<keyof DirectusFile, string>>;
|
|
6
5
|
}
|
|
7
|
-
export declare function uploadDirectusFile(file: DirectusFileUpload, query?: Query<DirectusSchema, DirectusSchema
|
|
8
|
-
export declare function uploadDirectusFiles(files: DirectusFileUpload[], query?: Query<DirectusSchema, DirectusSchema
|
|
6
|
+
export declare function uploadDirectusFile(file: DirectusFileUpload, query?: Query<DirectusSchema, DirectusSdkFile<DirectusSchema>>): Promise<any>;
|
|
7
|
+
export declare function uploadDirectusFiles(files: DirectusFileUpload[], query?: Query<DirectusSchema, DirectusSdkFile<DirectusSchema>>): Promise<any>;
|
|
9
8
|
export type DirectusThumbnailFormat = 'jpg' | 'png' | 'webp' | 'tiff' | 'avif';
|
|
10
9
|
export type DirectusThumbnailFit = 'cover' | 'contain' | 'inside' | 'outside';
|
|
11
10
|
export interface DirectusFileOptions {
|
|
@@ -2,7 +2,10 @@ import { uploadFiles } from "@directus/sdk";
|
|
|
2
2
|
import { useDirectus, useDirectusUrl } from "./directus.js";
|
|
3
3
|
export async function uploadDirectusFile(file, query) {
|
|
4
4
|
const result = await uploadDirectusFiles([file], query);
|
|
5
|
-
|
|
5
|
+
const uploaded = Array.isArray(result) ? result[0] : result;
|
|
6
|
+
if (!uploaded)
|
|
7
|
+
throw new Error("Upload did not return a file");
|
|
8
|
+
return uploaded;
|
|
6
9
|
}
|
|
7
10
|
export async function uploadDirectusFiles(files, query) {
|
|
8
11
|
const directus = useDirectus();
|
|
@@ -10,7 +13,7 @@ export async function uploadDirectusFiles(files, query) {
|
|
|
10
13
|
files.forEach(({ file, data }) => {
|
|
11
14
|
if (data) {
|
|
12
15
|
Object.entries(data).forEach(([key, value]) => {
|
|
13
|
-
formData.set(key, value);
|
|
16
|
+
if (value !== void 0) formData.set(key, value);
|
|
14
17
|
});
|
|
15
18
|
}
|
|
16
19
|
formData.append("file", file);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AuthenticationStorage } from '@directus/sdk';
|
|
2
2
|
/**
|
|
3
3
|
* Custom storage implementation for Directus SDK on the server
|
|
4
4
|
* Prevents localStorage errors during SSR
|
|
5
5
|
*/
|
|
6
|
-
export declare function useDirectusStorage():
|
|
6
|
+
export declare function useDirectusStorage(): AuthenticationStorage;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export function useDirectusStorage() {
|
|
2
|
-
|
|
2
|
+
let stored = null;
|
|
3
3
|
return {
|
|
4
|
-
get: async (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
set: async (key, value) => {
|
|
8
|
-
storage.set(key, value);
|
|
4
|
+
get: async () => stored,
|
|
5
|
+
set: async (value) => {
|
|
6
|
+
stored = value;
|
|
9
7
|
}
|
|
10
8
|
};
|
|
11
9
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("#app").RouteMiddleware;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("#app").RouteMiddleware;
|
|
2
2
|
export default _default;
|
package/dist/runtime/plugin.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("#app").Plugin<{
|
|
2
2
|
directusVisualEditing: {
|
|
3
3
|
refresh: () => Promise<void>;
|
|
4
4
|
};
|
|
5
|
-
}> & import("
|
|
5
|
+
}> & import("#app").ObjectPlugin<{
|
|
6
6
|
directusVisualEditing: {
|
|
7
7
|
refresh: () => Promise<void>;
|
|
8
8
|
};
|
|
@@ -9,7 +9,7 @@ export function useDirectusUrl(path = "") {
|
|
|
9
9
|
const config = useRuntimeConfig();
|
|
10
10
|
const serverUrl = config.directus?.serverDirectusUrl;
|
|
11
11
|
const fallback = config.public.directus.directusUrl || config.public.directus.url;
|
|
12
|
-
const url = serverUrl || fallback || process.env.DIRECTUS_URL;
|
|
12
|
+
const url = serverUrl || fallback || process.env.DIRECTUS_URL || "";
|
|
13
13
|
return useUrl(url, path);
|
|
14
14
|
}
|
|
15
15
|
export function useTokenDirectus(token) {
|
|
@@ -1,5 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
import type { DirectusFile as SdkDirectusFile } from '@directus/sdk'
|
|
2
|
+
|
|
3
|
+
export {}
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// Fields anchored to the SDK type so renames/removals error at compile time.
|
|
6
|
+
// folder is included as DirectusFolder<object> | string | null — the union covers both
|
|
7
|
+
// expanded queries and the bare UUID string used when passing folder as FormData metadata.
|
|
8
|
+
type SdkFileStringFields = Partial<Pick<SdkDirectusFile<object>,
|
|
9
|
+
| 'title'
|
|
10
|
+
| 'description'
|
|
11
|
+
| 'location'
|
|
12
|
+
| 'type'
|
|
13
|
+
| 'charset'
|
|
14
|
+
| 'storage'
|
|
15
|
+
| 'filename_disk'
|
|
16
|
+
| 'filename_download'
|
|
17
|
+
| 'folder'
|
|
18
|
+
>>
|
|
19
|
+
|
|
20
|
+
declare global {
|
|
21
|
+
interface DirectusFile extends SdkFileStringFields {
|
|
22
|
+
id: string
|
|
23
|
+
}
|
|
24
|
+
interface DirectusUser {
|
|
25
|
+
id: string
|
|
26
|
+
}
|
|
27
|
+
interface DirectusSchema {
|
|
28
|
+
directus_files: DirectusFile
|
|
29
|
+
directus_users: DirectusUser
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { SnapshotCollection, SnapshotField, SnapshotRelation } from '@directus/types';
|
|
2
2
|
import type { TypegenExtension } from './extensions/index.js';
|
|
3
|
-
export declare const FALLBACK_TYPE_STRING = "declare global {\n\ninterface DirectusFile {\n\tid: string;\n}\ninterface DirectusUser {\n\tid: string;\n}\ninterface DirectusSchema { }\n}\n\nexport {};";
|
|
4
3
|
interface RewriteRecord {
|
|
5
4
|
fromCollection: string;
|
|
6
5
|
fromField: string;
|
|
@@ -48,7 +47,7 @@ export interface GenerateTypesOptions {
|
|
|
48
47
|
verbose?: boolean;
|
|
49
48
|
}
|
|
50
49
|
export declare function generateTypesFromDirectus(url: string, token: string, prefix: string, options?: GenerateTypesOptions): Promise<{
|
|
51
|
-
typeString: string;
|
|
50
|
+
typeString: string | null;
|
|
52
51
|
logs: string[];
|
|
53
52
|
}>;
|
|
54
53
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createDirectus, isDirectusError, readCollections, readFields, readRelations, rest, staticToken } from "@directus/sdk";
|
|
2
2
|
import { typegenExtensions } from "./extensions/index.js";
|
|
3
|
-
export const FALLBACK_TYPE_STRING = "declare global {\n\ninterface DirectusFile {\n id: string;\n}\ninterface DirectusUser {\n id: string;\n}\ninterface DirectusSchema { }\n}\n\nexport {};";
|
|
4
3
|
export async function generateTypesFromDirectus(url, token, prefix, options = {}) {
|
|
5
4
|
const logs = [];
|
|
6
5
|
const client = createDirectus(url).with(rest()).with(staticToken(token));
|
|
@@ -26,7 +25,7 @@ export async function generateTypesFromDirectus(url, token, prefix, options = {}
|
|
|
26
25
|
} else {
|
|
27
26
|
logs.push(` - Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
28
27
|
}
|
|
29
|
-
return { typeString:
|
|
28
|
+
return { typeString: null, logs };
|
|
30
29
|
}
|
|
31
30
|
const resolvedOptions = {
|
|
32
31
|
include: options.include ?? [],
|
|
@@ -132,7 +131,7 @@ export function transformSnapshotToTypeString(collections, fields, relations, pr
|
|
|
132
131
|
});
|
|
133
132
|
const customInterfaceBlocks = generatedCollections.map((g) => g.interfaceBlock);
|
|
134
133
|
const directusSchemaBlock = generateDirectusSchemaInterface(allCollectionsForSchema, prefix, singletonCollectionNames);
|
|
135
|
-
const allCollectionNames = allCollectionsForSchema.map((c) => c.collection);
|
|
134
|
+
const allCollectionNames = allCollectionsForSchema.filter((c) => !collectionIsDirectusSystem(c.collection)).map((c) => c.collection);
|
|
136
135
|
const enumBlock = generateCollectionNamesEnum(allCollectionNames, prefix);
|
|
137
136
|
const bodyParts = [
|
|
138
137
|
...uniqueExtensionOutputs,
|
|
@@ -305,8 +304,9 @@ ${fieldLines.join("\n")}
|
|
|
305
304
|
function generateDirectusSchemaInterface(allCollections, prefix, singletons = /* @__PURE__ */ new Set()) {
|
|
306
305
|
const entries = allCollections.map((collection) => {
|
|
307
306
|
const isSingleton = collection.meta?.singleton === true;
|
|
307
|
+
const isDirectusSystemCollection = collectionIsDirectusSystem(collection.collection);
|
|
308
308
|
const interfaceName = collectionNameToInterfaceName(collection.collection, prefix, singletons);
|
|
309
|
-
const valueType = isSingleton ? interfaceName : `${interfaceName}[]`;
|
|
309
|
+
const valueType = isSingleton || isDirectusSystemCollection ? interfaceName : `${interfaceName}[]`;
|
|
310
310
|
return ` ${collection.collection}: ${valueType};`;
|
|
311
311
|
});
|
|
312
312
|
return `interface DirectusSchema {
|
|
@@ -354,7 +354,7 @@ function determineFieldType(field) {
|
|
|
354
354
|
);
|
|
355
355
|
const unionOfChoices = [...new Set(choiceValues)].join(" | ");
|
|
356
356
|
const interfacesWithMultiSelect = ["select-multiple", "select-multiple-dropdown", "select-multiple-checkbox"];
|
|
357
|
-
if (interfacesWithMultiSelect.includes(field.meta.interface)) {
|
|
357
|
+
if (interfacesWithMultiSelect.includes(field.meta.interface ?? "")) {
|
|
358
358
|
return `Array<${unionOfChoices}>`;
|
|
359
359
|
}
|
|
360
360
|
return unionOfChoices;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { generateTypesFromDirectus } from './generate.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { generateTypesFromDirectus } from "./generate.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export {}
|
|
2
2
|
|
|
3
3
|
declare module '#app' {
|
|
4
4
|
interface RuntimeNuxtHooks {
|
|
5
|
-
'directus:loggedIn': (user:
|
|
5
|
+
'directus:loggedIn': (user: DirectusUser | null) => void
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
interface NuxtApp {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Slot } from './slot.js';
|
|
2
2
|
export declare function useUrl(base: string, ...paths: string[]): string;
|
|
3
|
-
export declare function isQueryParamEnabled(value:
|
|
3
|
+
export declare function isQueryParamEnabled(value: unknown): value is true | 1 | "true" | "1";
|
|
@@ -138,17 +138,15 @@ function loadRulesFromPayload(payload) {
|
|
|
138
138
|
}
|
|
139
139
|
permissionsByPolicy.get(key).push(perm);
|
|
140
140
|
}
|
|
141
|
+
const policyById = /* @__PURE__ */ new Map();
|
|
141
142
|
const policies = payload.policies.map((policy) => {
|
|
142
143
|
const policyPerms = permissionsByPolicy.get(policy.id ?? null) ?? [];
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
for (let i = 0; i < payload.policies.length; i++) {
|
|
147
|
-
const apiPolicy = payload.policies[i];
|
|
148
|
-
if (apiPolicy.id) {
|
|
149
|
-
policyById.set(apiPolicy.id, policies[i]);
|
|
144
|
+
const converted = convertPayloadPolicy(policy, policyPerms);
|
|
145
|
+
if (policy.id) {
|
|
146
|
+
policyById.set(policy.id, converted);
|
|
150
147
|
}
|
|
151
|
-
|
|
148
|
+
return converted;
|
|
149
|
+
});
|
|
152
150
|
const roles = payload.roles.map((role) => {
|
|
153
151
|
const rolePolicies = [];
|
|
154
152
|
if (role.policies) {
|
|
@@ -215,8 +213,8 @@ function convertPayloadPermission(perm) {
|
|
|
215
213
|
}
|
|
216
214
|
return {
|
|
217
215
|
fields: perm.fields ? perm.fields.includes("*") ? "*" : perm.fields : void 0,
|
|
218
|
-
filter: perm.permissions,
|
|
219
|
-
presets: perm.presets,
|
|
216
|
+
filter: perm.permissions ?? void 0,
|
|
217
|
+
presets: perm.presets ?? void 0,
|
|
220
218
|
validation: perm.validation ?? void 0
|
|
221
219
|
};
|
|
222
220
|
}
|
|
@@ -740,11 +738,13 @@ function formatAddedFields(lines, item, excludeKeys) {
|
|
|
740
738
|
}
|
|
741
739
|
function formatModifiedFields(lines, local, remote, excludeKeys) {
|
|
742
740
|
const allKeys = /* @__PURE__ */ new Set([...Object.keys(local), ...Object.keys(remote)]);
|
|
741
|
+
const localRec = local;
|
|
742
|
+
const remoteRec = remote;
|
|
743
743
|
for (const key of allKeys) {
|
|
744
744
|
if (excludeKeys.includes(key))
|
|
745
745
|
continue;
|
|
746
|
-
const localVal =
|
|
747
|
-
const remoteVal =
|
|
746
|
+
const localVal = localRec[key];
|
|
747
|
+
const remoteVal = remoteRec[key];
|
|
748
748
|
if (!valuesEqual(localVal, remoteVal)) {
|
|
749
749
|
lines.push(` ${key}:`);
|
|
750
750
|
lines.push(` - ${formatValue(remoteVal)}`);
|
|
@@ -1105,13 +1105,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1105
1105
|
}
|
|
1106
1106
|
const policyIdMap = /* @__PURE__ */ new Map();
|
|
1107
1107
|
const policiesToCreate = diff.policies.filter((p) => p.type === "added");
|
|
1108
|
-
for (
|
|
1109
|
-
const change = policiesToCreate[i];
|
|
1108
|
+
for (const [idx, change] of policiesToCreate.entries()) {
|
|
1110
1109
|
onProgress?.({
|
|
1111
1110
|
phase: "policies",
|
|
1112
1111
|
action: "create",
|
|
1113
1112
|
name: change.name,
|
|
1114
|
-
current:
|
|
1113
|
+
current: idx + 1,
|
|
1115
1114
|
total: policiesToCreate.length
|
|
1116
1115
|
});
|
|
1117
1116
|
try {
|
|
@@ -1142,13 +1141,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1142
1141
|
}
|
|
1143
1142
|
if (!addOnly) {
|
|
1144
1143
|
const policiesToUpdate = diff.policies.filter((p) => p.type === "modified");
|
|
1145
|
-
for (
|
|
1146
|
-
const change = policiesToUpdate[i];
|
|
1144
|
+
for (const [idx, change] of policiesToUpdate.entries()) {
|
|
1147
1145
|
onProgress?.({
|
|
1148
1146
|
phase: "policies",
|
|
1149
1147
|
action: "update",
|
|
1150
1148
|
name: change.name,
|
|
1151
|
-
current:
|
|
1149
|
+
current: idx + 1,
|
|
1152
1150
|
total: policiesToUpdate.length
|
|
1153
1151
|
});
|
|
1154
1152
|
try {
|
|
@@ -1184,13 +1182,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1184
1182
|
}
|
|
1185
1183
|
}
|
|
1186
1184
|
const rolesToCreate = diff.roles.filter((r) => r.type === "added");
|
|
1187
|
-
for (
|
|
1188
|
-
const change = rolesToCreate[i];
|
|
1185
|
+
for (const [idx, change] of rolesToCreate.entries()) {
|
|
1189
1186
|
onProgress?.({
|
|
1190
1187
|
phase: "roles",
|
|
1191
1188
|
action: "create",
|
|
1192
1189
|
name: change.name,
|
|
1193
|
-
current:
|
|
1190
|
+
current: idx + 1,
|
|
1194
1191
|
total: rolesToCreate.length
|
|
1195
1192
|
});
|
|
1196
1193
|
try {
|
|
@@ -1218,13 +1215,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1218
1215
|
}
|
|
1219
1216
|
if (!addOnly) {
|
|
1220
1217
|
const rolesToUpdate = diff.roles.filter((r) => r.type === "modified");
|
|
1221
|
-
for (
|
|
1222
|
-
const change = rolesToUpdate[i];
|
|
1218
|
+
for (const [idx, change] of rolesToUpdate.entries()) {
|
|
1223
1219
|
onProgress?.({
|
|
1224
1220
|
phase: "roles",
|
|
1225
1221
|
action: "update",
|
|
1226
1222
|
name: change.name,
|
|
1227
|
-
current:
|
|
1223
|
+
current: idx + 1,
|
|
1228
1224
|
total: rolesToUpdate.length
|
|
1229
1225
|
});
|
|
1230
1226
|
try {
|
|
@@ -1253,13 +1249,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1253
1249
|
}
|
|
1254
1250
|
}
|
|
1255
1251
|
const permsToCreate = diff.permissions.filter((p) => p.type === "added");
|
|
1256
|
-
for (
|
|
1257
|
-
const change = permsToCreate[i];
|
|
1252
|
+
for (const [idx, change] of permsToCreate.entries()) {
|
|
1258
1253
|
onProgress?.({
|
|
1259
1254
|
phase: "permissions",
|
|
1260
1255
|
action: "create",
|
|
1261
1256
|
name: change.name,
|
|
1262
|
-
current:
|
|
1257
|
+
current: idx + 1,
|
|
1263
1258
|
total: permsToCreate.length
|
|
1264
1259
|
});
|
|
1265
1260
|
try {
|
|
@@ -1288,13 +1283,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1288
1283
|
}
|
|
1289
1284
|
if (!addOnly) {
|
|
1290
1285
|
const permsToUpdate = diff.permissions.filter((p) => p.type === "modified");
|
|
1291
|
-
for (
|
|
1292
|
-
const change = permsToUpdate[i];
|
|
1286
|
+
for (const [idx, change] of permsToUpdate.entries()) {
|
|
1293
1287
|
onProgress?.({
|
|
1294
1288
|
phase: "permissions",
|
|
1295
1289
|
action: "update",
|
|
1296
1290
|
name: change.name,
|
|
1297
|
-
current:
|
|
1291
|
+
current: idx + 1,
|
|
1298
1292
|
total: permsToUpdate.length
|
|
1299
1293
|
});
|
|
1300
1294
|
try {
|
|
@@ -1320,13 +1314,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1320
1314
|
}
|
|
1321
1315
|
if (!skipDeletes && !addOnly) {
|
|
1322
1316
|
const permsToDelete = diff.permissions.filter((p) => p.type === "removed");
|
|
1323
|
-
for (
|
|
1324
|
-
const change = permsToDelete[i];
|
|
1317
|
+
for (const [idx, change] of permsToDelete.entries()) {
|
|
1325
1318
|
onProgress?.({
|
|
1326
1319
|
phase: "permissions",
|
|
1327
1320
|
action: "delete",
|
|
1328
1321
|
name: change.name,
|
|
1329
|
-
current:
|
|
1322
|
+
current: idx + 1,
|
|
1330
1323
|
total: permsToDelete.length
|
|
1331
1324
|
});
|
|
1332
1325
|
try {
|
|
@@ -1342,13 +1335,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1342
1335
|
}
|
|
1343
1336
|
}
|
|
1344
1337
|
const rolesToDelete = diff.roles.filter((r) => r.type === "removed");
|
|
1345
|
-
for (
|
|
1346
|
-
const change = rolesToDelete[i];
|
|
1338
|
+
for (const [idx, change] of rolesToDelete.entries()) {
|
|
1347
1339
|
onProgress?.({
|
|
1348
1340
|
phase: "roles",
|
|
1349
1341
|
action: "delete",
|
|
1350
1342
|
name: change.name,
|
|
1351
|
-
current:
|
|
1343
|
+
current: idx + 1,
|
|
1352
1344
|
total: rolesToDelete.length
|
|
1353
1345
|
});
|
|
1354
1346
|
try {
|
|
@@ -1364,13 +1356,12 @@ async function pushRules(client, localRules, options = {}) {
|
|
|
1364
1356
|
}
|
|
1365
1357
|
}
|
|
1366
1358
|
const policiesToDelete = diff.policies.filter((p) => p.type === "removed");
|
|
1367
|
-
for (
|
|
1368
|
-
const change = policiesToDelete[i];
|
|
1359
|
+
for (const [idx, change] of policiesToDelete.entries()) {
|
|
1369
1360
|
onProgress?.({
|
|
1370
1361
|
phase: "policies",
|
|
1371
1362
|
action: "delete",
|
|
1372
1363
|
name: change.name,
|
|
1373
|
-
current:
|
|
1364
|
+
current: idx + 1,
|
|
1374
1365
|
total: policiesToDelete.length
|
|
1375
1366
|
});
|
|
1376
1367
|
try {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-directus-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.0.0-beta.
|
|
4
|
+
"version": "6.0.0-beta.3",
|
|
5
5
|
"packageManager": "pnpm@10.32.1",
|
|
6
6
|
"description": "A Nuxt module for Directus with built-in authentication, realtime, file management, type generation, and visual editor support.",
|
|
7
7
|
"author": "Matthew Rollinson <matt@rolley.io>",
|
|
8
8
|
"license": "MIT",
|
|
9
|
-
"homepage": "https://nuxt-directus-sdk.
|
|
9
|
+
"homepage": "https://www.nuxt-directus-sdk.com",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/rolleyio/nuxt-directus-sdk"
|
|
@@ -84,28 +84,31 @@
|
|
|
84
84
|
"ufo": "^1.6.3"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@antfu/eslint-config": "^4.10.0",
|
|
88
87
|
"@directus/sdk": "^21.2.2",
|
|
89
88
|
"@directus/types": "^15.0.2",
|
|
90
89
|
"@directus/visual-editing": "^2.0.0",
|
|
91
90
|
"@nuxt/devtools": "^3.2.4",
|
|
91
|
+
"@nuxt/eslint-config": "^1.15.2",
|
|
92
92
|
"@nuxt/image": "^2.0.0",
|
|
93
93
|
"@nuxt/module-builder": "^1.0.2",
|
|
94
94
|
"@nuxt/schema": "^4.4.2",
|
|
95
95
|
"@nuxt/test-utils": "^4.0.2",
|
|
96
96
|
"@types/http-proxy": "^1.17.17",
|
|
97
97
|
"changelogen": "^0.6.1",
|
|
98
|
-
"eslint": "^
|
|
98
|
+
"eslint": "^10.2.1",
|
|
99
99
|
"nuxt": "^4.4.2",
|
|
100
100
|
"typescript": "^6.0.3",
|
|
101
101
|
"vitepress": "^1.6.4",
|
|
102
102
|
"vitest": "^4.1.4",
|
|
103
|
-
"vue-tsc": "^3.
|
|
103
|
+
"vue-tsc": "^3.2.7"
|
|
104
104
|
},
|
|
105
105
|
"unbuild": {
|
|
106
106
|
"failOnWarn": false,
|
|
107
107
|
"externals": [
|
|
108
108
|
"consola/utils"
|
|
109
109
|
]
|
|
110
|
+
},
|
|
111
|
+
"engines": {
|
|
112
|
+
"node": ">=22.0.0"
|
|
110
113
|
}
|
|
111
114
|
}
|