@directus/api 32.1.0 → 32.2.0
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/ai/chat/constants/system-prompt.d.ts +1 -0
- package/dist/ai/chat/constants/system-prompt.js +51 -0
- package/dist/ai/chat/controllers/chat.post.d.ts +2 -0
- package/dist/ai/chat/controllers/chat.post.js +47 -0
- package/dist/ai/chat/lib/create-ui-stream.d.ts +15 -0
- package/dist/ai/chat/lib/create-ui-stream.js +42 -0
- package/dist/ai/chat/middleware/load-settings.d.ts +2 -0
- package/dist/ai/chat/middleware/load-settings.js +18 -0
- package/dist/ai/chat/models/chat-request.d.ts +34 -0
- package/dist/ai/chat/models/chat-request.js +26 -0
- package/dist/ai/chat/models/providers.d.ts +9 -0
- package/dist/ai/chat/models/providers.js +9 -0
- package/dist/ai/chat/router.d.ts +1 -0
- package/dist/ai/chat/router.js +5 -0
- package/dist/ai/chat/utils/chat-request-tool-to-ai-sdk-tool.d.ts +9 -0
- package/dist/ai/chat/utils/chat-request-tool-to-ai-sdk-tool.js +38 -0
- package/dist/ai/chat/utils/fix-error-tool-calls.d.ts +12 -0
- package/dist/ai/chat/utils/fix-error-tool-calls.js +30 -0
- package/dist/ai/chat/utils/parse-json-schema-7.d.ts +13 -0
- package/dist/ai/chat/utils/parse-json-schema-7.js +75 -0
- package/dist/{mcp → ai/mcp}/server.d.ts +13 -16
- package/dist/{mcp → ai/mcp}/server.js +4 -13
- package/dist/ai/mcp/types.d.ts +15 -0
- package/dist/{mcp/tools/assets.js → ai/tools/assets/index.js} +8 -5
- package/dist/{mcp/tools/collections.js → ai/tools/collections/index.js} +7 -4
- package/dist/{mcp/tools/fields.js → ai/tools/fields/index.js} +12 -9
- package/dist/{mcp/tools/files.js → ai/tools/files/index.js} +11 -5
- package/dist/{mcp/tools/flows.js → ai/tools/flows/index.js} +11 -5
- package/dist/{mcp/tools/folders.js → ai/tools/folders/index.js} +12 -5
- package/dist/ai/tools/index.d.ts +15 -0
- package/dist/ai/tools/index.js +29 -0
- package/dist/{mcp/tools/items.js → ai/tools/items/index.js} +13 -6
- package/dist/{mcp/tools/prompts/items.md → ai/tools/items/prompt.md} +19 -15
- package/dist/{mcp/tools/operations.d.ts → ai/tools/operations/index.d.ts} +46 -0
- package/dist/{mcp/tools/operations.js → ai/tools/operations/index.js} +12 -5
- package/dist/{mcp/tools/relations.js → ai/tools/relations/index.js} +7 -4
- package/dist/{mcp/tools/schema.d.ts → ai/tools/schema/index.d.ts} +1 -1
- package/dist/{mcp/tools/schema.js → ai/tools/schema/index.js} +9 -6
- package/dist/{mcp/tools/system.js → ai/tools/system/index.js} +7 -4
- package/dist/{mcp/tools/trigger-flow.js → ai/tools/trigger-flow/index.js} +8 -5
- package/dist/{mcp → ai/tools}/types.d.ts +1 -17
- package/dist/ai/tools/utils.d.ts +9 -0
- package/dist/ai/tools/utils.js +17 -0
- package/dist/app.js +5 -0
- package/dist/auth/drivers/oauth2.d.ts +2 -1
- package/dist/auth/drivers/oauth2.js +17 -22
- package/dist/auth/drivers/openid.d.ts +2 -1
- package/dist/auth/drivers/openid.js +13 -18
- package/dist/auth/drivers/saml.js +6 -3
- package/dist/controllers/assets.js +39 -2
- package/dist/controllers/mcp.js +1 -1
- package/dist/database/migrations/20240806A-permissions-policies.js +2 -2
- package/dist/database/migrations/20251103A-add-ai-settings.d.ts +3 -0
- package/dist/database/migrations/20251103A-add-ai-settings.js +14 -0
- package/dist/database/run-ast/run-ast.js +1 -1
- package/dist/extensions/lib/installation/manager.js +5 -9
- package/dist/extensions/lib/sync/status.d.ts +11 -0
- package/dist/extensions/lib/sync/status.js +34 -0
- package/dist/extensions/lib/sync/sync.d.ts +6 -0
- package/dist/extensions/lib/sync/sync.js +90 -0
- package/dist/extensions/lib/sync/tracker.d.ts +18 -0
- package/dist/extensions/lib/sync/tracker.js +71 -0
- package/dist/extensions/lib/sync/utils.d.ts +24 -0
- package/dist/extensions/lib/sync/utils.js +62 -0
- package/dist/extensions/manager.d.ts +8 -4
- package/dist/extensions/manager.js +30 -13
- package/dist/middleware/respond.js +2 -2
- package/dist/permissions/lib/fetch-policies.d.ts +1 -1
- package/dist/permissions/lib/fetch-roles-tree.d.ts +6 -3
- package/dist/permissions/lib/fetch-roles-tree.js +5 -27
- package/dist/permissions/modules/fetch-global-access/fetch-global-access.d.ts +9 -7
- package/dist/permissions/modules/fetch-global-access/fetch-global-access.js +17 -9
- package/dist/permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.d.ts +1 -1
- package/dist/permissions/utils/fetch-raw-permissions.d.ts +1 -1
- package/dist/permissions/utils/fetch-share-info.d.ts +1 -1
- package/dist/permissions/utils/fetch-share-info.js +1 -1
- package/dist/permissions/utils/filter-policies-by-ip.js +1 -1
- package/dist/permissions/utils/get-permissions-for-share.js +8 -8
- package/dist/permissions/utils/with-cache.d.ts +8 -6
- package/dist/permissions/utils/with-cache.js +12 -10
- package/dist/request/is-denied-ip.js +2 -2
- package/dist/services/assets/name-deduper.d.ts +7 -0
- package/dist/services/assets/name-deduper.js +23 -0
- package/dist/services/assets.d.ts +15 -2
- package/dist/services/assets.js +98 -5
- package/dist/services/authentication.js +4 -4
- package/dist/services/comments.js +2 -2
- package/dist/services/extensions.js +4 -0
- package/dist/services/folders.d.ts +27 -2
- package/dist/services/folders.js +75 -0
- package/dist/services/graphql/resolvers/query.js +1 -1
- package/dist/services/import-export.d.ts +1 -1
- package/dist/services/import-export.js +4 -5
- package/dist/services/notifications.js +2 -2
- package/dist/services/payload.js +20 -0
- package/dist/services/roles.js +2 -2
- package/dist/services/tus/server.js +3 -3
- package/dist/telemetry/utils/get-settings.d.ts +15 -0
- package/dist/telemetry/utils/get-settings.js +25 -9
- package/dist/test-utils/README.md +95 -24
- package/dist/test-utils/cache.d.ts +2 -2
- package/dist/test-utils/cache.js +2 -2
- package/dist/test-utils/{fields-service.d.ts → services/fields-service.d.ts} +1 -1
- package/dist/test-utils/{fields-service.js → services/fields-service.js} +3 -2
- package/dist/test-utils/services/files-service.d.ts +28 -0
- package/dist/test-utils/services/files-service.js +34 -0
- package/dist/test-utils/services/folders-service.d.ts +28 -0
- package/dist/test-utils/services/folders-service.js +33 -0
- package/dist/utils/encrypt.d.ts +2 -0
- package/dist/utils/encrypt.js +64 -0
- package/dist/utils/get-accountability-for-role.js +2 -2
- package/dist/utils/get-accountability-for-token.js +4 -4
- package/dist/utils/get-cache-key.js +2 -2
- package/dist/utils/is-login-redirect-allowed.d.ts +4 -0
- package/dist/{auth/utils → utils}/is-login-redirect-allowed.js +8 -16
- package/dist/utils/require-text.d.ts +1 -0
- package/dist/utils/require-text.js +4 -0
- package/dist/utils/require-yaml.js +2 -2
- package/package.json +31 -25
- package/dist/auth/utils/generate-callback-url.d.ts +0 -8
- package/dist/auth/utils/generate-callback-url.js +0 -11
- package/dist/auth/utils/is-login-redirect-allowed.d.ts +0 -8
- package/dist/extensions/lib/sync-extensions.d.ts +0 -3
- package/dist/extensions/lib/sync-extensions.js +0 -70
- package/dist/extensions/lib/sync-status.d.ts +0 -10
- package/dist/extensions/lib/sync-status.js +0 -27
- package/dist/mcp/tools/index.d.ts +0 -15
- package/dist/mcp/tools/index.js +0 -29
- package/dist/mcp/tools/prompts/index.d.ts +0 -16
- package/dist/mcp/tools/prompts/index.js +0 -19
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.d.ts +0 -5
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.js +0 -7
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.d.ts +0 -5
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.js +0 -10
- package/dist/permissions/modules/fetch-global-access/types.d.ts +0 -4
- package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.d.ts +0 -4
- package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.js +0 -27
- package/dist/utils/get-date-formatted.d.ts +0 -1
- package/dist/utils/get-date-formatted.js +0 -10
- package/dist/utils/ip-in-networks.d.ts +0 -6
- package/dist/utils/ip-in-networks.js +0 -13
- /package/dist/{mcp → ai/mcp}/index.d.ts +0 -0
- /package/dist/{mcp → ai/mcp}/index.js +0 -0
- /package/dist/{mcp → ai/mcp}/transport.d.ts +0 -0
- /package/dist/{mcp → ai/mcp}/transport.js +0 -0
- /package/dist/{mcp → ai/mcp}/types.js +0 -0
- /package/dist/{mcp/tools/assets.d.ts → ai/tools/assets/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/assets.md → ai/tools/assets/prompt.md} +0 -0
- /package/dist/{mcp/tools/collections.d.ts → ai/tools/collections/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/collections.md → ai/tools/collections/prompt.md} +0 -0
- /package/dist/{mcp/define.d.ts → ai/tools/define-tool.d.ts} +0 -0
- /package/dist/{mcp/define.js → ai/tools/define-tool.js} +0 -0
- /package/dist/{mcp/tools/fields.d.ts → ai/tools/fields/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/fields.md → ai/tools/fields/prompt.md} +0 -0
- /package/dist/{mcp/tools/files.d.ts → ai/tools/files/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/files.md → ai/tools/files/prompt.md} +0 -0
- /package/dist/{mcp/tools/flows.d.ts → ai/tools/flows/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/flows.md → ai/tools/flows/prompt.md} +0 -0
- /package/dist/{mcp/tools/folders.d.ts → ai/tools/folders/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/folders.md → ai/tools/folders/prompt.md} +0 -0
- /package/dist/{mcp/tools/items.d.ts → ai/tools/items/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/operations.md → ai/tools/operations/prompt.md} +0 -0
- /package/dist/{mcp/tools/relations.d.ts → ai/tools/relations/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/relations.md → ai/tools/relations/prompt.md} +0 -0
- /package/dist/{mcp/tools/prompts/schema.md → ai/tools/schema/prompt.md} +0 -0
- /package/dist/{mcp → ai/tools}/schema.d.ts +0 -0
- /package/dist/{mcp → ai/tools}/schema.js +0 -0
- /package/dist/{mcp/tools/system.d.ts → ai/tools/system/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/system-prompt-description.md → ai/tools/system/prompt-description.md} +0 -0
- /package/dist/{mcp/tools/prompts/system-prompt.md → ai/tools/system/prompt.md} +0 -0
- /package/dist/{mcp/tools/trigger-flow.d.ts → ai/tools/trigger-flow/index.d.ts} +0 -0
- /package/dist/{mcp/tools/prompts/trigger-flow.md → ai/tools/trigger-flow/prompt.md} +0 -0
- /package/dist/{permissions/modules/fetch-global-access → ai/tools}/types.js +0 -0
- /package/dist/test-utils/{items-service.d.ts → services/items-service.d.ts} +0 -0
- /package/dist/test-utils/{items-service.js → services/items-service.js} +0 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import Queue from 'p-queue';
|
|
2
|
+
import mid from 'node-machine-id';
|
|
3
|
+
import { useEnv } from '@directus/env';
|
|
4
|
+
import { createWriteStream } from 'node:fs';
|
|
5
|
+
import { mkdir, rm } from 'node:fs/promises';
|
|
6
|
+
import { pipeline } from 'node:stream/promises';
|
|
7
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
8
|
+
import { getSyncPaths, compareFileMetadata } from './utils.js';
|
|
9
|
+
import { useBus } from '../../../bus/index.js';
|
|
10
|
+
import { SyncFileTracker } from './tracker.js';
|
|
11
|
+
import { useLock } from '../../../lock/index.js';
|
|
12
|
+
import { useLogger } from '../../../logger/index.js';
|
|
13
|
+
import { getStorage } from '../../../storage/index.js';
|
|
14
|
+
import { getExtensionsPath } from '../get-extensions-path.js';
|
|
15
|
+
import { isSynchronizing, setSyncStatus, SyncStatus } from './status.js';
|
|
16
|
+
import { normalizePath } from '@directus/utils';
|
|
17
|
+
export async function syncExtensions(options) {
|
|
18
|
+
if (options?.skipSync === true)
|
|
19
|
+
return;
|
|
20
|
+
const env = useEnv();
|
|
21
|
+
const lock = useLock();
|
|
22
|
+
const messenger = useBus();
|
|
23
|
+
const logger = useLogger();
|
|
24
|
+
if (options?.forceSync !== true && (await isSynchronizing())) {
|
|
25
|
+
logger.debug('Extensions are already being synced to this directory from another process.');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const machineId = await mid.machineId();
|
|
29
|
+
const machineKey = `extensions-sync/${machineId}`;
|
|
30
|
+
const processId = await lock.increment(machineKey);
|
|
31
|
+
if (processId !== 1) {
|
|
32
|
+
logger.debug('Extensions are already being synced to this machine from another process.');
|
|
33
|
+
// Wait until the process that called the lock publishes a message that the syncing is complete
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
messenger.subscribe(machineKey, () => resolve());
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
logger.debug('Syncing extensions from configured storage location...');
|
|
40
|
+
// Ensure that the local extensions cache path exists
|
|
41
|
+
await mkdir(getExtensionsPath(), { recursive: true });
|
|
42
|
+
await setSyncStatus(SyncStatus.SYNCING);
|
|
43
|
+
const { localExtensionsPath, remoteExtensionsPath } = getSyncPaths(options?.partialSync);
|
|
44
|
+
const storage = await getStorage();
|
|
45
|
+
const disk = storage.location(env['EXTENSIONS_LOCATION']);
|
|
46
|
+
// check if we are only removing the local directory
|
|
47
|
+
if (options?.partialSync) {
|
|
48
|
+
const remoteExists = await disk.exists(normalizePath(join(remoteExtensionsPath, 'package.json')));
|
|
49
|
+
if (remoteExists === false) {
|
|
50
|
+
await rm(localExtensionsPath, { recursive: true, force: true });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Make sure we don't overload the file handles
|
|
55
|
+
const queue = new Queue({ concurrency: 1000 });
|
|
56
|
+
// start file tracker
|
|
57
|
+
const fileTracker = new SyncFileTracker();
|
|
58
|
+
const localFileCount = await fileTracker.readLocalFiles(localExtensionsPath);
|
|
59
|
+
const hasLocalFiles = localFileCount > 0;
|
|
60
|
+
for await (const filepath of disk.list(remoteExtensionsPath)) {
|
|
61
|
+
// We want files to be stored in the root of `$TEMP_PATH/extensions`, so gotta remove the
|
|
62
|
+
// extensions path on disk from the start of the file path
|
|
63
|
+
const relativePath = relative(resolve(sep, remoteExtensionsPath), resolve(sep, filepath));
|
|
64
|
+
const destinationPath = join(localExtensionsPath, relativePath);
|
|
65
|
+
await fileTracker.passedFile(relativePath);
|
|
66
|
+
// No need to check metadata when force is enabled
|
|
67
|
+
if (options?.forceSync !== true && hasLocalFiles) {
|
|
68
|
+
const fileUnchanged = await compareFileMetadata(destinationPath, filepath, disk);
|
|
69
|
+
if (fileUnchanged)
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// Ensure that the directory path exists
|
|
73
|
+
await mkdir(dirname(destinationPath), { recursive: true });
|
|
74
|
+
// write remote file to the local filesystem
|
|
75
|
+
const readStream = await disk.read(filepath);
|
|
76
|
+
const writeStream = createWriteStream(destinationPath);
|
|
77
|
+
queue.add(() => pipeline(readStream, writeStream));
|
|
78
|
+
}
|
|
79
|
+
// wait for the queue to finish
|
|
80
|
+
await queue.onIdle();
|
|
81
|
+
// cleanup dangling local files
|
|
82
|
+
await fileTracker.cleanup(localExtensionsPath);
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
// release various locking mechanisms
|
|
86
|
+
messenger.publish(machineKey, { ready: true });
|
|
87
|
+
await lock.delete(machineKey);
|
|
88
|
+
await setSyncStatus(SyncStatus.IDLE);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class SyncFileTracker {
|
|
2
|
+
private localFiles;
|
|
3
|
+
private trackedDirs;
|
|
4
|
+
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* Reads all files recusrively in the provided directory
|
|
7
|
+
* @returns the number of files read
|
|
8
|
+
*/
|
|
9
|
+
readLocalFiles(localExtensionsPath: string): Promise<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Removes a file from the locally tracked files
|
|
12
|
+
*/
|
|
13
|
+
passedFile(filePath: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Removes left over tracked files that were not processed
|
|
16
|
+
*/
|
|
17
|
+
cleanup(localExtensionsPath: string): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* class to help tracking file status between local and remote
|
|
3
|
+
*/
|
|
4
|
+
import { readdir, rm } from 'node:fs/promises';
|
|
5
|
+
import { dirname, join, relative } from 'node:path';
|
|
6
|
+
import { pathDepth } from './utils.js';
|
|
7
|
+
export class SyncFileTracker {
|
|
8
|
+
localFiles;
|
|
9
|
+
trackedDirs;
|
|
10
|
+
constructor() {
|
|
11
|
+
this.localFiles = new Set();
|
|
12
|
+
this.trackedDirs = new Set();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reads all files recusrively in the provided directory
|
|
16
|
+
* @returns the number of files read
|
|
17
|
+
*/
|
|
18
|
+
async readLocalFiles(localExtensionsPath) {
|
|
19
|
+
const entries = await readdir(localExtensionsPath, { recursive: true, withFileTypes: true }).catch(() => {
|
|
20
|
+
/* path doesnt exist */
|
|
21
|
+
});
|
|
22
|
+
if (!entries)
|
|
23
|
+
return 0;
|
|
24
|
+
for (const entry of entries) {
|
|
25
|
+
if (!entry.isFile())
|
|
26
|
+
continue;
|
|
27
|
+
const relativePath = join(relative(localExtensionsPath, entry.parentPath), entry.name);
|
|
28
|
+
this.localFiles.add(relativePath);
|
|
29
|
+
}
|
|
30
|
+
return this.localFiles.size;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Removes a file from the locally tracked files
|
|
34
|
+
*/
|
|
35
|
+
async passedFile(filePath) {
|
|
36
|
+
this.localFiles.delete(filePath);
|
|
37
|
+
let currentDir = dirname(filePath);
|
|
38
|
+
while (currentDir !== '.') {
|
|
39
|
+
if (this.trackedDirs.has(currentDir))
|
|
40
|
+
break;
|
|
41
|
+
this.trackedDirs.add(currentDir);
|
|
42
|
+
currentDir = dirname(currentDir);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Removes left over tracked files that were not processed
|
|
47
|
+
*/
|
|
48
|
+
async cleanup(localExtensionsPath) {
|
|
49
|
+
const removeDirs = new Set();
|
|
50
|
+
for (const removeFile of this.localFiles) {
|
|
51
|
+
if (removeFile === '.status')
|
|
52
|
+
continue;
|
|
53
|
+
let currentDir = dirname(removeFile);
|
|
54
|
+
while (currentDir !== localExtensionsPath && currentDir !== '.') {
|
|
55
|
+
if (this.trackedDirs.has(currentDir))
|
|
56
|
+
break;
|
|
57
|
+
removeDirs.add(currentDir);
|
|
58
|
+
currentDir = dirname(currentDir);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// sort directory by depth so we can remove the highest level directory recursively
|
|
62
|
+
const removeDirsRecursive = Array.from(removeDirs)
|
|
63
|
+
.sort((a, b) => pathDepth(b) - pathDepth(a))
|
|
64
|
+
.filter((d) => !removeDirs.has(dirname(d)));
|
|
65
|
+
for (const dir of removeDirsRecursive) {
|
|
66
|
+
const relativePath = join(localExtensionsPath, dir);
|
|
67
|
+
// removing local folder that does not exist in the remote storage
|
|
68
|
+
await rm(relativePath, { recursive: true, force: true });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Driver } from '@directus/storage';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the directory depth of the provided path
|
|
4
|
+
*/
|
|
5
|
+
export declare function pathDepth(path: string): number;
|
|
6
|
+
/**
|
|
7
|
+
* Reads the size and modified date of a file if it exists
|
|
8
|
+
*/
|
|
9
|
+
export declare function fsStat(path: string): Promise<{
|
|
10
|
+
size: number;
|
|
11
|
+
modified: Date;
|
|
12
|
+
} | null>;
|
|
13
|
+
/**
|
|
14
|
+
* Builds up the local and remote paths to use with syncing
|
|
15
|
+
*/
|
|
16
|
+
export declare function getSyncPaths(partialPath: string | undefined): {
|
|
17
|
+
localExtensionsPath: string;
|
|
18
|
+
remoteExtensionsPath: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Retrieve the stats for local and remote files and check if they are the same
|
|
22
|
+
* Returns false if files are differnt else true
|
|
23
|
+
*/
|
|
24
|
+
export declare function compareFileMetadata(localPath: string, remotePath: string, disk: Driver): Promise<boolean>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
2
|
+
import { stat } from 'node:fs/promises';
|
|
3
|
+
import { getExtensionsPath } from '../get-extensions-path.js';
|
|
4
|
+
import { useEnv } from '@directus/env';
|
|
5
|
+
import { normalizePath } from '@directus/utils';
|
|
6
|
+
/**
|
|
7
|
+
* Returns the directory depth of the provided path
|
|
8
|
+
*/
|
|
9
|
+
export function pathDepth(path) {
|
|
10
|
+
let count = 0;
|
|
11
|
+
for (let i = 0; i < path.length; i++) {
|
|
12
|
+
if (path[i] === sep)
|
|
13
|
+
count++;
|
|
14
|
+
}
|
|
15
|
+
return count;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reads the size and modified date of a file if it exists
|
|
19
|
+
*/
|
|
20
|
+
export async function fsStat(path) {
|
|
21
|
+
const data = await stat(path, { bigint: false }).catch(() => {
|
|
22
|
+
/* file not available */
|
|
23
|
+
});
|
|
24
|
+
if (!data)
|
|
25
|
+
return null;
|
|
26
|
+
return {
|
|
27
|
+
size: data.size,
|
|
28
|
+
modified: data.mtime,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Builds up the local and remote paths to use with syncing
|
|
33
|
+
*/
|
|
34
|
+
export function getSyncPaths(partialPath) {
|
|
35
|
+
const env = useEnv();
|
|
36
|
+
const localRootPath = getExtensionsPath();
|
|
37
|
+
const remoteRootPath = env['EXTENSIONS_PATH'];
|
|
38
|
+
if (!partialPath) {
|
|
39
|
+
return {
|
|
40
|
+
localExtensionsPath: localRootPath,
|
|
41
|
+
remoteExtensionsPath: normalizePath(remoteRootPath),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const resolvedPartialPath = relative(sep, resolve(sep, partialPath));
|
|
45
|
+
return {
|
|
46
|
+
localExtensionsPath: join(localRootPath, resolvedPartialPath),
|
|
47
|
+
remoteExtensionsPath: normalizePath(join(remoteRootPath, resolvedPartialPath)),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieve the stats for local and remote files and check if they are the same
|
|
52
|
+
* Returns false if files are differnt else true
|
|
53
|
+
*/
|
|
54
|
+
export async function compareFileMetadata(localPath, remotePath, disk) {
|
|
55
|
+
const localStat = await fsStat(localPath).catch(() => { });
|
|
56
|
+
if (!localStat)
|
|
57
|
+
return false;
|
|
58
|
+
const remoteStat = await disk.stat(remotePath).catch(() => { });
|
|
59
|
+
if (!remoteStat)
|
|
60
|
+
return false;
|
|
61
|
+
return remoteStat.modified <= localStat.modified && remoteStat.size === localStat.size;
|
|
62
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Extension, ExtensionManagerOptions } from '@directus/types';
|
|
2
2
|
import { Router } from 'express';
|
|
3
3
|
import type { ReadStream } from 'node:fs';
|
|
4
|
+
import { type ExtensionSyncOptions } from './lib/sync/sync.js';
|
|
4
5
|
export declare class ExtensionManager {
|
|
5
6
|
private options;
|
|
6
7
|
/**
|
|
@@ -47,6 +48,10 @@ export declare class ExtensionManager {
|
|
|
47
48
|
* sequence.
|
|
48
49
|
*/
|
|
49
50
|
private reloadQueue;
|
|
51
|
+
/**
|
|
52
|
+
* Used to prevent race condition when reading extension data while reloading extensions
|
|
53
|
+
*/
|
|
54
|
+
private reloadPromise;
|
|
50
55
|
/**
|
|
51
56
|
* Optional file system watcher to auto-reload extensions when the local file system changes
|
|
52
57
|
*/
|
|
@@ -76,7 +81,7 @@ export declare class ExtensionManager {
|
|
|
76
81
|
*/
|
|
77
82
|
install(versionId: string): Promise<void>;
|
|
78
83
|
uninstall(folder: string): Promise<void>;
|
|
79
|
-
broadcastReloadNotification(): Promise<void>;
|
|
84
|
+
broadcastReloadNotification(options?: ExtensionSyncOptions): Promise<void>;
|
|
80
85
|
/**
|
|
81
86
|
* Load all extensions from disk and register them in their respective places
|
|
82
87
|
*/
|
|
@@ -88,9 +93,8 @@ export declare class ExtensionManager {
|
|
|
88
93
|
/**
|
|
89
94
|
* Reload all the extensions. Will unload if extensions have already been loaded
|
|
90
95
|
*/
|
|
91
|
-
reload(options?:
|
|
92
|
-
|
|
93
|
-
}): Promise<unknown>;
|
|
96
|
+
reload(options?: ExtensionSyncOptions): Promise<unknown>;
|
|
97
|
+
isReloading(): Promise<void>;
|
|
94
98
|
/**
|
|
95
99
|
* Return the previously generated app extension bundle chunk by name.
|
|
96
100
|
* Providing no name will return the entry bundle.
|
|
@@ -13,7 +13,7 @@ import ivm from 'isolated-vm';
|
|
|
13
13
|
import { clone, debounce, isPlainObject } from 'lodash-es';
|
|
14
14
|
import { readFile, readdir } from 'node:fs/promises';
|
|
15
15
|
import os from 'node:os';
|
|
16
|
-
import { dirname, join } from 'node:path';
|
|
16
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
17
17
|
import { fileURLToPath } from 'node:url';
|
|
18
18
|
import path from 'path';
|
|
19
19
|
import { rolldown } from 'rolldown';
|
|
@@ -37,9 +37,9 @@ import { getSharedDepsMapping } from './lib/get-shared-deps-mapping.js';
|
|
|
37
37
|
import { getInstallationManager } from './lib/installation/index.js';
|
|
38
38
|
import { generateApiExtensionsSandboxEntrypoint } from './lib/sandbox/generate-api-extensions-sandbox-entrypoint.js';
|
|
39
39
|
import { instantiateSandboxSdk } from './lib/sandbox/sdk/instantiate.js';
|
|
40
|
-
import { syncExtensions } from './lib/sync-extensions.js';
|
|
41
40
|
import { wrapEmbeds } from './lib/wrap-embeds.js';
|
|
42
41
|
import DriverLocal from '@directus/storage-driver-local';
|
|
42
|
+
import { syncExtensions } from './lib/sync/sync.js';
|
|
43
43
|
// Workaround for https://github.com/rollup/plugins/issues/1329
|
|
44
44
|
const virtual = virtualDefault;
|
|
45
45
|
const alias = aliasDefault;
|
|
@@ -99,6 +99,10 @@ export class ExtensionManager {
|
|
|
99
99
|
* sequence.
|
|
100
100
|
*/
|
|
101
101
|
reloadQueue = new JobQueue();
|
|
102
|
+
/**
|
|
103
|
+
* Used to prevent race condition when reading extension data while reloading extensions
|
|
104
|
+
*/
|
|
105
|
+
reloadPromise = Promise.resolve();
|
|
102
106
|
/**
|
|
103
107
|
* Optional file system watcher to auto-reload extensions when the local file system changes
|
|
104
108
|
*/
|
|
@@ -148,7 +152,7 @@ export class ExtensionManager {
|
|
|
148
152
|
await this.closeWatcher();
|
|
149
153
|
}
|
|
150
154
|
if (!this.isLoaded) {
|
|
151
|
-
await this.load();
|
|
155
|
+
await this.load({ forceSync: true });
|
|
152
156
|
if (this.extensions.length > 0) {
|
|
153
157
|
logger.info(`Loaded extensions: ${this.extensions.map((ext) => ext.name).join(', ')}`);
|
|
154
158
|
}
|
|
@@ -160,7 +164,13 @@ export class ExtensionManager {
|
|
|
160
164
|
// Ignore requests for reloading that were published by the current process
|
|
161
165
|
if (isPlainObject(payload) && 'origin' in payload && payload['origin'] === this.processId)
|
|
162
166
|
return;
|
|
163
|
-
|
|
167
|
+
// Reload extensions with event options
|
|
168
|
+
const options = {};
|
|
169
|
+
if (typeof payload['forceSync'] === 'boolean')
|
|
170
|
+
options.forceSync = payload['forceSync'];
|
|
171
|
+
if (typeof payload['partialSync'] === 'string')
|
|
172
|
+
options.partialSync = payload['partialSync'];
|
|
173
|
+
this.reload(options);
|
|
164
174
|
});
|
|
165
175
|
}
|
|
166
176
|
/**
|
|
@@ -169,27 +179,31 @@ export class ExtensionManager {
|
|
|
169
179
|
async install(versionId) {
|
|
170
180
|
const logger = useLogger();
|
|
171
181
|
await this.installationManager.install(versionId);
|
|
172
|
-
|
|
182
|
+
const resolvedFolder = relative(sep, resolve(sep, versionId));
|
|
183
|
+
const syncFolder = join('.registry', resolvedFolder);
|
|
184
|
+
await this.broadcastReloadNotification({ partialSync: syncFolder });
|
|
185
|
+
await this.reload({ skipSync: true });
|
|
173
186
|
emitter.emitAction('extensions.installed', {
|
|
174
187
|
extensions: this.extensions,
|
|
175
188
|
versionId,
|
|
176
189
|
});
|
|
177
190
|
logger.info(`Installed extension: ${versionId}`);
|
|
178
|
-
await this.broadcastReloadNotification();
|
|
179
191
|
}
|
|
180
192
|
async uninstall(folder) {
|
|
181
193
|
const logger = useLogger();
|
|
182
194
|
await this.installationManager.uninstall(folder);
|
|
183
|
-
|
|
195
|
+
const resolvedFolder = relative(sep, resolve(sep, folder));
|
|
196
|
+
const syncFolder = join('.registry', resolvedFolder);
|
|
197
|
+
await this.broadcastReloadNotification({ partialSync: syncFolder });
|
|
198
|
+
await this.reload({ skipSync: true });
|
|
184
199
|
emitter.emitAction('extensions.uninstalled', {
|
|
185
200
|
extensions: this.extensions,
|
|
186
201
|
folder,
|
|
187
202
|
});
|
|
188
203
|
logger.info(`Uninstalled extension: ${folder}`);
|
|
189
|
-
await this.broadcastReloadNotification();
|
|
190
204
|
}
|
|
191
|
-
async broadcastReloadNotification() {
|
|
192
|
-
await this.messenger.publish(this.reloadChannel, { origin: this.processId });
|
|
205
|
+
async broadcastReloadNotification(options) {
|
|
206
|
+
await this.messenger.publish(this.reloadChannel, { ...options, origin: this.processId });
|
|
193
207
|
}
|
|
194
208
|
/**
|
|
195
209
|
* Load all extensions from disk and register them in their respective places
|
|
@@ -198,7 +212,7 @@ export class ExtensionManager {
|
|
|
198
212
|
const logger = useLogger();
|
|
199
213
|
if (env['EXTENSIONS_LOCATION']) {
|
|
200
214
|
try {
|
|
201
|
-
await syncExtensions(
|
|
215
|
+
await syncExtensions(options);
|
|
202
216
|
}
|
|
203
217
|
catch (error) {
|
|
204
218
|
logger.error(`Failed to sync extensions`);
|
|
@@ -250,7 +264,7 @@ export class ExtensionManager {
|
|
|
250
264
|
const logger = useLogger();
|
|
251
265
|
let resolve;
|
|
252
266
|
let reject;
|
|
253
|
-
|
|
267
|
+
this.reloadPromise = new Promise((res, rej) => {
|
|
254
268
|
resolve = res;
|
|
255
269
|
reject = rej;
|
|
256
270
|
});
|
|
@@ -283,7 +297,10 @@ export class ExtensionManager {
|
|
|
283
297
|
reject(new Error('Extensions have to be loaded before they can be reloaded'));
|
|
284
298
|
}
|
|
285
299
|
});
|
|
286
|
-
return
|
|
300
|
+
return this.reloadPromise;
|
|
301
|
+
}
|
|
302
|
+
isReloading() {
|
|
303
|
+
return this.reloadPromise;
|
|
287
304
|
}
|
|
288
305
|
/**
|
|
289
306
|
* Return the previously generated app extension bundle chunk by name.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEnv } from '@directus/env';
|
|
2
|
+
import { getDateTimeFormatted } from '@directus/utils';
|
|
2
3
|
import { parse as parseBytesConfiguration } from 'bytes';
|
|
3
4
|
import { getCache, setCacheValue } from '../cache.js';
|
|
4
5
|
import getDatabase from '../database/index.js';
|
|
@@ -7,7 +8,6 @@ import { ExportService } from '../services/import-export.js';
|
|
|
7
8
|
import asyncHandler from '../utils/async-handler.js';
|
|
8
9
|
import { getCacheControlHeader } from '../utils/get-cache-headers.js';
|
|
9
10
|
import { getCacheKey } from '../utils/get-cache-key.js';
|
|
10
|
-
import { getDateFormatted } from '../utils/get-date-formatted.js';
|
|
11
11
|
import { getMilliseconds } from '../utils/get-milliseconds.js';
|
|
12
12
|
import { stringByteSize } from '../utils/get-string-byte-size.js';
|
|
13
13
|
import { permissionsCacheable } from '../utils/permissions-cacheable.js';
|
|
@@ -58,7 +58,7 @@ export const respond = asyncHandler(async (req, res) => {
|
|
|
58
58
|
else {
|
|
59
59
|
filename += 'Export';
|
|
60
60
|
}
|
|
61
|
-
filename += ' ' +
|
|
61
|
+
filename += ' ' + getDateTimeFormatted();
|
|
62
62
|
if (req.sanitizedQuery.export === 'json') {
|
|
63
63
|
res.attachment(`${filename}.json`);
|
|
64
64
|
res.set('Content-Type', 'application/json');
|
|
@@ -7,7 +7,7 @@ export interface AccessRow {
|
|
|
7
7
|
};
|
|
8
8
|
role: string | null;
|
|
9
9
|
}
|
|
10
|
-
export declare const fetchPolicies:
|
|
10
|
+
export declare const fetchPolicies: (args_0: Pick<Accountability, "user" | "roles" | "ip">, context: Context) => Promise<string[]>;
|
|
11
11
|
/**
|
|
12
12
|
* Fetch the policies associated with the current user accountability
|
|
13
13
|
*/
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Fetches the roles tree starting from a specific role.
|
|
3
|
+
*/
|
|
4
|
+
export declare const fetchRolesTree: (start: string | null, context: {
|
|
5
|
+
knex: import("knex").Knex;
|
|
6
|
+
}) => Promise<string[]>;
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
+
import { fetchRolesTree as _fetchRolesTree } from '@directus/utils/node';
|
|
1
2
|
import { withCache } from '../utils/with-cache.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let parent = start;
|
|
7
|
-
const roles = [];
|
|
8
|
-
while (parent) {
|
|
9
|
-
const role = await knex
|
|
10
|
-
.select('id', 'parent')
|
|
11
|
-
.from('directus_roles')
|
|
12
|
-
.where({ id: parent })
|
|
13
|
-
.first();
|
|
14
|
-
if (!role) {
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
roles.push(role.id);
|
|
18
|
-
// Prevent infinite recursion loops
|
|
19
|
-
if (role.parent && roles.includes(role.parent) === true) {
|
|
20
|
-
roles.reverse();
|
|
21
|
-
const rolesStr = roles.map((role) => `"${role}"`).join('->');
|
|
22
|
-
throw new Error(`Recursion encountered: role "${role.id}" already exists in tree path ${rolesStr}`);
|
|
23
|
-
}
|
|
24
|
-
parent = role.parent;
|
|
25
|
-
}
|
|
26
|
-
roles.reverse();
|
|
27
|
-
return roles;
|
|
28
|
-
}
|
|
3
|
+
/**
|
|
4
|
+
* Fetches the roles tree starting from a specific role.
|
|
5
|
+
*/
|
|
6
|
+
export const fetchRolesTree = withCache('roles-tree', _fetchRolesTree, (start) => ({ start }));
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { Accountability } from '@directus/types';
|
|
1
|
+
import type { Accountability, GlobalAccess } from '@directus/types';
|
|
2
2
|
import type { Knex } from 'knex';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
interface FetchGlobalAccessContext {
|
|
4
|
+
knex: Knex;
|
|
5
|
+
ip?: Accountability['ip'];
|
|
6
|
+
}
|
|
7
|
+
export declare const fetchGlobalAccess: (accountability: Pick<Accountability, "user" | "roles" | "ip">, context: FetchGlobalAccessContext) => Promise<GlobalAccess>;
|
|
5
8
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Will fetch roles and user info separately so they can be cached and reused individually
|
|
9
|
+
* Re-implements fetchGlobalAccess to add caching, fetches roles and user info separately so they can be cached and reused individually
|
|
9
10
|
*/
|
|
10
|
-
export declare function _fetchGlobalAccess(accountability: Pick<Accountability, 'user' | 'roles' | 'ip'>,
|
|
11
|
+
export declare function _fetchGlobalAccess(accountability: Pick<Accountability, 'user' | 'roles' | 'ip'>, context: FetchGlobalAccessContext): Promise<GlobalAccess>;
|
|
12
|
+
export {};
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
+
import { fetchGlobalAccessForRoles as _fetchGlobalAccessForRoles, fetchGlobalAccessForUser as _fetchGlobalAccessForUser, } from '@directus/utils/node';
|
|
1
2
|
import { withCache } from '../../utils/with-cache.js';
|
|
2
|
-
|
|
3
|
-
import { fetchGlobalAccessForUser } from './lib/fetch-global-access-for-user.js';
|
|
4
|
-
export const fetchGlobalAccess = withCache('global-access', _fetchGlobalAccess, ({ user, roles, ip }) => ({
|
|
3
|
+
export const fetchGlobalAccess = withCache('global-access', _fetchGlobalAccess, ({ user, roles }, { ip }) => ({
|
|
5
4
|
user,
|
|
6
5
|
roles,
|
|
7
6
|
ip,
|
|
8
7
|
}));
|
|
8
|
+
const fetchGlobalAccessForRoles = withCache('global-access-roles', _fetchGlobalAccessForRoles, (roles, { ip }) => ({
|
|
9
|
+
roles,
|
|
10
|
+
ip,
|
|
11
|
+
}));
|
|
12
|
+
const fetchGlobalAccessForUser = withCache('global-access-user', _fetchGlobalAccessForUser, (user, { ip }) => ({
|
|
13
|
+
user,
|
|
14
|
+
ip,
|
|
15
|
+
}));
|
|
9
16
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Will fetch roles and user info separately so they can be cached and reused individually
|
|
17
|
+
* Re-implements fetchGlobalAccess to add caching, fetches roles and user info separately so they can be cached and reused individually
|
|
13
18
|
*/
|
|
14
|
-
export async function _fetchGlobalAccess(accountability,
|
|
15
|
-
const access = await fetchGlobalAccessForRoles(accountability, knex);
|
|
19
|
+
export async function _fetchGlobalAccess(accountability, context) {
|
|
20
|
+
const access = await fetchGlobalAccessForRoles(accountability.roles, { knex: context.knex, ip: accountability.ip });
|
|
16
21
|
if (accountability.user !== undefined) {
|
|
17
|
-
const userAccess = await fetchGlobalAccessForUser(accountability,
|
|
22
|
+
const userAccess = await fetchGlobalAccessForUser(accountability.user, {
|
|
23
|
+
knex: context.knex,
|
|
24
|
+
ip: accountability.ip,
|
|
25
|
+
});
|
|
18
26
|
// If app/admin is already true, keep it true
|
|
19
27
|
access.app ||= userAccess.app;
|
|
20
28
|
access.admin ||= userAccess.admin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Accountability } from '@directus/types';
|
|
2
2
|
import type { Knex } from 'knex';
|
|
3
|
-
export declare const fetchPoliciesIpAccess:
|
|
3
|
+
export declare const fetchPoliciesIpAccess: (accountability: Pick<Accountability, "user" | "roles">, knex: Knex<any, any[]>) => Promise<string[][]>;
|
|
4
4
|
export declare function _fetchPoliciesIpAccess(accountability: Pick<Accountability, 'user' | 'roles'>, knex: Knex): Promise<string[][]>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Accountability, Permission, PermissionsAction } from '@directus/types';
|
|
2
2
|
import type { Context } from '../types.js';
|
|
3
|
-
export declare const fetchRawPermissions:
|
|
3
|
+
export declare const fetchRawPermissions: (options: FetchRawPermissionsOptions, context: Context) => Promise<Permission[]>;
|
|
4
4
|
export interface FetchRawPermissionsOptions {
|
|
5
5
|
action?: PermissionsAction;
|
|
6
6
|
policies: string[];
|
|
@@ -8,5 +8,5 @@ export interface ShareInfo {
|
|
|
8
8
|
role: string;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
export declare const fetchShareInfo:
|
|
11
|
+
export declare const fetchShareInfo: (shareId: string, context: AbstractServiceOptions) => Promise<ShareInfo>;
|
|
12
12
|
export declare function _fetchShareInfo(shareId: string, context: AbstractServiceOptions): Promise<ShareInfo>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { withCache } from './with-cache.js';
|
|
2
|
-
export const fetchShareInfo = withCache('share-info', _fetchShareInfo);
|
|
2
|
+
export const fetchShareInfo = withCache('share-info', _fetchShareInfo, (shareId) => ({ shareId }));
|
|
3
3
|
export async function _fetchShareInfo(shareId, context) {
|
|
4
4
|
const { SharesService } = await import('../../services/shares.js');
|
|
5
5
|
const sharesService = new SharesService(context);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ipInNetworks } from '
|
|
1
|
+
import { ipInNetworks } from '@directus/utils/node';
|
|
2
2
|
export function filterPoliciesByIp(policies, ip) {
|
|
3
3
|
return policies.filter(({ policy }) => {
|
|
4
4
|
// Keep policies that don't have an ip address allow list configured
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { schemaPermissions } from '@directus/system-data';
|
|
2
2
|
import { set, uniq } from 'lodash-es';
|
|
3
|
-
import {
|
|
4
|
-
import { fetchShareInfo } from './fetch-share-info.js';
|
|
5
|
-
import { mergePermissions } from './merge-permissions.js';
|
|
3
|
+
import { reduceSchema } from '../../utils/reduce-schema.js';
|
|
6
4
|
import { fetchPermissions } from '../lib/fetch-permissions.js';
|
|
7
5
|
import { fetchPolicies } from '../lib/fetch-policies.js';
|
|
8
6
|
import { fetchRolesTree } from '../lib/fetch-roles-tree.js';
|
|
9
|
-
import {
|
|
7
|
+
import { fetchAllowedFieldMap } from '../modules/fetch-allowed-field-map/fetch-allowed-field-map.js';
|
|
10
8
|
import { fetchGlobalAccess } from '../modules/fetch-global-access/fetch-global-access.js';
|
|
9
|
+
import { fetchShareInfo } from './fetch-share-info.js';
|
|
10
|
+
import { mergePermissions } from './merge-permissions.js';
|
|
11
11
|
export async function getPermissionsForShare(accountability, collections, context) {
|
|
12
12
|
const defaults = {
|
|
13
13
|
action: 'read',
|
|
@@ -22,7 +22,7 @@ export async function getPermissionsForShare(accountability, collections, contex
|
|
|
22
22
|
const userAccountability = {
|
|
23
23
|
user: user_created.id,
|
|
24
24
|
role: user_created.role,
|
|
25
|
-
roles: await fetchRolesTree(user_created.role, context.knex),
|
|
25
|
+
roles: await fetchRolesTree(user_created.role, { knex: context.knex }),
|
|
26
26
|
admin: false,
|
|
27
27
|
app: false,
|
|
28
28
|
ip: accountability.ip,
|
|
@@ -31,14 +31,14 @@ export async function getPermissionsForShare(accountability, collections, contex
|
|
|
31
31
|
const shareAccountability = {
|
|
32
32
|
user: null,
|
|
33
33
|
role: role,
|
|
34
|
-
roles: await fetchRolesTree(role, context.knex),
|
|
34
|
+
roles: await fetchRolesTree(role, { knex: context.knex }),
|
|
35
35
|
admin: false,
|
|
36
36
|
app: false,
|
|
37
37
|
ip: accountability.ip,
|
|
38
38
|
};
|
|
39
39
|
const [{ admin: shareIsAdmin }, { admin: userIsAdmin }, userPermissions, sharePermissions, shareFieldMap, userFieldMap,] = await Promise.all([
|
|
40
|
-
fetchGlobalAccess(shareAccountability, context.knex),
|
|
41
|
-
fetchGlobalAccess(userAccountability, context.knex),
|
|
40
|
+
fetchGlobalAccess(shareAccountability, { knex: context.knex }),
|
|
41
|
+
fetchGlobalAccess(userAccountability, { knex: context.knex }),
|
|
42
42
|
getPermissionsForAccountability(userAccountability, context),
|
|
43
43
|
getPermissionsForAccountability(shareAccountability, context),
|
|
44
44
|
fetchAllowedFieldMap({
|