@directus/api 21.0.0 → 22.1.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/app.js +4 -4
- package/dist/auth/drivers/ldap.js +4 -4
- package/dist/auth/drivers/local.js +4 -4
- package/dist/auth/drivers/oauth2.js +4 -4
- package/dist/auth/drivers/openid.js +2 -4
- package/dist/cache.js +3 -0
- package/dist/cli/commands/bootstrap/index.js +8 -2
- package/dist/cli/commands/init/index.js +9 -10
- package/dist/cli/commands/init/questions.d.ts +7 -6
- package/dist/cli/commands/init/questions.js +2 -2
- package/dist/cli/utils/create-env/index.d.ts +2 -2
- package/dist/cli/utils/create-env/index.js +3 -1
- package/dist/cli/utils/defaults.d.ts +4 -11
- package/dist/cli/utils/defaults.js +7 -1
- package/dist/cli/utils/drivers.js +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/controllers/access.d.ts +2 -0
- package/dist/controllers/access.js +148 -0
- package/dist/controllers/auth.js +5 -16
- package/dist/controllers/permissions.js +14 -2
- package/dist/controllers/policies.d.ts +2 -0
- package/dist/controllers/policies.js +169 -0
- package/dist/controllers/roles.js +22 -1
- package/dist/controllers/tus.js +14 -26
- package/dist/controllers/users.js +0 -55
- package/dist/database/get-ast-from-query/get-ast-from-query.d.ts +16 -0
- package/dist/database/get-ast-from-query/get-ast-from-query.js +82 -0
- package/dist/database/get-ast-from-query/lib/convert-wildcards.d.ts +13 -0
- package/dist/database/get-ast-from-query/lib/convert-wildcards.js +69 -0
- package/dist/database/get-ast-from-query/lib/parse-fields.d.ts +15 -0
- package/dist/database/get-ast-from-query/lib/parse-fields.js +200 -0
- package/dist/database/get-ast-from-query/utils/get-deep-query.d.ts +14 -0
- package/dist/database/get-ast-from-query/utils/get-deep-query.js +17 -0
- package/dist/database/get-ast-from-query/utils/get-related-collection.d.ts +2 -0
- package/dist/database/get-ast-from-query/utils/get-related-collection.js +13 -0
- package/dist/database/get-ast-from-query/utils/get-relation.d.ts +2 -0
- package/dist/database/get-ast-from-query/utils/get-relation.js +7 -0
- package/dist/database/helpers/fn/types.d.ts +2 -1
- package/dist/database/helpers/fn/types.js +1 -1
- package/dist/database/helpers/geometry/dialects/mssql.d.ts +1 -1
- package/dist/database/helpers/geometry/dialects/mssql.js +4 -2
- package/dist/database/helpers/geometry/dialects/mysql.js +1 -1
- package/dist/database/helpers/geometry/dialects/oracle.d.ts +1 -1
- package/dist/database/helpers/geometry/dialects/oracle.js +5 -3
- package/dist/database/helpers/geometry/types.d.ts +1 -1
- package/dist/database/helpers/geometry/types.js +4 -2
- package/dist/database/helpers/index.d.ts +3 -3
- package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +2 -1
- package/dist/database/helpers/schema/dialects/cockroachdb.js +4 -0
- package/dist/database/helpers/schema/dialects/mssql.d.ts +2 -1
- package/dist/database/helpers/schema/dialects/mssql.js +4 -0
- package/dist/database/helpers/schema/dialects/oracle.d.ts +2 -1
- package/dist/database/helpers/schema/dialects/oracle.js +4 -0
- package/dist/database/helpers/schema/dialects/postgres.d.ts +2 -1
- package/dist/database/helpers/schema/dialects/postgres.js +4 -0
- package/dist/database/helpers/schema/types.d.ts +5 -0
- package/dist/database/helpers/schema/types.js +3 -0
- package/dist/database/helpers/schema/utils/preprocess-bindings.d.ts +8 -0
- package/dist/database/helpers/schema/utils/preprocess-bindings.js +30 -0
- package/dist/database/index.js +6 -1
- package/dist/database/migrations/20210519A-add-system-fk-triggers.js +3 -2
- package/dist/database/migrations/20230721A-require-shares-fields.js +3 -5
- package/dist/database/migrations/20240716A-update-files-date-fields.js +3 -7
- package/dist/{utils/merge-permissions.d.ts → database/migrations/20240806A-permissions-policies.d.ts} +4 -1
- package/dist/database/migrations/20240806A-permissions-policies.js +352 -0
- package/dist/database/run-ast/lib/get-db-query.d.ts +4 -0
- package/dist/database/run-ast/lib/get-db-query.js +218 -0
- package/dist/database/run-ast/lib/parse-current-level.d.ts +7 -0
- package/dist/database/run-ast/lib/parse-current-level.js +41 -0
- package/dist/database/run-ast/run-ast.d.ts +7 -0
- package/dist/database/run-ast/run-ast.js +107 -0
- package/dist/database/{run-ast.d.ts → run-ast/types.d.ts} +3 -9
- package/dist/database/run-ast/types.js +1 -0
- package/dist/database/run-ast/utils/apply-case-when.d.ts +16 -0
- package/dist/database/run-ast/utils/apply-case-when.js +27 -0
- package/dist/database/run-ast/utils/apply-parent-filters.d.ts +3 -0
- package/dist/database/run-ast/utils/apply-parent-filters.js +55 -0
- package/dist/database/run-ast/utils/get-column-pre-processor.d.ts +10 -0
- package/dist/database/run-ast/utils/get-column-pre-processor.js +57 -0
- package/dist/database/run-ast/utils/get-field-alias.d.ts +2 -0
- package/dist/database/run-ast/utils/get-field-alias.js +4 -0
- package/dist/database/run-ast/utils/get-inner-query-column-pre-processor.d.ts +5 -0
- package/dist/database/run-ast/utils/get-inner-query-column-pre-processor.js +23 -0
- package/dist/database/run-ast/utils/merge-with-parent-items.d.ts +3 -0
- package/dist/database/run-ast/utils/merge-with-parent-items.js +87 -0
- package/dist/database/run-ast/utils/remove-temporary-fields.d.ts +3 -0
- package/dist/database/run-ast/utils/remove-temporary-fields.js +73 -0
- package/dist/database/run-ast/utils/with-preprocess-bindings.d.ts +2 -0
- package/dist/database/run-ast/utils/with-preprocess-bindings.js +14 -0
- package/dist/flows.js +3 -4
- package/dist/middleware/authenticate.js +2 -7
- package/dist/middleware/cache.js +1 -1
- package/dist/middleware/respond.js +1 -1
- package/dist/permissions/cache.d.ts +2 -0
- package/dist/permissions/cache.js +23 -0
- package/dist/permissions/lib/fetch-permissions.d.ts +11 -0
- package/dist/permissions/lib/fetch-permissions.js +56 -0
- package/dist/permissions/lib/fetch-policies.d.ts +14 -0
- package/dist/permissions/lib/fetch-policies.js +43 -0
- package/dist/permissions/lib/fetch-roles-tree.d.ts +3 -0
- package/dist/permissions/lib/fetch-roles-tree.js +28 -0
- package/dist/{services/permissions → permissions}/lib/with-app-minimal-permissions.d.ts +1 -1
- package/dist/permissions/lib/with-app-minimal-permissions.js +10 -0
- package/dist/permissions/modules/fetch-accountability-collection-access/fetch-accountability-collection-access.d.ts +7 -0
- package/dist/permissions/modules/fetch-accountability-collection-access/fetch-accountability-collection-access.js +56 -0
- package/dist/permissions/modules/fetch-accountability-policy-globals/fetch-accountability-policy-globals.d.ts +3 -0
- package/dist/permissions/modules/fetch-accountability-policy-globals/fetch-accountability-policy-globals.js +16 -0
- package/dist/permissions/modules/fetch-allowed-collections/fetch-allowed-collections.d.ts +8 -0
- package/dist/permissions/modules/fetch-allowed-collections/fetch-allowed-collections.js +24 -0
- package/dist/permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.d.ts +9 -0
- package/dist/permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.js +31 -0
- package/dist/permissions/modules/fetch-allowed-fields/fetch-allowed-fields.d.ts +16 -0
- package/dist/permissions/modules/fetch-allowed-fields/fetch-allowed-fields.js +27 -0
- package/dist/permissions/modules/fetch-global-access/fetch-global-access.d.ts +10 -0
- package/dist/permissions/modules/fetch-global-access/fetch-global-access.js +23 -0
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.d.ts +5 -0
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-roles.js +7 -0
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.d.ts +5 -0
- package/dist/permissions/modules/fetch-global-access/lib/fetch-global-access-for-user.js +10 -0
- package/dist/permissions/modules/fetch-global-access/types.d.ts +4 -0
- package/dist/permissions/modules/fetch-global-access/types.js +1 -0
- package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.d.ts +4 -0
- package/dist/permissions/modules/fetch-global-access/utils/fetch-global-access-for-query.js +27 -0
- package/dist/permissions/modules/fetch-inconsistent-field-map/fetch-inconsistent-field-map.d.ts +12 -0
- package/dist/permissions/modules/fetch-inconsistent-field-map/fetch-inconsistent-field-map.js +32 -0
- package/dist/permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.d.ts +4 -0
- package/dist/permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.js +29 -0
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-children.d.ts +4 -0
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-children.js +49 -0
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-query.d.ts +3 -0
- package/dist/permissions/modules/process-ast/lib/extract-fields-from-query.js +56 -0
- package/dist/permissions/modules/process-ast/lib/field-map-from-ast.d.ts +4 -0
- package/dist/permissions/modules/process-ast/lib/field-map-from-ast.js +8 -0
- package/dist/permissions/modules/process-ast/lib/inject-cases.d.ts +9 -0
- package/dist/permissions/modules/process-ast/lib/inject-cases.js +93 -0
- package/dist/permissions/modules/process-ast/process-ast.d.ts +9 -0
- package/dist/permissions/modules/process-ast/process-ast.js +39 -0
- package/dist/permissions/modules/process-ast/types.d.ts +18 -0
- package/dist/permissions/modules/process-ast/types.js +1 -0
- package/dist/permissions/modules/process-ast/utils/collections-in-field-map.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/collections-in-field-map.js +7 -0
- package/dist/permissions/modules/process-ast/utils/dedupe-access.d.ts +12 -0
- package/dist/permissions/modules/process-ast/utils/dedupe-access.js +30 -0
- package/dist/permissions/modules/process-ast/utils/extract-paths-from-query.d.ts +15 -0
- package/dist/permissions/modules/process-ast/utils/extract-paths-from-query.js +60 -0
- package/dist/permissions/modules/process-ast/utils/find-related-collection.d.ts +3 -0
- package/dist/permissions/modules/process-ast/utils/find-related-collection.js +9 -0
- package/dist/permissions/modules/process-ast/utils/flatten-filter.d.ts +3 -0
- package/dist/permissions/modules/process-ast/utils/flatten-filter.js +34 -0
- package/dist/permissions/modules/process-ast/utils/format-a2o-key.d.ts +1 -0
- package/dist/permissions/modules/process-ast/utils/format-a2o-key.js +3 -0
- package/dist/permissions/modules/process-ast/utils/get-info-for-path.d.ts +5 -0
- package/dist/permissions/modules/process-ast/utils/get-info-for-path.js +7 -0
- package/dist/permissions/modules/process-ast/utils/has-item-permissions.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/has-item-permissions.js +3 -0
- package/dist/permissions/modules/process-ast/utils/stringify-query-path.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/stringify-query-path.js +3 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/create-error.d.ts +3 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/create-error.js +16 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-existence.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-existence.js +12 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-permissions.d.ts +2 -0
- package/dist/permissions/modules/process-ast/utils/validate-path/validate-path-permissions.js +28 -0
- package/dist/permissions/modules/process-payload/lib/is-field-nullable.d.ts +5 -0
- package/dist/permissions/modules/process-payload/lib/is-field-nullable.js +12 -0
- package/dist/permissions/modules/process-payload/process-payload.d.ts +13 -0
- package/dist/permissions/modules/process-payload/process-payload.js +77 -0
- package/dist/permissions/modules/validate-access/lib/validate-collection-access.d.ts +12 -0
- package/dist/permissions/modules/validate-access/lib/validate-collection-access.js +11 -0
- package/dist/permissions/modules/validate-access/lib/validate-item-access.d.ts +9 -0
- package/dist/permissions/modules/validate-access/lib/validate-item-access.js +33 -0
- package/dist/permissions/modules/validate-access/validate-access.d.ts +14 -0
- package/dist/permissions/modules/validate-access/validate-access.js +28 -0
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.d.ts +1 -0
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-count.js +8 -0
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-users.d.ts +5 -0
- package/dist/permissions/modules/validate-remaining-admin/validate-remaining-admin-users.js +10 -0
- package/dist/permissions/types.d.ts +6 -0
- package/dist/permissions/types.js +1 -0
- package/dist/permissions/utils/create-default-accountability.d.ts +2 -0
- package/dist/permissions/utils/create-default-accountability.js +11 -0
- package/dist/permissions/utils/extract-required-dynamic-variable-context.d.ts +8 -0
- package/dist/permissions/utils/extract-required-dynamic-variable-context.js +27 -0
- package/dist/permissions/utils/fetch-dynamic-variable-context.d.ts +9 -0
- package/dist/permissions/utils/fetch-dynamic-variable-context.js +43 -0
- package/dist/permissions/utils/filter-policies-by-ip.d.ts +2 -0
- package/dist/permissions/utils/filter-policies-by-ip.js +15 -0
- package/dist/permissions/utils/get-unaliased-field-key.d.ts +5 -0
- package/dist/permissions/utils/get-unaliased-field-key.js +17 -0
- package/dist/permissions/utils/process-permissions.d.ts +7 -0
- package/dist/permissions/utils/process-permissions.js +9 -0
- package/dist/permissions/utils/with-cache.d.ts +10 -0
- package/dist/permissions/utils/with-cache.js +25 -0
- package/dist/server.js +17 -4
- package/dist/services/access.d.ts +10 -0
- package/dist/services/access.js +43 -0
- package/dist/services/activity.js +22 -10
- package/dist/services/assets.d.ts +2 -3
- package/dist/services/assets.js +10 -5
- package/dist/services/authentication.js +18 -18
- package/dist/services/collections.js +18 -17
- package/dist/services/fields.d.ts +0 -1
- package/dist/services/fields.js +54 -25
- package/dist/services/files.js +10 -3
- package/dist/services/graphql/index.d.ts +3 -3
- package/dist/services/graphql/index.js +126 -22
- package/dist/services/graphql/subscription.js +2 -4
- package/dist/services/import-export.d.ts +3 -1
- package/dist/services/import-export.js +67 -9
- package/dist/services/index.d.ts +3 -2
- package/dist/services/index.js +3 -2
- package/dist/services/items.js +115 -44
- package/dist/services/meta.js +60 -23
- package/dist/services/notifications.js +14 -6
- package/dist/services/payload.d.ts +9 -10
- package/dist/services/payload.js +18 -3
- package/dist/services/{permissions/index.d.ts → permissions.d.ts} +5 -7
- package/dist/services/{permissions/index.js → permissions.js} +30 -54
- package/dist/services/policies.d.ts +12 -0
- package/dist/services/policies.js +87 -0
- package/dist/services/relations.d.ts +0 -6
- package/dist/services/relations.js +27 -30
- package/dist/services/roles.d.ts +4 -12
- package/dist/services/roles.js +57 -424
- package/dist/services/shares.d.ts +0 -2
- package/dist/services/shares.js +12 -8
- package/dist/services/specifications.d.ts +2 -2
- package/dist/services/specifications.js +39 -27
- package/dist/services/users.d.ts +1 -5
- package/dist/services/users.js +78 -161
- package/dist/services/utils.js +11 -7
- package/dist/services/versions.d.ts +0 -2
- package/dist/services/versions.js +34 -10
- package/dist/telemetry/lib/get-report.js +2 -2
- package/dist/telemetry/utils/check-user-limits.d.ts +5 -0
- package/dist/telemetry/utils/check-user-limits.js +19 -0
- package/dist/types/ast.d.ts +43 -1
- package/dist/types/database.d.ts +1 -1
- package/dist/types/items.d.ts +11 -0
- package/dist/utils/apply-query.d.ts +11 -7
- package/dist/utils/apply-query.js +69 -11
- package/dist/utils/fetch-user-count/fetch-access-lookup.d.ts +19 -0
- package/dist/utils/fetch-user-count/fetch-access-lookup.js +23 -0
- package/dist/utils/fetch-user-count/fetch-access-roles.d.ts +16 -0
- package/dist/utils/fetch-user-count/fetch-access-roles.js +37 -0
- package/dist/utils/fetch-user-count/fetch-active-users.d.ts +6 -0
- package/dist/utils/fetch-user-count/fetch-active-users.js +3 -0
- package/dist/utils/fetch-user-count/fetch-user-count.d.ts +12 -0
- package/dist/utils/fetch-user-count/fetch-user-count.js +64 -0
- package/dist/utils/fetch-user-count/get-user-count-query.d.ts +20 -0
- package/dist/utils/fetch-user-count/get-user-count-query.js +17 -0
- package/dist/utils/get-accountability-for-role.js +16 -25
- package/dist/utils/get-accountability-for-token.js +17 -16
- package/dist/utils/get-address.d.ts +5 -0
- package/dist/utils/get-address.js +13 -0
- package/dist/utils/get-cache-key.d.ts +1 -1
- package/dist/utils/get-cache-key.js +12 -1
- package/dist/utils/get-column.d.ts +2 -1
- package/dist/utils/get-column.js +1 -0
- package/dist/utils/get-service.js +5 -1
- package/dist/utils/reduce-schema.d.ts +4 -6
- package/dist/utils/reduce-schema.js +16 -32
- package/dist/utils/sanitize-schema.d.ts +1 -1
- package/dist/utils/transaction.js +28 -11
- package/dist/utils/validate-user-count-integrity.d.ts +13 -0
- package/dist/utils/validate-user-count-integrity.js +29 -0
- package/dist/websocket/authenticate.d.ts +0 -2
- package/dist/websocket/authenticate.js +0 -12
- package/dist/websocket/controllers/graphql.js +3 -7
- package/dist/websocket/controllers/hooks.js +4 -0
- package/dist/websocket/controllers/rest.js +2 -5
- package/dist/websocket/handlers/subscribe.js +0 -2
- package/dist/websocket/utils/items.d.ts +1 -1
- package/package.json +31 -30
- package/dist/database/run-ast.js +0 -458
- package/dist/middleware/check-ip.d.ts +0 -2
- package/dist/middleware/check-ip.js +0 -37
- package/dist/middleware/get-permissions.d.ts +0 -3
- package/dist/middleware/get-permissions.js +0 -10
- package/dist/services/authorization.d.ts +0 -17
- package/dist/services/authorization.js +0 -456
- package/dist/services/permissions/lib/with-app-minimal-permissions.js +0 -13
- package/dist/telemetry/utils/check-increased-user-limits.d.ts +0 -7
- package/dist/telemetry/utils/check-increased-user-limits.js +0 -25
- package/dist/telemetry/utils/get-role-counts-by-roles.d.ts +0 -6
- package/dist/telemetry/utils/get-role-counts-by-roles.js +0 -27
- package/dist/telemetry/utils/get-role-counts-by-users.d.ts +0 -11
- package/dist/telemetry/utils/get-role-counts-by-users.js +0 -34
- package/dist/telemetry/utils/get-user-count.d.ts +0 -8
- package/dist/telemetry/utils/get-user-count.js +0 -33
- package/dist/telemetry/utils/get-user-counts-by-roles.d.ts +0 -7
- package/dist/telemetry/utils/get-user-counts-by-roles.js +0 -35
- package/dist/utils/get-ast-from-query.d.ts +0 -13
- package/dist/utils/get-ast-from-query.js +0 -297
- package/dist/utils/get-permissions.d.ts +0 -2
- package/dist/utils/get-permissions.js +0 -150
- package/dist/utils/merge-permissions-for-share.d.ts +0 -4
- package/dist/utils/merge-permissions-for-share.js +0 -109
- package/dist/utils/merge-permissions.js +0 -95
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
import { InvalidCredentialsError } from '@directus/errors';
|
|
2
2
|
import getDatabase from '../database/index.js';
|
|
3
|
+
import { fetchRolesTree } from '../permissions/lib/fetch-roles-tree.js';
|
|
4
|
+
import { fetchGlobalAccess } from '../permissions/modules/fetch-global-access/fetch-global-access.js';
|
|
5
|
+
import { createDefaultAccountability } from '../permissions/utils/create-default-accountability.js';
|
|
3
6
|
import { getSecret } from './get-secret.js';
|
|
4
7
|
import isDirectusJWT from './is-directus-jwt.js';
|
|
5
|
-
import { verifySessionJWT } from './verify-session-jwt.js';
|
|
6
8
|
import { verifyAccessJWT } from './jwt.js';
|
|
9
|
+
import { verifySessionJWT } from './verify-session-jwt.js';
|
|
7
10
|
export async function getAccountabilityForToken(token, accountability) {
|
|
8
11
|
if (!accountability) {
|
|
9
|
-
accountability =
|
|
10
|
-
user: null,
|
|
11
|
-
role: null,
|
|
12
|
-
admin: false,
|
|
13
|
-
app: false,
|
|
14
|
-
};
|
|
12
|
+
accountability = createDefaultAccountability();
|
|
15
13
|
}
|
|
14
|
+
// Try finding the user with the provided token
|
|
15
|
+
const database = getDatabase();
|
|
16
16
|
if (token) {
|
|
17
17
|
if (isDirectusJWT(token)) {
|
|
18
18
|
const payload = verifyAccessJWT(token, getSecret());
|
|
19
19
|
if ('session' in payload) {
|
|
20
20
|
await verifySessionJWT(payload);
|
|
21
21
|
}
|
|
22
|
-
accountability.role = payload.role;
|
|
23
|
-
accountability.admin = payload.admin_access === true || payload.admin_access == 1;
|
|
24
|
-
accountability.app = payload.app_access === true || payload.app_access == 1;
|
|
25
22
|
if (payload.share)
|
|
26
23
|
accountability.share = payload.share;
|
|
27
24
|
if (payload.share_scope)
|
|
28
25
|
accountability.share_scope = payload.share_scope;
|
|
29
26
|
if (payload.id)
|
|
30
27
|
accountability.user = payload.id;
|
|
28
|
+
accountability.role = payload.role;
|
|
29
|
+
accountability.roles = await fetchRolesTree(payload.role, database);
|
|
30
|
+
const { admin, app } = await fetchGlobalAccess(accountability, database);
|
|
31
|
+
accountability.admin = admin;
|
|
32
|
+
accountability.app = app;
|
|
31
33
|
}
|
|
32
34
|
else {
|
|
33
|
-
// Try finding the user with the provided token
|
|
34
|
-
const database = getDatabase();
|
|
35
35
|
const user = await database
|
|
36
|
-
.select('directus_users.id', 'directus_users.role'
|
|
36
|
+
.select('directus_users.id', 'directus_users.role')
|
|
37
37
|
.from('directus_users')
|
|
38
|
-
.leftJoin('directus_roles', 'directus_users.role', 'directus_roles.id')
|
|
39
38
|
.where({
|
|
40
39
|
'directus_users.token': token,
|
|
41
40
|
status: 'active',
|
|
@@ -46,8 +45,10 @@ export async function getAccountabilityForToken(token, accountability) {
|
|
|
46
45
|
}
|
|
47
46
|
accountability.user = user.id;
|
|
48
47
|
accountability.role = user.role;
|
|
49
|
-
accountability.
|
|
50
|
-
|
|
48
|
+
accountability.roles = await fetchRolesTree(user.role, database);
|
|
49
|
+
const { admin, app } = await fetchGlobalAccess(accountability, database);
|
|
50
|
+
accountability.admin = admin;
|
|
51
|
+
accountability.app = app;
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
return accountability;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
export function getAddress(server) {
|
|
3
|
+
const address = server.address();
|
|
4
|
+
if (address === null) {
|
|
5
|
+
// Before the 'listening' event has been emitted or after calling server.close()
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (typeof address === 'string') {
|
|
9
|
+
// unix path
|
|
10
|
+
return address;
|
|
11
|
+
}
|
|
12
|
+
return `${address.address}:${address.port}`;
|
|
13
|
+
}
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import hash from 'object-hash';
|
|
2
2
|
import url from 'url';
|
|
3
|
+
import getDatabase from '../database/index.js';
|
|
4
|
+
import { fetchPoliciesIpAccess } from '../permissions/modules/fetch-policies-ip-access/fetch-policies-ip-access.js';
|
|
3
5
|
import { getGraphqlQueryAndVariables } from './get-graphql-query-and-variables.js';
|
|
4
6
|
import { version } from 'directus/version';
|
|
5
|
-
|
|
7
|
+
import { ipInNetworks } from './ip-in-networks.js';
|
|
8
|
+
export async function getCacheKey(req) {
|
|
6
9
|
const path = url.parse(req.originalUrl).pathname;
|
|
7
10
|
const isGraphQl = path?.startsWith('/graphql');
|
|
11
|
+
let includeIp = false;
|
|
12
|
+
if (req.accountability && req.accountability.ip) {
|
|
13
|
+
// Check if the IP influences the result of the request, that can be the case if some policies have an ip_access
|
|
14
|
+
// filter and the request IP matches any of those filters
|
|
15
|
+
const ipFilters = await fetchPoliciesIpAccess(req.accountability, getDatabase());
|
|
16
|
+
includeIp = ipFilters.length > 0 && ipFilters.some((networks) => ipInNetworks(req.accountability.ip, networks));
|
|
17
|
+
}
|
|
8
18
|
const info = {
|
|
9
19
|
version,
|
|
10
20
|
user: req.accountability?.user || null,
|
|
11
21
|
path,
|
|
12
22
|
query: isGraphQl ? getGraphqlQueryAndVariables(req) : req.sanitizedQuery,
|
|
23
|
+
...(includeIp && { ip: req.accountability.ip }),
|
|
13
24
|
};
|
|
14
25
|
const key = hash(info);
|
|
15
26
|
return key;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { Query, SchemaOverview } from '@directus/types';
|
|
1
|
+
import type { Filter, Query, SchemaOverview } from '@directus/types';
|
|
2
2
|
import type { Knex } from 'knex';
|
|
3
3
|
type GetColumnOptions = {
|
|
4
4
|
query?: Query | undefined;
|
|
5
|
+
cases?: Filter[];
|
|
5
6
|
originalCollectionName?: string | undefined;
|
|
6
7
|
};
|
|
7
8
|
/**
|
package/dist/utils/get-column.js
CHANGED
|
@@ -30,6 +30,7 @@ export function getColumn(knex, table, column, alias = applyFunctionToColumnName
|
|
|
30
30
|
const result = fn[functionName](table, columnName, {
|
|
31
31
|
type,
|
|
32
32
|
query: options?.query,
|
|
33
|
+
cases: options?.cases,
|
|
33
34
|
originalCollectionName: options?.originalCollectionName,
|
|
34
35
|
});
|
|
35
36
|
if (alias) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ForbiddenError } from '@directus/errors';
|
|
2
|
-
import { ActivityService, DashboardsService, FilesService, FlowsService, FoldersService, ItemsService, NotificationsService, OperationsService, PanelsService, PermissionsService, PresetsService, RevisionsService, RolesService, SettingsService, SharesService, TranslationsService, UsersService, VersionsService, WebhooksService, } from '../services/index.js';
|
|
2
|
+
import { AccessService, ActivityService, DashboardsService, FilesService, FlowsService, FoldersService, ItemsService, NotificationsService, OperationsService, PanelsService, PermissionsService, PoliciesService, PresetsService, RevisionsService, RolesService, SettingsService, SharesService, TranslationsService, UsersService, VersionsService, WebhooksService, } from '../services/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Select the correct service for the given collection. This allows the individual services to run
|
|
5
5
|
* their custom checks (f.e. it allows `UsersService` to prevent updating TFA secret from outside).
|
|
6
6
|
*/
|
|
7
7
|
export function getService(collection, opts) {
|
|
8
8
|
switch (collection) {
|
|
9
|
+
case 'directus_access':
|
|
10
|
+
return new AccessService(opts);
|
|
9
11
|
case 'directus_activity':
|
|
10
12
|
return new ActivityService(opts);
|
|
11
13
|
case 'directus_dashboards':
|
|
@@ -26,6 +28,8 @@ export function getService(collection, opts) {
|
|
|
26
28
|
return new PermissionsService(opts);
|
|
27
29
|
case 'directus_presets':
|
|
28
30
|
return new PresetsService(opts);
|
|
31
|
+
case 'directus_policies':
|
|
32
|
+
return new PoliciesService(opts);
|
|
29
33
|
case 'directus_revisions':
|
|
30
34
|
return new RevisionsService(opts);
|
|
31
35
|
case 'directus_roles':
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SchemaOverview } from '@directus/types';
|
|
2
|
+
import type { FieldMap } from '../permissions/modules/fetch-allowed-field-map/fetch-allowed-field-map.js';
|
|
2
3
|
/**
|
|
3
4
|
* Reduces the schema based on the included permissions. The resulting object is the schema structure, but with only
|
|
4
|
-
* the allowed collections/fields/relations included based on the
|
|
5
|
-
* @param schema The full project schema
|
|
6
|
-
* @param actions Array of permissions actions (crud)
|
|
7
|
-
* @returns Reduced schema
|
|
5
|
+
* the allowed collections/fields/relations included based on the passed field map.
|
|
8
6
|
*/
|
|
9
|
-
export declare function reduceSchema(schema: SchemaOverview,
|
|
7
|
+
export declare function reduceSchema(schema: SchemaOverview, fieldMap: FieldMap): SchemaOverview;
|
|
@@ -1,40 +1,24 @@
|
|
|
1
|
-
import { uniq } from 'lodash-es';
|
|
2
1
|
/**
|
|
3
2
|
* Reduces the schema based on the included permissions. The resulting object is the schema structure, but with only
|
|
4
|
-
* the allowed collections/fields/relations included based on the
|
|
5
|
-
* @param schema The full project schema
|
|
6
|
-
* @param actions Array of permissions actions (crud)
|
|
7
|
-
* @returns Reduced schema
|
|
3
|
+
* the allowed collections/fields/relations included based on the passed field map.
|
|
8
4
|
*/
|
|
9
|
-
export function reduceSchema(schema,
|
|
5
|
+
export function reduceSchema(schema, fieldMap) {
|
|
10
6
|
const reduced = {
|
|
11
7
|
collections: {},
|
|
12
8
|
relations: [],
|
|
13
9
|
};
|
|
14
|
-
const allowedFieldsInCollection = permissions
|
|
15
|
-
?.filter((permission) => actions.includes(permission.action))
|
|
16
|
-
.reduce((acc, permission) => {
|
|
17
|
-
if (!acc[permission.collection]) {
|
|
18
|
-
acc[permission.collection] = [];
|
|
19
|
-
}
|
|
20
|
-
if (permission.fields) {
|
|
21
|
-
acc[permission.collection] = uniq([...acc[permission.collection], ...permission.fields]);
|
|
22
|
-
}
|
|
23
|
-
return acc;
|
|
24
|
-
}, {}) ?? {};
|
|
25
10
|
for (const [collectionName, collection] of Object.entries(schema.collections)) {
|
|
26
|
-
if (!
|
|
11
|
+
if (!fieldMap[collectionName]) {
|
|
12
|
+
// Collection is not allowed at all
|
|
27
13
|
continue;
|
|
28
14
|
}
|
|
29
15
|
const fields = {};
|
|
30
16
|
for (const [fieldName, field] of Object.entries(schema.collections[collectionName].fields)) {
|
|
31
|
-
if (!
|
|
32
|
-
!allowedFieldsInCollection[collectionName]?.includes(fieldName)) {
|
|
17
|
+
if (!fieldMap[collectionName]?.includes('*') && !fieldMap[collectionName]?.includes(fieldName)) {
|
|
33
18
|
continue;
|
|
34
19
|
}
|
|
35
20
|
const o2mRelation = schema.relations.find((relation) => relation.related_collection === collectionName && relation.meta?.one_field === fieldName);
|
|
36
|
-
if (o2mRelation &&
|
|
37
|
-
!permissions?.some((permission) => permission.collection === o2mRelation.collection && actions.includes(permission.action))) {
|
|
21
|
+
if (o2mRelation && !fieldMap[collectionName]) {
|
|
38
22
|
continue;
|
|
39
23
|
}
|
|
40
24
|
fields[fieldName] = field;
|
|
@@ -47,29 +31,29 @@ export function reduceSchema(schema, permissions, actions = ['create', 'read', '
|
|
|
47
31
|
reduced.relations = schema.relations.filter((relation) => {
|
|
48
32
|
let collectionsAllowed = true;
|
|
49
33
|
let fieldsAllowed = true;
|
|
50
|
-
if (Object.keys(
|
|
34
|
+
if (Object.keys(fieldMap).includes(relation.collection) === false) {
|
|
51
35
|
collectionsAllowed = false;
|
|
52
36
|
}
|
|
53
37
|
if (relation.related_collection &&
|
|
54
|
-
(Object.keys(
|
|
38
|
+
(Object.keys(fieldMap).includes(relation.related_collection) === false ||
|
|
55
39
|
// Ignore legacy permissions with an empty fields array
|
|
56
|
-
|
|
40
|
+
fieldMap[relation.related_collection]?.length === 0)) {
|
|
57
41
|
collectionsAllowed = false;
|
|
58
42
|
}
|
|
59
43
|
if (relation.meta?.one_allowed_collections &&
|
|
60
|
-
relation.meta.one_allowed_collections.every((collection) => Object.keys(
|
|
44
|
+
relation.meta.one_allowed_collections.every((collection) => Object.keys(fieldMap).includes(collection)) === false) {
|
|
61
45
|
collectionsAllowed = false;
|
|
62
46
|
}
|
|
63
|
-
if (!
|
|
64
|
-
(
|
|
65
|
-
|
|
47
|
+
if (!fieldMap[relation.collection] ||
|
|
48
|
+
(fieldMap[relation.collection]?.includes('*') === false &&
|
|
49
|
+
fieldMap[relation.collection]?.includes(relation.field) === false)) {
|
|
66
50
|
fieldsAllowed = false;
|
|
67
51
|
}
|
|
68
52
|
if (relation.related_collection &&
|
|
69
53
|
relation.meta?.one_field &&
|
|
70
|
-
(!
|
|
71
|
-
(
|
|
72
|
-
|
|
54
|
+
(!fieldMap[relation.related_collection] ||
|
|
55
|
+
(fieldMap[relation.related_collection]?.includes('*') === false &&
|
|
56
|
+
fieldMap[relation.related_collection]?.includes(relation.meta?.one_field) === false))) {
|
|
73
57
|
fieldsAllowed = false;
|
|
74
58
|
}
|
|
75
59
|
return collectionsAllowed && fieldsAllowed;
|
|
@@ -16,7 +16,7 @@ export declare function sanitizeCollection(collection: Collection | undefined):
|
|
|
16
16
|
* @returns sanitized field
|
|
17
17
|
*/
|
|
18
18
|
export declare function sanitizeField(field: Field | undefined, sanitizeAllSchema?: boolean): Partial<Field> | undefined;
|
|
19
|
-
export declare function sanitizeColumn(column: Column): Pick<Column, "
|
|
19
|
+
export declare function sanitizeColumn(column: Column): Pick<Column, "table" | "name" | "numeric_precision" | "numeric_scale" | "data_type" | "default_value" | "max_length" | "is_nullable" | "is_unique" | "is_primary_key" | "is_generated" | "generation_expression" | "has_auto_increment" | "foreign_key_table" | "foreign_key_column">;
|
|
20
20
|
/**
|
|
21
21
|
* Pick certain database vendor specific relation properties that should be compared when performing diff
|
|
22
22
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isObject } from '@directus/utils';
|
|
1
2
|
import {} from 'knex';
|
|
2
3
|
import { getDatabaseClient } from '../database/index.js';
|
|
3
4
|
import { useLogger } from '../logger/index.js';
|
|
@@ -18,16 +19,7 @@ export const transaction = async (knex, handler) => {
|
|
|
18
19
|
}
|
|
19
20
|
catch (error) {
|
|
20
21
|
const client = getDatabaseClient(knex);
|
|
21
|
-
|
|
22
|
-
* This error code indicates that the transaction failed due to another
|
|
23
|
-
* concurrent or recent transaction attempting to write to the same data.
|
|
24
|
-
* This can usually be solved by restarting the transaction on client-side
|
|
25
|
-
* after a short delay, so that it is executed against the latest state.
|
|
26
|
-
*
|
|
27
|
-
* @link https://www.cockroachlabs.com/docs/stable/transaction-retry-error-reference
|
|
28
|
-
*/
|
|
29
|
-
const COCKROACH_RETRY_ERROR_CODE = '40001';
|
|
30
|
-
if (client !== 'cockroachdb' || error?.code !== COCKROACH_RETRY_ERROR_CODE)
|
|
22
|
+
if (!shouldRetryTransaction(client, error))
|
|
31
23
|
throw error;
|
|
32
24
|
const MAX_ATTEMPTS = 3;
|
|
33
25
|
const BASE_DELAY = 100;
|
|
@@ -40,7 +32,7 @@ export const transaction = async (knex, handler) => {
|
|
|
40
32
|
return await knex.transaction((trx) => handler(trx));
|
|
41
33
|
}
|
|
42
34
|
catch (error) {
|
|
43
|
-
if (error
|
|
35
|
+
if (!shouldRetryTransaction(client, error))
|
|
44
36
|
throw error;
|
|
45
37
|
}
|
|
46
38
|
}
|
|
@@ -50,3 +42,28 @@ export const transaction = async (knex, handler) => {
|
|
|
50
42
|
}
|
|
51
43
|
}
|
|
52
44
|
};
|
|
45
|
+
function shouldRetryTransaction(client, error) {
|
|
46
|
+
/**
|
|
47
|
+
* This error code indicates that the transaction failed due to another
|
|
48
|
+
* concurrent or recent transaction attempting to write to the same data.
|
|
49
|
+
* This can usually be solved by restarting the transaction on client-side
|
|
50
|
+
* after a short delay, so that it is executed against the latest state.
|
|
51
|
+
*
|
|
52
|
+
* @link https://www.cockroachlabs.com/docs/stable/transaction-retry-error-reference
|
|
53
|
+
*/
|
|
54
|
+
const COCKROACH_RETRY_ERROR_CODE = '40001';
|
|
55
|
+
/**
|
|
56
|
+
* SQLITE_BUSY is an error code returned by SQLite when an operation can't be
|
|
57
|
+
* performed due to a locked database file. This often arises due to multiple
|
|
58
|
+
* processes trying to simultaneously access the database, causing potential
|
|
59
|
+
* data inconsistencies. There are a few mechanisms to handle this case,
|
|
60
|
+
* one of which is to retry the complete transaction again
|
|
61
|
+
* on client-side after a short delay.
|
|
62
|
+
*
|
|
63
|
+
* @link https://www.sqlite.org/rescode.html#busy
|
|
64
|
+
*/
|
|
65
|
+
const SQLITE_BUSY_ERROR_CODE = 'SQLITE_BUSY';
|
|
66
|
+
return (isObject(error) &&
|
|
67
|
+
((client === 'cockroachdb' && error['code'] === COCKROACH_RETRY_ERROR_CODE) ||
|
|
68
|
+
(client === 'sqlite' && error['code'] === SQLITE_BUSY_ERROR_CODE)));
|
|
69
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type FetchUserCountOptions } from './fetch-user-count/fetch-user-count.js';
|
|
2
|
+
export declare enum UserIntegrityCheckFlag {
|
|
3
|
+
None = 0,
|
|
4
|
+
/** Check if the number of remaining admin users is greater than 0 */
|
|
5
|
+
RemainingAdmins = 1,
|
|
6
|
+
/** Check if the number of users is within the limits */
|
|
7
|
+
UserLimits = 2,
|
|
8
|
+
All = 3
|
|
9
|
+
}
|
|
10
|
+
export interface ValidateUserCountIntegrityOptions extends Omit<FetchUserCountOptions, 'adminOnly'> {
|
|
11
|
+
flags: UserIntegrityCheckFlag;
|
|
12
|
+
}
|
|
13
|
+
export declare function validateUserCountIntegrity(options: ValidateUserCountIntegrityOptions): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { validateRemainingAdminCount } from '../permissions/modules/validate-remaining-admin/validate-remaining-admin-count.js';
|
|
2
|
+
import { checkUserLimits } from '../telemetry/utils/check-user-limits.js';
|
|
3
|
+
import { shouldCheckUserLimits } from '../telemetry/utils/should-check-user-limits.js';
|
|
4
|
+
import { fetchUserCount } from './fetch-user-count/fetch-user-count.js';
|
|
5
|
+
export var UserIntegrityCheckFlag;
|
|
6
|
+
(function (UserIntegrityCheckFlag) {
|
|
7
|
+
UserIntegrityCheckFlag[UserIntegrityCheckFlag["None"] = 0] = "None";
|
|
8
|
+
/** Check if the number of remaining admin users is greater than 0 */
|
|
9
|
+
UserIntegrityCheckFlag[UserIntegrityCheckFlag["RemainingAdmins"] = 1] = "RemainingAdmins";
|
|
10
|
+
/** Check if the number of users is within the limits */
|
|
11
|
+
UserIntegrityCheckFlag[UserIntegrityCheckFlag["UserLimits"] = 2] = "UserLimits";
|
|
12
|
+
UserIntegrityCheckFlag[UserIntegrityCheckFlag["All"] = 3] = "All";
|
|
13
|
+
})(UserIntegrityCheckFlag || (UserIntegrityCheckFlag = {}));
|
|
14
|
+
export async function validateUserCountIntegrity(options) {
|
|
15
|
+
const validateUserLimits = (options.flags & UserIntegrityCheckFlag.UserLimits) !== 0;
|
|
16
|
+
const validateRemainingAdminUsers = (options.flags & UserIntegrityCheckFlag.RemainingAdmins) !== 0;
|
|
17
|
+
const limitCheck = validateUserLimits && shouldCheckUserLimits();
|
|
18
|
+
if (!validateRemainingAdminUsers && !limitCheck) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const adminOnly = validateRemainingAdminUsers && !limitCheck;
|
|
22
|
+
const userCounts = await fetchUserCount({ ...options, adminOnly });
|
|
23
|
+
if (limitCheck) {
|
|
24
|
+
await checkUserLimits(userCounts);
|
|
25
|
+
}
|
|
26
|
+
if (validateRemainingAdminUsers) {
|
|
27
|
+
validateRemainingAdminCount(userCounts.admin);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { Accountability } from '@directus/types';
|
|
2
1
|
import type { BasicAuthMessage } from './messages.js';
|
|
3
2
|
import type { AuthenticationState } from './types.js';
|
|
4
3
|
export declare function authenticateConnection(message: BasicAuthMessage & Record<string, any>): Promise<AuthenticationState>;
|
|
5
|
-
export declare function refreshAccountability(accountability: Accountability | null | undefined): Promise<Accountability>;
|
|
6
4
|
export declare function authenticationSuccess(uid?: string | number, refresh_token?: string): string;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_AUTH_PROVIDER } from '../constants.js';
|
|
2
2
|
import { AuthenticationService } from '../services/index.js';
|
|
3
3
|
import { getAccountabilityForToken } from '../utils/get-accountability-for-token.js';
|
|
4
|
-
import { getPermissions } from '../utils/get-permissions.js';
|
|
5
4
|
import { getSchema } from '../utils/get-schema.js';
|
|
6
5
|
import { WebSocketError } from './errors.js';
|
|
7
6
|
import { getExpiresAtForToken } from './utils/get-expires-at-for-token.js';
|
|
@@ -33,17 +32,6 @@ export async function authenticateConnection(message) {
|
|
|
33
32
|
throw new WebSocketError('auth', 'AUTH_FAILED', 'Authentication failed.', message['uid']);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
|
-
export async function refreshAccountability(accountability) {
|
|
37
|
-
accountability = accountability ?? {
|
|
38
|
-
role: null,
|
|
39
|
-
user: null,
|
|
40
|
-
admin: false,
|
|
41
|
-
app: false,
|
|
42
|
-
};
|
|
43
|
-
const schema = await getSchema();
|
|
44
|
-
const permissions = await getPermissions(accountability, schema);
|
|
45
|
-
return { ...accountability, permissions };
|
|
46
|
-
}
|
|
47
35
|
export function authenticationSuccess(uid, refresh_token) {
|
|
48
36
|
const message = {
|
|
49
37
|
type: 'auth',
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useEnv } from '@directus/env';
|
|
2
1
|
import { CloseCode, MessageType, makeServer } from 'graphql-ws';
|
|
3
2
|
import { useLogger } from '../../logger/index.js';
|
|
4
3
|
import { bindPubSub } from '../../services/graphql/subscription.js';
|
|
5
4
|
import { GraphQLService } from '../../services/index.js';
|
|
6
5
|
import { getSchema } from '../../utils/get-schema.js';
|
|
7
|
-
import {
|
|
6
|
+
import { getAddress } from '../../utils/get-address.js';
|
|
7
|
+
import { authenticateConnection } from '../authenticate.js';
|
|
8
8
|
import { handleWebSocketError } from '../errors.js';
|
|
9
9
|
import { ConnectionParams, WebSocketMessage } from '../messages.js';
|
|
10
10
|
import { getMessageType } from '../utils/message.js';
|
|
@@ -14,7 +14,6 @@ export class GraphQLSubscriptionController extends SocketController {
|
|
|
14
14
|
gql;
|
|
15
15
|
constructor(httpServer) {
|
|
16
16
|
super(httpServer, 'WEBSOCKETS_GRAPHQL');
|
|
17
|
-
const env = useEnv();
|
|
18
17
|
this.server.on('connection', (ws, auth) => {
|
|
19
18
|
this.bindEvents(this.createClient(ws, auth));
|
|
20
19
|
});
|
|
@@ -31,7 +30,7 @@ export class GraphQLSubscriptionController extends SocketController {
|
|
|
31
30
|
},
|
|
32
31
|
});
|
|
33
32
|
bindPubSub();
|
|
34
|
-
logger.info(`GraphQL Subscriptions started at ws://${
|
|
33
|
+
logger.info(`GraphQL Subscriptions started at ws://${getAddress(httpServer)}${this.endpoint}`);
|
|
35
34
|
}
|
|
36
35
|
bindEvents(client) {
|
|
37
36
|
const closedHandler = this.gql.opened({
|
|
@@ -64,9 +63,6 @@ export class GraphQLSubscriptionController extends SocketController {
|
|
|
64
63
|
client.close(CloseCode.Forbidden, 'Forbidden');
|
|
65
64
|
return;
|
|
66
65
|
}
|
|
67
|
-
else {
|
|
68
|
-
client.accountability = await refreshAccountability(client.accountability);
|
|
69
|
-
}
|
|
70
66
|
await cb(JSON.stringify(message));
|
|
71
67
|
}
|
|
72
68
|
catch (error) {
|
|
@@ -7,19 +7,23 @@ export function registerWebSocketEvents() {
|
|
|
7
7
|
actionsRegistered = true;
|
|
8
8
|
registerActionHooks([
|
|
9
9
|
'items',
|
|
10
|
+
'access',
|
|
10
11
|
'activity',
|
|
11
12
|
'collections',
|
|
12
13
|
'dashboards',
|
|
14
|
+
'flows',
|
|
13
15
|
'folders',
|
|
14
16
|
'notifications',
|
|
15
17
|
'operations',
|
|
16
18
|
'panels',
|
|
17
19
|
'permissions',
|
|
20
|
+
'policies',
|
|
18
21
|
'presets',
|
|
19
22
|
'revisions',
|
|
20
23
|
'roles',
|
|
21
24
|
'settings',
|
|
22
25
|
'shares',
|
|
26
|
+
'translations',
|
|
23
27
|
'users',
|
|
24
28
|
'versions',
|
|
25
29
|
'webhooks',
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { useEnv } from '@directus/env';
|
|
2
1
|
import { parseJSON } from '@directus/utils';
|
|
3
2
|
import emitter from '../../emitter.js';
|
|
4
3
|
import { useLogger } from '../../logger/index.js';
|
|
5
|
-
import {
|
|
4
|
+
import { getAddress } from '../../utils/get-address.js';
|
|
6
5
|
import { WebSocketError, handleWebSocketError } from '../errors.js';
|
|
7
6
|
import { WebSocketMessage } from '../messages.js';
|
|
8
7
|
import SocketController from './base.js';
|
|
@@ -10,17 +9,15 @@ const logger = useLogger();
|
|
|
10
9
|
export class WebSocketController extends SocketController {
|
|
11
10
|
constructor(httpServer) {
|
|
12
11
|
super(httpServer, 'WEBSOCKETS_REST');
|
|
13
|
-
const env = useEnv();
|
|
14
12
|
this.server.on('connection', (ws, auth) => {
|
|
15
13
|
this.bindEvents(this.createClient(ws, auth));
|
|
16
14
|
});
|
|
17
|
-
logger.info(`WebSocket Server started at ws://${
|
|
15
|
+
logger.info(`WebSocket Server started at ws://${getAddress(httpServer)}${this.endpoint}`);
|
|
18
16
|
}
|
|
19
17
|
bindEvents(client) {
|
|
20
18
|
client.on('parsed-message', async (message) => {
|
|
21
19
|
try {
|
|
22
20
|
message = WebSocketMessage.parse(await emitter.emitFilter('websocket.message', message, { client }));
|
|
23
|
-
client.accountability = await refreshAccountability(client.accountability);
|
|
24
21
|
emitter.emitAction('websocket.message', { message, client });
|
|
25
22
|
}
|
|
26
23
|
catch (error) {
|
|
@@ -4,7 +4,6 @@ import { useBus } from '../../bus/index.js';
|
|
|
4
4
|
import emitter from '../../emitter.js';
|
|
5
5
|
import { getSchema } from '../../utils/get-schema.js';
|
|
6
6
|
import { sanitizeQuery } from '../../utils/sanitize-query.js';
|
|
7
|
-
import { refreshAccountability } from '../authenticate.js';
|
|
8
7
|
import { WebSocketError, handleWebSocketError } from '../errors.js';
|
|
9
8
|
import { WebSocketSubscribeMessage } from '../messages.js';
|
|
10
9
|
import { getPayload } from '../utils/items.js';
|
|
@@ -112,7 +111,6 @@ export class SubscribeHandler {
|
|
|
112
111
|
continue;
|
|
113
112
|
}
|
|
114
113
|
try {
|
|
115
|
-
client.accountability = await refreshAccountability(client.accountability);
|
|
116
114
|
const result = await getPayload(subscription, client.accountability, schema, event);
|
|
117
115
|
if (Array.isArray(result?.['data']) && result?.['data']?.length === 0)
|
|
118
116
|
continue;
|
|
@@ -39,5 +39,5 @@ export declare function getFieldsPayload(subscription: PSubscription, accountabi
|
|
|
39
39
|
* @param event Event data
|
|
40
40
|
* @returns the fetched data
|
|
41
41
|
*/
|
|
42
|
-
export declare function getItemsPayload(subscription: PSubscription, accountability: Accountability | null, schema: SchemaOverview, event?: WebSocketEvent): Promise<string | number | import("@directus/types").Item |
|
|
42
|
+
export declare function getItemsPayload(subscription: PSubscription, accountability: Accountability | null, schema: SchemaOverview, event?: WebSocketEvent): Promise<string | number | (string | number)[] | import("@directus/types").Item | import("@directus/types").Item[]>;
|
|
43
43
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directus/api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.1.0",
|
|
4
4
|
"description": "Directus is a real-time API and App dashboard for managing SQL database content",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"directus",
|
|
@@ -148,30 +148,30 @@
|
|
|
148
148
|
"wellknown": "0.5.0",
|
|
149
149
|
"ws": "8.18.0",
|
|
150
150
|
"zod": "3.23.8",
|
|
151
|
-
"zod-validation-error": "3.3.
|
|
152
|
-
"@directus/app": "
|
|
153
|
-
"@directus/
|
|
154
|
-
"@directus/
|
|
155
|
-
"@directus/
|
|
156
|
-
"@directus/extensions": "
|
|
157
|
-
"@directus/extensions-registry": "
|
|
158
|
-
"@directus/
|
|
159
|
-
"@directus/
|
|
160
|
-
"@directus/
|
|
161
|
-
"@directus/
|
|
162
|
-
"@directus/
|
|
163
|
-
"@directus/specs": "
|
|
164
|
-
"@directus/storage": "
|
|
165
|
-
"@directus/storage
|
|
166
|
-
"@directus/storage-driver-
|
|
167
|
-
"@directus/storage-driver-gcs": "
|
|
168
|
-
"@directus/storage-driver-local": "
|
|
169
|
-
"@directus/storage-driver-supabase": "
|
|
170
|
-
"@directus/
|
|
171
|
-
"@directus/
|
|
172
|
-
"@directus/validation": "0.0
|
|
173
|
-
"
|
|
174
|
-
"directus": "
|
|
151
|
+
"zod-validation-error": "3.3.1",
|
|
152
|
+
"@directus/app": "13.0.1",
|
|
153
|
+
"@directus/constants": "12.0.0",
|
|
154
|
+
"@directus/env": "3.0.0",
|
|
155
|
+
"@directus/errors": "1.0.0",
|
|
156
|
+
"@directus/extensions": "2.0.0",
|
|
157
|
+
"@directus/extensions-registry": "2.0.0",
|
|
158
|
+
"@directus/format-title": "11.0.0",
|
|
159
|
+
"@directus/memory": "2.0.0",
|
|
160
|
+
"@directus/pressure": "2.0.0",
|
|
161
|
+
"@directus/schema": "12.0.0",
|
|
162
|
+
"@directus/extensions-sdk": "12.0.0",
|
|
163
|
+
"@directus/specs": "11.0.0",
|
|
164
|
+
"@directus/storage-driver-azure": "11.0.0",
|
|
165
|
+
"@directus/storage": "11.0.0",
|
|
166
|
+
"@directus/storage-driver-cloudinary": "11.0.0",
|
|
167
|
+
"@directus/storage-driver-gcs": "11.0.0",
|
|
168
|
+
"@directus/storage-driver-local": "11.0.0",
|
|
169
|
+
"@directus/storage-driver-supabase": "2.0.0",
|
|
170
|
+
"@directus/system-data": "2.0.0",
|
|
171
|
+
"@directus/storage-driver-s3": "11.0.0",
|
|
172
|
+
"@directus/validation": "1.0.0",
|
|
173
|
+
"directus": "11.0.1",
|
|
174
|
+
"@directus/utils": "12.0.0"
|
|
175
175
|
},
|
|
176
176
|
"devDependencies": {
|
|
177
177
|
"@ngneat/falso": "7.2.0",
|
|
@@ -212,13 +212,13 @@
|
|
|
212
212
|
"knex-mock-client": "2.0.1",
|
|
213
213
|
"typescript": "5.4.5",
|
|
214
214
|
"vitest": "1.5.3",
|
|
215
|
-
"@directus/
|
|
216
|
-
"@directus/
|
|
217
|
-
"@directus/types": "
|
|
215
|
+
"@directus/random": "1.0.0",
|
|
216
|
+
"@directus/tsconfig": "2.0.0",
|
|
217
|
+
"@directus/types": "12.0.0"
|
|
218
218
|
},
|
|
219
219
|
"optionalDependencies": {
|
|
220
220
|
"@keyv/redis": "2.8.5",
|
|
221
|
-
"
|
|
221
|
+
"mysql2": "3.10.0",
|
|
222
222
|
"nodemailer-mailgun-transport": "2.1.5",
|
|
223
223
|
"nodemailer-sendgrid": "1.0.3",
|
|
224
224
|
"oracledb": "6.5.1",
|
|
@@ -233,6 +233,7 @@
|
|
|
233
233
|
"build": "tsc --project tsconfig.prod.json && copyfiles \"src/**/*.{yaml,liquid}\" -u 1 dist",
|
|
234
234
|
"cli": "NODE_ENV=development SERVE_APP=false tsx src/cli/run.ts",
|
|
235
235
|
"dev": "NODE_ENV=development SERVE_APP=true tsx watch --ignore extensions --clear-screen=false src/start.ts",
|
|
236
|
-
"test": "vitest
|
|
236
|
+
"test": "vitest run",
|
|
237
|
+
"test:watch": "vitest"
|
|
237
238
|
}
|
|
238
239
|
}
|