directus 9.23.1 → 9.23.4
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 +25 -21
- package/dist/auth/auth.d.ts +3 -3
- package/dist/auth/auth.js +2 -0
- package/dist/auth/drivers/ldap.d.ts +1 -1
- package/dist/auth/drivers/ldap.js +57 -46
- package/dist/auth/drivers/local.d.ts +1 -1
- package/dist/auth/drivers/local.js +20 -17
- package/dist/auth/drivers/oauth2.d.ts +1 -1
- package/dist/auth/drivers/oauth2.js +44 -35
- package/dist/auth/drivers/openid.d.ts +1 -1
- package/dist/auth/drivers/openid.js +50 -41
- package/dist/auth/drivers/saml.d.ts +1 -1
- package/dist/auth/drivers/saml.js +20 -17
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +8 -7
- package/dist/cache.d.ts +9 -1
- package/dist/cache.js +66 -18
- package/dist/cli/commands/bootstrap/index.js +7 -6
- package/dist/cli/commands/init/index.js +3 -3
- package/dist/cli/commands/schema/apply.js +14 -15
- package/dist/cli/commands/schema/snapshot.js +2 -2
- package/dist/cli/utils/create-db-connection.d.ts +1 -1
- package/dist/cli/utils/create-db-connection.js +3 -2
- package/dist/cli/utils/create-env/index.d.ts +2 -2
- package/dist/cli/utils/create-env/index.js +1 -1
- package/dist/cli/utils/drivers.d.ts +1 -1
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +7 -7
- package/dist/controllers/activity.js +10 -11
- package/dist/controllers/assets.js +31 -25
- package/dist/controllers/auth.js +40 -26
- package/dist/controllers/collections.js +10 -10
- package/dist/controllers/dashboards.js +14 -11
- package/dist/controllers/extensions.js +3 -3
- package/dist/controllers/fields.js +20 -20
- package/dist/controllers/files.js +26 -20
- package/dist/controllers/flows.js +16 -13
- package/dist/controllers/folders.js +14 -11
- package/dist/controllers/graphql.js +6 -8
- package/dist/controllers/items.js +22 -19
- package/dist/controllers/not-found.d.ts +1 -1
- package/dist/controllers/not-found.js +1 -2
- package/dist/controllers/notifications.js +14 -11
- package/dist/controllers/operations.js +14 -11
- package/dist/controllers/panels.js +14 -11
- package/dist/controllers/permissions.js +14 -11
- package/dist/controllers/presets.js +14 -11
- package/dist/controllers/relations.js +10 -10
- package/dist/controllers/revisions.js +3 -3
- package/dist/controllers/roles.js +14 -11
- package/dist/controllers/schema.js +5 -5
- package/dist/controllers/server.js +7 -7
- package/dist/controllers/settings.js +2 -2
- package/dist/controllers/shares.js +21 -18
- package/dist/controllers/users.js +32 -36
- package/dist/controllers/utils.js +10 -15
- package/dist/controllers/webhooks.js +14 -11
- package/dist/database/helpers/fn/dialects/mssql.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/mssql.js +10 -11
- package/dist/database/helpers/fn/dialects/mysql.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/mysql.js +2 -3
- package/dist/database/helpers/fn/dialects/oracle.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/oracle.js +10 -11
- package/dist/database/helpers/fn/dialects/postgres.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/postgres.js +10 -11
- package/dist/database/helpers/fn/dialects/sqlite.d.ts +1 -1
- package/dist/database/helpers/fn/dialects/sqlite.js +10 -11
- package/dist/database/helpers/fn/types.d.ts +5 -6
- package/dist/database/helpers/fn/types.js +4 -5
- package/dist/database/helpers/geometry/dialects/mssql.d.ts +3 -3
- package/dist/database/helpers/geometry/dialects/mysql.d.ts +1 -1
- package/dist/database/helpers/geometry/dialects/oracle.d.ts +3 -3
- package/dist/database/helpers/geometry/dialects/postgres.d.ts +3 -3
- package/dist/database/helpers/geometry/dialects/postgres.js +1 -2
- package/dist/database/helpers/geometry/dialects/redshift.d.ts +2 -2
- package/dist/database/helpers/geometry/dialects/sqlite.d.ts +1 -1
- package/dist/database/helpers/geometry/types.d.ts +2 -2
- package/dist/database/helpers/geometry/types.js +1 -2
- package/dist/database/helpers/index.d.ts +5 -5
- package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mssql.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mysql.d.ts +1 -1
- package/dist/database/helpers/schema/dialects/mysql.js +1 -2
- package/dist/database/helpers/schema/dialects/oracle.d.ts +2 -2
- package/dist/database/helpers/schema/dialects/oracle.js +4 -6
- package/dist/database/helpers/schema/types.d.ts +4 -4
- package/dist/database/helpers/types.d.ts +1 -1
- package/dist/database/helpers/types.js +1 -0
- package/dist/database/index.d.ts +1 -1
- package/dist/database/index.js +13 -13
- package/dist/database/migrations/20201028A-remove-collection-foreign-keys.d.ts +1 -1
- package/dist/database/migrations/20201029A-remove-system-relations.d.ts +1 -1
- package/dist/database/migrations/20201029B-remove-system-collections.d.ts +1 -1
- package/dist/database/migrations/20201029C-remove-system-fields.d.ts +1 -1
- package/dist/database/migrations/20201105A-add-cascade-system-relations.d.ts +1 -1
- package/dist/database/migrations/20201105B-change-webhook-url-type.d.ts +1 -1
- package/dist/database/migrations/20210225A-add-relations-sort-field.d.ts +1 -1
- package/dist/database/migrations/20210225A-add-relations-sort-field.js +1 -2
- package/dist/database/migrations/20210304A-remove-locked-fields.d.ts +1 -1
- package/dist/database/migrations/20210312A-webhooks-collections-text.d.ts +1 -1
- package/dist/database/migrations/20210331A-add-refresh-interval.d.ts +1 -1
- package/dist/database/migrations/20210415A-make-filesize-nullable.d.ts +1 -1
- package/dist/database/migrations/20210416A-add-collections-accountability.d.ts +1 -1
- package/dist/database/migrations/20210422A-remove-files-interface.d.ts +1 -1
- package/dist/database/migrations/20210506A-rename-interfaces.d.ts +1 -1
- package/dist/database/migrations/20210510A-restructure-relations.d.ts +1 -1
- package/dist/database/migrations/20210518A-add-foreign-key-constraints.d.ts +1 -1
- package/dist/database/migrations/20210518A-add-foreign-key-constraints.js +1 -1
- package/dist/database/migrations/20210519A-add-system-fk-triggers.d.ts +1 -1
- package/dist/database/migrations/20210519A-add-system-fk-triggers.js +2 -2
- package/dist/database/migrations/20210521A-add-collections-icon-color.d.ts +1 -1
- package/dist/database/migrations/20210525A-add-insights.d.ts +1 -1
- package/dist/database/migrations/20210608A-add-deep-clone-config.d.ts +1 -1
- package/dist/database/migrations/20210626A-change-filesize-bigint.d.ts +1 -1
- package/dist/database/migrations/20210716A-add-conditions-to-fields.d.ts +1 -1
- package/dist/database/migrations/20210721A-add-default-folder.d.ts +1 -1
- package/dist/database/migrations/20210802A-replace-groups.d.ts +1 -1
- package/dist/database/migrations/20210803A-add-required-to-fields.d.ts +1 -1
- package/dist/database/migrations/20210805A-update-groups.d.ts +1 -1
- package/dist/database/migrations/20210805B-change-image-metadata-structure.d.ts +1 -1
- package/dist/database/migrations/20210805B-change-image-metadata-structure.js +15 -15
- package/dist/database/migrations/20210811A-add-geometry-config.d.ts +1 -1
- package/dist/database/migrations/20210831A-remove-limit-column.d.ts +1 -1
- package/dist/database/migrations/20210903A-add-auth-provider.d.ts +1 -1
- package/dist/database/migrations/20210907A-webhooks-collections-not-null.d.ts +1 -1
- package/dist/database/migrations/20210910A-move-module-setup.d.ts +1 -1
- package/dist/database/migrations/20210920A-webhooks-url-not-null.d.ts +1 -1
- package/dist/database/migrations/20210924A-add-collection-organization.d.ts +1 -1
- package/dist/database/migrations/20210927A-replace-fields-group.d.ts +1 -1
- package/dist/database/migrations/20210927B-replace-m2m-interface.d.ts +1 -1
- package/dist/database/migrations/20210929A-rename-login-action.d.ts +1 -1
- package/dist/database/migrations/20211007A-update-presets.d.ts +1 -1
- package/dist/database/migrations/20211007A-update-presets.js +7 -9
- package/dist/database/migrations/20211009A-add-auth-data.d.ts +1 -1
- package/dist/database/migrations/20211016A-add-webhook-headers.d.ts +1 -1
- package/dist/database/migrations/20211103A-set-unique-to-user-token.d.ts +1 -1
- package/dist/database/migrations/20211103B-update-special-geometry.d.ts +1 -1
- package/dist/database/migrations/20211104A-remove-collections-listing.d.ts +1 -1
- package/dist/database/migrations/20211118A-add-notifications.d.ts +1 -1
- package/dist/database/migrations/20211211A-add-shares.d.ts +1 -1
- package/dist/database/migrations/20211230A-add-project-descriptor.d.ts +1 -1
- package/dist/database/migrations/20220303A-remove-default-project-color.d.ts +1 -1
- package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.d.ts +1 -1
- package/dist/database/migrations/20220314A-add-translation-strings.d.ts +1 -1
- package/dist/database/migrations/20220322A-rename-field-typecast-flags.d.ts +1 -1
- package/dist/database/migrations/20220323A-add-field-validation.d.ts +1 -1
- package/dist/database/migrations/20220325A-fix-typecast-flags.d.ts +1 -1
- package/dist/database/migrations/20220325B-add-default-language.d.ts +1 -1
- package/dist/database/migrations/20220402A-remove-default-value-panel-icon.d.ts +1 -1
- package/dist/database/migrations/20220429A-add-flows.d.ts +1 -1
- package/dist/database/migrations/20220429B-add-color-to-insights-icon.d.ts +1 -1
- package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.d.ts +1 -1
- package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.d.ts +1 -1
- package/dist/database/migrations/20220614A-rename-hook-trigger-to-event.d.ts +1 -1
- package/dist/database/migrations/20220801A-update-notifications-timestamp-column.d.ts +1 -1
- package/dist/database/migrations/20220802A-add-custom-aspect-ratios.d.ts +1 -1
- package/dist/database/migrations/20220826A-add-origin-to-accountability.d.ts +1 -1
- package/dist/database/migrations/run.d.ts +1 -1
- package/dist/database/migrations/run.js +1 -1
- package/dist/database/run-ast.d.ts +3 -3
- package/dist/database/run-ast.js +21 -30
- package/dist/database/seeds/run.d.ts +1 -1
- package/dist/database/seeds/run.js +1 -2
- package/dist/database/system-data/app-access-permissions/index.d.ts +1 -1
- package/dist/database/system-data/collections/index.d.ts +1 -1
- package/dist/database/system-data/collections/index.js +2 -2
- package/dist/database/system-data/fields/collections.yaml +2 -0
- package/dist/database/system-data/fields/index.d.ts +1 -1
- package/dist/database/system-data/fields/index.js +3 -4
- package/dist/database/system-data/fields/settings.yaml +4 -0
- package/dist/database/system-data/relations/index.d.ts +1 -1
- package/dist/emitter.d.ts +1 -1
- package/dist/emitter.js +3 -0
- package/dist/env.js +11 -3
- package/dist/exceptions/database/dialects/mssql.d.ts +1 -1
- package/dist/exceptions/database/dialects/mssql.js +5 -6
- package/dist/exceptions/database/dialects/mysql.d.ts +1 -1
- package/dist/exceptions/database/dialects/mysql.js +19 -25
- package/dist/exceptions/database/dialects/oracle.d.ts +1 -1
- package/dist/exceptions/database/dialects/postgres.d.ts +1 -1
- package/dist/exceptions/database/dialects/sqlite.d.ts +1 -1
- package/dist/exceptions/database/translate.d.ts +1 -1
- package/dist/exceptions/database/value-out-of-range.js +1 -1
- package/dist/exceptions/range-not-satisfiable.js +2 -3
- package/dist/extensions.d.ts +1 -1
- package/dist/extensions.js +43 -33
- package/dist/flows.js +65 -46
- package/dist/logger.d.ts +2 -1
- package/dist/logger.js +35 -19
- package/dist/logger.test.d.ts +1 -0
- package/dist/mailer.js +16 -16
- package/dist/messenger.js +9 -7
- package/dist/middleware/authenticate.d.ts +1 -1
- package/dist/middleware/authenticate.js +13 -6
- package/dist/middleware/cache.d.ts +1 -1
- package/dist/middleware/cache.js +16 -16
- package/dist/middleware/check-ip.d.ts +1 -1
- package/dist/middleware/check-ip.js +1 -1
- package/dist/middleware/collection-exists.d.ts +1 -1
- package/dist/middleware/collection-exists.js +5 -5
- package/dist/middleware/cors.d.ts +1 -1
- package/dist/middleware/cors.js +7 -7
- package/dist/middleware/error-handler.d.ts +1 -1
- package/dist/middleware/error-handler.js +11 -12
- package/dist/middleware/extract-token.d.ts +1 -1
- package/dist/middleware/extract-token.js +2 -2
- package/dist/middleware/get-permissions.d.ts +1 -1
- package/dist/middleware/graphql.d.ts +1 -1
- package/dist/middleware/graphql.js +15 -9
- package/dist/middleware/rate-limiter-global.d.ts +5 -0
- package/dist/middleware/rate-limiter-global.js +48 -0
- package/dist/middleware/{rate-limiter.d.ts → rate-limiter-ip.d.ts} +2 -2
- package/dist/middleware/{rate-limiter.js → rate-limiter-ip.js} +5 -5
- package/dist/middleware/respond.d.ts +1 -1
- package/dist/middleware/respond.js +18 -19
- package/dist/middleware/sanitize-query.d.ts +1 -1
- package/dist/middleware/sanitize-query.js +1 -1
- package/dist/middleware/schema.d.ts +1 -1
- package/dist/middleware/use-collection.d.ts +1 -1
- package/dist/operations/condition/index.d.ts +1 -1
- package/dist/operations/exec/index.js +15 -4
- package/dist/operations/item-create/index.js +1 -2
- package/dist/operations/item-delete/index.d.ts +1 -1
- package/dist/operations/item-read/index.d.ts +1 -1
- package/dist/operations/item-update/index.d.ts +1 -1
- package/dist/operations/item-update/index.js +1 -2
- package/dist/operations/notification/index.js +1 -2
- package/dist/operations/request/index.js +19 -19
- package/dist/operations/trigger/index.js +2 -3
- package/dist/rate-limiter.d.ts +1 -1
- package/dist/rate-limiter.js +9 -9
- package/dist/request/validate-ip.js +2 -2
- package/dist/server.js +12 -13
- package/dist/services/activity.d.ts +1 -1
- package/dist/services/activity.js +17 -16
- package/dist/services/assets.d.ts +3 -3
- package/dist/services/assets.js +35 -37
- package/dist/services/authentication.d.ts +2 -2
- package/dist/services/authentication.js +22 -19
- package/dist/services/authorization.d.ts +3 -3
- package/dist/services/authorization.js +27 -31
- package/dist/services/collections.d.ts +5 -5
- package/dist/services/collections.js +54 -50
- package/dist/services/dashboards.d.ts +1 -1
- package/dist/services/fields.d.ts +5 -5
- package/dist/services/fields.js +50 -50
- package/dist/services/files.d.ts +1 -2
- package/dist/services/files.js +33 -27
- package/dist/services/flows.d.ts +2 -2
- package/dist/services/folders.d.ts +1 -1
- package/dist/services/graphql/index.d.ts +4 -4
- package/dist/services/graphql/index.js +259 -252
- package/dist/services/graphql/utils/add-path-to-validation-error.js +1 -2
- package/dist/services/graphql/utils/process-error.d.ts +2 -2
- package/dist/services/graphql/utils/process-error.js +11 -4
- package/dist/services/import-export.d.ts +3 -3
- package/dist/services/import-export.js +30 -27
- package/dist/services/items.d.ts +3 -3
- package/dist/services/items.js +42 -36
- package/dist/services/mail/index.d.ts +4 -4
- package/dist/services/mail/index.js +14 -10
- package/dist/services/meta.d.ts +3 -3
- package/dist/services/meta.js +11 -9
- package/dist/services/notifications.d.ts +3 -3
- package/dist/services/notifications.js +10 -9
- package/dist/services/operations.d.ts +2 -2
- package/dist/services/panels.d.ts +1 -1
- package/dist/services/payload.d.ts +3 -3
- package/dist/services/payload.js +124 -122
- package/dist/services/permissions.d.ts +3 -3
- package/dist/services/permissions.js +11 -11
- package/dist/services/presets.d.ts +1 -1
- package/dist/services/relations.d.ts +6 -6
- package/dist/services/relations.js +45 -43
- package/dist/services/revisions.d.ts +1 -1
- package/dist/services/revisions.js +3 -3
- package/dist/services/roles.d.ts +2 -2
- package/dist/services/roles.js +7 -7
- package/dist/services/schema.d.ts +3 -3
- package/dist/services/schema.js +9 -11
- package/dist/services/server.d.ts +3 -3
- package/dist/services/server.js +88 -32
- package/dist/services/settings.d.ts +1 -1
- package/dist/services/shares.d.ts +1 -1
- package/dist/services/shares.js +14 -15
- package/dist/services/specifications.d.ts +4 -4
- package/dist/services/specifications.js +137 -119
- package/dist/services/tfa.d.ts +2 -2
- package/dist/services/tfa.js +7 -5
- package/dist/services/users.d.ts +2 -6
- package/dist/services/users.js +37 -40
- package/dist/services/utils.d.ts +3 -3
- package/dist/services/utils.js +10 -8
- package/dist/services/webhooks.d.ts +2 -2
- package/dist/services/webhooks.js +2 -1
- package/dist/storage/register-locations.js +1 -1
- package/dist/types/assets.d.ts +1 -1
- package/dist/types/ast.d.ts +1 -1
- package/dist/types/auth.d.ts +2 -2
- package/dist/types/collection.d.ts +2 -2
- package/dist/types/events.d.ts +2 -2
- package/dist/types/graphql.d.ts +2 -2
- package/dist/types/items.d.ts +3 -3
- package/dist/types/services.d.ts +5 -5
- package/dist/types/snapshot.d.ts +4 -4
- package/dist/utils/apply-diff.d.ts +3 -3
- package/dist/utils/apply-diff.js +25 -28
- package/dist/utils/apply-query.d.ts +3 -3
- package/dist/utils/apply-query.js +10 -12
- package/dist/utils/apply-snapshot.d.ts +3 -3
- package/dist/utils/apply-snapshot.js +5 -6
- package/dist/utils/construct-flow-tree.d.ts +1 -1
- package/dist/utils/construct-flow-tree.js +2 -2
- package/dist/utils/dynamic-import.js +1 -1
- package/dist/utils/filter-items.d.ts +1 -1
- package/dist/utils/generate-hash.js +1 -1
- package/dist/utils/get-accountability-for-role.d.ts +2 -2
- package/dist/utils/get-accountability-for-role.js +1 -1
- package/dist/utils/get-ast-from-query.d.ts +3 -3
- package/dist/utils/get-ast-from-query.js +22 -28
- package/dist/utils/get-auth-providers.js +1 -1
- package/dist/utils/get-cache-headers.d.ts +1 -1
- package/dist/utils/get-cache-headers.js +6 -7
- package/dist/utils/get-cache-key.d.ts +1 -1
- package/dist/utils/get-cache-key.js +2 -3
- package/dist/utils/get-collection-from-alias.d.ts +1 -1
- package/dist/utils/get-collection-from-alias.js +1 -0
- package/dist/utils/get-column-path.d.ts +2 -2
- package/dist/utils/get-column-path.js +3 -4
- package/dist/utils/get-column.d.ts +4 -4
- package/dist/utils/get-column.js +4 -5
- package/dist/utils/get-default-value.d.ts +2 -2
- package/dist/utils/get-default-value.js +2 -3
- package/dist/utils/get-graphql-query-and-variables.d.ts +1 -1
- package/dist/utils/get-graphql-query-and-variables.js +1 -2
- package/dist/utils/get-graphql-type.d.ts +2 -2
- package/dist/utils/get-graphql-type.js +1 -1
- package/dist/utils/get-ip-from-req.d.ts +1 -1
- package/dist/utils/get-ip-from-req.js +2 -2
- package/dist/utils/get-local-type.d.ts +1 -1
- package/dist/utils/get-local-type.js +3 -3
- package/dist/utils/get-milliseconds.js +1 -2
- package/dist/utils/get-permissions.d.ts +1 -1
- package/dist/utils/get-permissions.js +12 -12
- package/dist/utils/get-relation-info.d.ts +1 -1
- package/dist/utils/get-relation-info.js +3 -5
- package/dist/utils/get-relation-type.d.ts +1 -1
- package/dist/utils/get-relation-type.js +3 -4
- package/dist/utils/get-schema.d.ts +2 -2
- package/dist/utils/get-schema.js +20 -22
- package/dist/utils/get-snapshot-diff.js +2 -3
- package/dist/utils/get-snapshot.d.ts +3 -3
- package/dist/utils/get-snapshot.js +6 -8
- package/dist/utils/is-directus-jwt.js +1 -1
- package/dist/utils/is-url-allowed.js +5 -2
- package/dist/utils/job-queue.js +2 -0
- package/dist/utils/jwt.d.ts +1 -1
- package/dist/utils/merge-permissions-for-share.d.ts +1 -1
- package/dist/utils/merge-permissions-for-share.js +3 -4
- package/dist/utils/merge-permissions.d.ts +3 -3
- package/dist/utils/reduce-schema.d.ts +1 -1
- package/dist/utils/reduce-schema.js +12 -12
- package/dist/utils/sanitize-query.d.ts +1 -1
- package/dist/utils/sanitize-query.js +27 -27
- package/dist/utils/sanitize-schema.d.ts +2 -2
- package/dist/utils/should-skip-cache.d.ts +7 -0
- package/dist/utils/should-skip-cache.js +21 -0
- package/dist/utils/should-skip-cache.test.d.ts +1 -0
- package/dist/utils/track.js +16 -16
- package/dist/utils/transformations.d.ts +1 -1
- package/dist/utils/transformations.js +2 -4
- package/dist/utils/url.js +7 -2
- package/dist/utils/user-name.d.ts +1 -1
- package/dist/utils/validate-diff.js +7 -8
- package/dist/utils/validate-keys.d.ts +2 -2
- package/dist/utils/validate-keys.js +1 -1
- package/dist/utils/validate-query.d.ts +1 -1
- package/dist/utils/validate-query.js +3 -3
- package/dist/utils/validate-storage.js +8 -8
- package/dist/webhooks.js +3 -3
- package/package.json +36 -37
- package/dist/utils/with-timeout.d.ts +0 -1
- package/dist/utils/with-timeout.js +0 -16
|
@@ -27,19 +27,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.RelationsService = void 0;
|
|
30
|
-
const relations_1 = require("../database/system-data/relations");
|
|
31
|
-
const exceptions_1 = require("../exceptions");
|
|
32
|
-
const utils_1 = require("@directus/shared/utils");
|
|
33
|
-
const items_1 = require("./items");
|
|
34
|
-
const permissions_1 = require("./permissions");
|
|
35
30
|
const schema_1 = __importDefault(require("@directus/schema"));
|
|
36
|
-
const
|
|
37
|
-
const get_default_index_name_1 = require("../utils/get-default-index-name");
|
|
31
|
+
const utils_1 = require("@directus/shared/utils");
|
|
38
32
|
const cache_1 = require("../cache");
|
|
33
|
+
const database_1 = __importStar(require("../database"));
|
|
39
34
|
const helpers_1 = require("../database/helpers");
|
|
35
|
+
const relations_1 = require("../database/system-data/relations");
|
|
40
36
|
const emitter_1 = __importDefault(require("../emitter"));
|
|
37
|
+
const exceptions_1 = require("../exceptions");
|
|
38
|
+
const get_default_index_name_1 = require("../utils/get-default-index-name");
|
|
41
39
|
const get_schema_1 = require("../utils/get-schema");
|
|
40
|
+
const items_1 = require("./items");
|
|
41
|
+
const permissions_1 = require("./permissions");
|
|
42
42
|
class RelationsService {
|
|
43
|
+
knex;
|
|
44
|
+
permissionsService;
|
|
45
|
+
schemaInspector;
|
|
46
|
+
accountability;
|
|
47
|
+
schema;
|
|
48
|
+
relationsItemService;
|
|
49
|
+
systemCache;
|
|
50
|
+
helpers;
|
|
43
51
|
constructor(options) {
|
|
44
52
|
this.knex = options.knex || (0, database_1.default)();
|
|
45
53
|
this.permissionsService = new permissions_1.PermissionsService(options);
|
|
@@ -83,12 +91,11 @@ class RelationsService {
|
|
|
83
91
|
return await this.filterForbidden(results);
|
|
84
92
|
}
|
|
85
93
|
async readOne(collection, field) {
|
|
86
|
-
var _a;
|
|
87
94
|
if (this.accountability && this.accountability.admin !== true) {
|
|
88
95
|
if (this.hasReadAccess === false) {
|
|
89
96
|
throw new exceptions_1.ForbiddenException();
|
|
90
97
|
}
|
|
91
|
-
const permissions =
|
|
98
|
+
const permissions = this.accountability.permissions?.find((permission) => {
|
|
92
99
|
return permission.action === 'read' && permission.collection === collection;
|
|
93
100
|
});
|
|
94
101
|
if (!permissions || !permissions.fields)
|
|
@@ -167,13 +174,12 @@ class RelationsService {
|
|
|
167
174
|
await this.knex.transaction(async (trx) => {
|
|
168
175
|
if (relation.related_collection) {
|
|
169
176
|
await trx.schema.alterTable(relation.collection, async (table) => {
|
|
170
|
-
var _a;
|
|
171
177
|
this.alterType(table, relation);
|
|
172
178
|
const constraintName = (0, get_default_index_name_1.getDefaultIndexName)('foreign', relation.collection, relation.field);
|
|
173
179
|
const builder = table
|
|
174
180
|
.foreign(relation.field, constraintName)
|
|
175
181
|
.references(`${relation.related_collection}.${this.schema.collections[relation.related_collection].primary}`);
|
|
176
|
-
if (
|
|
182
|
+
if (relation.schema?.on_delete) {
|
|
177
183
|
builder.onDelete(relation.schema.on_delete);
|
|
178
184
|
}
|
|
179
185
|
});
|
|
@@ -186,7 +192,7 @@ class RelationsService {
|
|
|
186
192
|
// happens in `filterForbidden` down below
|
|
187
193
|
});
|
|
188
194
|
await relationsItemService.createOne(metaRow, {
|
|
189
|
-
bypassEmitAction: (params) =>
|
|
195
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
190
196
|
});
|
|
191
197
|
});
|
|
192
198
|
}
|
|
@@ -194,10 +200,10 @@ class RelationsService {
|
|
|
194
200
|
if (runPostColumnChange) {
|
|
195
201
|
await this.helpers.schema.postColumnChange();
|
|
196
202
|
}
|
|
197
|
-
if (
|
|
198
|
-
await (0, cache_1.clearSystemCache)();
|
|
203
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
204
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
199
205
|
}
|
|
200
|
-
if (
|
|
206
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
201
207
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
202
208
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
203
209
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -232,10 +238,9 @@ class RelationsService {
|
|
|
232
238
|
await this.knex.transaction(async (trx) => {
|
|
233
239
|
if (existingRelation.related_collection) {
|
|
234
240
|
await trx.schema.alterTable(collection, async (table) => {
|
|
235
|
-
var _a;
|
|
236
241
|
let constraintName = (0, get_default_index_name_1.getDefaultIndexName)('foreign', collection, field);
|
|
237
242
|
// If the FK already exists in the DB, drop it first
|
|
238
|
-
if (existingRelation
|
|
243
|
+
if (existingRelation?.schema) {
|
|
239
244
|
constraintName = existingRelation.schema.constraint_name || constraintName;
|
|
240
245
|
table.dropForeign(field, constraintName);
|
|
241
246
|
constraintName = this.helpers.schema.constraintName(constraintName);
|
|
@@ -245,7 +250,7 @@ class RelationsService {
|
|
|
245
250
|
const builder = table
|
|
246
251
|
.foreign(field, constraintName || undefined)
|
|
247
252
|
.references(`${existingRelation.related_collection}.${this.schema.collections[existingRelation.related_collection].primary}`);
|
|
248
|
-
if (
|
|
253
|
+
if (relation.schema?.on_delete) {
|
|
249
254
|
builder.onDelete(relation.schema.on_delete);
|
|
250
255
|
}
|
|
251
256
|
});
|
|
@@ -258,9 +263,9 @@ class RelationsService {
|
|
|
258
263
|
// happens in `filterForbidden` down below
|
|
259
264
|
});
|
|
260
265
|
if (relation.meta) {
|
|
261
|
-
if (existingRelation
|
|
266
|
+
if (existingRelation?.meta) {
|
|
262
267
|
await relationsItemService.updateOne(existingRelation.meta.id, relation.meta, {
|
|
263
|
-
bypassEmitAction: (params) =>
|
|
268
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
264
269
|
});
|
|
265
270
|
}
|
|
266
271
|
else {
|
|
@@ -270,7 +275,7 @@ class RelationsService {
|
|
|
270
275
|
many_field: relation.field,
|
|
271
276
|
one_collection: existingRelation.related_collection || null,
|
|
272
277
|
}, {
|
|
273
|
-
bypassEmitAction: (params) =>
|
|
278
|
+
bypassEmitAction: (params) => opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
|
|
274
279
|
});
|
|
275
280
|
}
|
|
276
281
|
}
|
|
@@ -280,10 +285,10 @@ class RelationsService {
|
|
|
280
285
|
if (runPostColumnChange) {
|
|
281
286
|
await this.helpers.schema.postColumnChange();
|
|
282
287
|
}
|
|
283
|
-
if (
|
|
284
|
-
await (0, cache_1.clearSystemCache)();
|
|
288
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
289
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
285
290
|
}
|
|
286
|
-
if (
|
|
291
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
287
292
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
288
293
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
289
294
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -313,10 +318,9 @@ class RelationsService {
|
|
|
313
318
|
const nestedActionEvents = [];
|
|
314
319
|
try {
|
|
315
320
|
await this.knex.transaction(async (trx) => {
|
|
316
|
-
var _a;
|
|
317
321
|
const existingConstraints = await this.schemaInspector.foreignKeys();
|
|
318
322
|
const constraintNames = existingConstraints.map((key) => key.constraint_name);
|
|
319
|
-
if (
|
|
323
|
+
if (existingRelation.schema?.constraint_name &&
|
|
320
324
|
constraintNames.includes(existingRelation.schema.constraint_name)) {
|
|
321
325
|
await trx.schema.alterTable(existingRelation.collection, (table) => {
|
|
322
326
|
table.dropForeign(existingRelation.field, existingRelation.schema.constraint_name);
|
|
@@ -337,7 +341,7 @@ class RelationsService {
|
|
|
337
341
|
accountability: this.accountability,
|
|
338
342
|
},
|
|
339
343
|
};
|
|
340
|
-
if (opts
|
|
344
|
+
if (opts?.bypassEmitAction) {
|
|
341
345
|
opts.bypassEmitAction(actionEvent);
|
|
342
346
|
}
|
|
343
347
|
else {
|
|
@@ -349,10 +353,10 @@ class RelationsService {
|
|
|
349
353
|
if (runPostColumnChange) {
|
|
350
354
|
await this.helpers.schema.postColumnChange();
|
|
351
355
|
}
|
|
352
|
-
if (
|
|
353
|
-
await (0, cache_1.clearSystemCache)();
|
|
356
|
+
if (opts?.autoPurgeSystemCache !== false) {
|
|
357
|
+
await (0, cache_1.clearSystemCache)({ autoPurgeCache: opts?.autoPurgeCache });
|
|
354
358
|
}
|
|
355
|
-
if (
|
|
359
|
+
if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
|
|
356
360
|
const updatedSchema = await (0, get_schema_1.getSchema)();
|
|
357
361
|
for (const nestedActionEvent of nestedActionEvents) {
|
|
358
362
|
nestedActionEvent.context.schema = updatedSchema;
|
|
@@ -365,10 +369,9 @@ class RelationsService {
|
|
|
365
369
|
* Whether or not the current user has read access to relations
|
|
366
370
|
*/
|
|
367
371
|
get hasReadAccess() {
|
|
368
|
-
|
|
369
|
-
return !!((_b = (_a = this.accountability) === null || _a === void 0 ? void 0 : _a.permissions) === null || _b === void 0 ? void 0 : _b.find((permission) => {
|
|
372
|
+
return !!this.accountability?.permissions?.find((permission) => {
|
|
370
373
|
return permission.collection === 'directus_relations' && permission.action === 'read';
|
|
371
|
-
})
|
|
374
|
+
});
|
|
372
375
|
}
|
|
373
376
|
/**
|
|
374
377
|
* Combine raw schema foreign key information with Directus relations meta rows to form final
|
|
@@ -400,11 +403,10 @@ class RelationsService {
|
|
|
400
403
|
return !results.find((relation) => relation.meta === meta);
|
|
401
404
|
})
|
|
402
405
|
.map((meta) => {
|
|
403
|
-
var _a;
|
|
404
406
|
return {
|
|
405
407
|
collection: meta.many_collection,
|
|
406
408
|
field: meta.many_field,
|
|
407
|
-
related_collection:
|
|
409
|
+
related_collection: meta.one_collection ?? null,
|
|
408
410
|
schema: null,
|
|
409
411
|
meta: meta,
|
|
410
412
|
};
|
|
@@ -417,16 +419,16 @@ class RelationsService {
|
|
|
417
419
|
* permissions to
|
|
418
420
|
*/
|
|
419
421
|
async filterForbidden(relations) {
|
|
420
|
-
|
|
421
|
-
if (this.accountability === null || ((_a = this.accountability) === null || _a === void 0 ? void 0 : _a.admin) === true)
|
|
422
|
+
if (this.accountability === null || this.accountability?.admin === true)
|
|
422
423
|
return relations;
|
|
423
|
-
const allowedCollections =
|
|
424
|
+
const allowedCollections = this.accountability.permissions
|
|
425
|
+
?.filter((permission) => {
|
|
424
426
|
return permission.action === 'read';
|
|
425
|
-
})
|
|
427
|
+
})
|
|
428
|
+
.map(({ collection }) => collection) ?? [];
|
|
426
429
|
const allowedFields = this.permissionsService.getAllowedFields('read');
|
|
427
430
|
relations = (0, utils_1.toArray)(relations);
|
|
428
431
|
return relations.filter((relation) => {
|
|
429
|
-
var _a, _b, _c;
|
|
430
432
|
let collectionsAllowed = true;
|
|
431
433
|
let fieldsAllowed = true;
|
|
432
434
|
if (allowedCollections.includes(relation.collection) === false) {
|
|
@@ -435,8 +437,8 @@ class RelationsService {
|
|
|
435
437
|
if (relation.related_collection && allowedCollections.includes(relation.related_collection) === false) {
|
|
436
438
|
collectionsAllowed = false;
|
|
437
439
|
}
|
|
438
|
-
if (
|
|
439
|
-
|
|
440
|
+
if (relation.meta?.one_allowed_collections &&
|
|
441
|
+
relation.meta?.one_allowed_collections.every((collection) => allowedCollections.includes(collection)) === false) {
|
|
440
442
|
collectionsAllowed = false;
|
|
441
443
|
}
|
|
442
444
|
if (!allowedFields[relation.collection] ||
|
|
@@ -445,7 +447,7 @@ class RelationsService {
|
|
|
445
447
|
fieldsAllowed = false;
|
|
446
448
|
}
|
|
447
449
|
if (relation.related_collection &&
|
|
448
|
-
|
|
450
|
+
relation.meta?.one_field &&
|
|
449
451
|
(!allowedFields[relation.related_collection] ||
|
|
450
452
|
(allowedFields[relation.related_collection].includes('*') === false &&
|
|
451
453
|
allowedFields[relation.related_collection].includes(relation.meta.one_field) === false))) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractServiceOptions, PrimaryKey } from '../types';
|
|
1
|
+
import type { AbstractServiceOptions, PrimaryKey } from '../types';
|
|
2
2
|
import { ItemsService } from './index';
|
|
3
3
|
export declare class RevisionsService extends ItemsService {
|
|
4
4
|
constructor(options: AbstractServiceOptions);
|
|
@@ -11,14 +11,14 @@ class RevisionsService extends index_1.ItemsService {
|
|
|
11
11
|
const revision = await super.readOne(pk);
|
|
12
12
|
if (!revision)
|
|
13
13
|
throw new exceptions_1.ForbiddenException();
|
|
14
|
-
if (!revision
|
|
14
|
+
if (!revision['data'])
|
|
15
15
|
throw new exceptions_1.InvalidPayloadException(`Revision doesn't contain data to revert to`);
|
|
16
|
-
const service = new index_1.ItemsService(revision
|
|
16
|
+
const service = new index_1.ItemsService(revision['collection'], {
|
|
17
17
|
accountability: this.accountability,
|
|
18
18
|
knex: this.knex,
|
|
19
19
|
schema: this.schema,
|
|
20
20
|
});
|
|
21
|
-
await service.updateOne(revision
|
|
21
|
+
await service.updateOne(revision['item'], revision['data']);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.RevisionsService = RevisionsService;
|
package/dist/services/roles.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Query } from '@directus/shared/types';
|
|
2
|
+
import type { AbstractServiceOptions, MutationOptions, PrimaryKey } from '../types';
|
|
3
3
|
import { ItemsService } from './items';
|
|
4
4
|
export declare class RolesService extends ItemsService {
|
|
5
5
|
constructor(options: AbstractServiceOptions);
|
package/dist/services/roles.js
CHANGED
|
@@ -18,7 +18,7 @@ class RolesService extends items_1.ItemsService {
|
|
|
18
18
|
.whereNotIn('id', excludeKeys)
|
|
19
19
|
.andWhere({ admin_access: true })
|
|
20
20
|
.first();
|
|
21
|
-
const otherAdminRolesCount = +(
|
|
21
|
+
const otherAdminRolesCount = +(otherAdminRoles?.count || 0);
|
|
22
22
|
if (otherAdminRolesCount === 0)
|
|
23
23
|
throw new exceptions_1.UnprocessableEntityException(`You can't delete the last admin role.`);
|
|
24
24
|
}
|
|
@@ -29,10 +29,10 @@ class RolesService extends items_1.ItemsService {
|
|
|
29
29
|
// The users that will now be in this new non-admin role
|
|
30
30
|
let userKeys = [];
|
|
31
31
|
if (Array.isArray(users)) {
|
|
32
|
-
userKeys = users.map((user) => (typeof user === 'string' ? user : user
|
|
32
|
+
userKeys = users.map((user) => (typeof user === 'string' ? user : user['id'])).filter((id) => id);
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
userKeys = users.update.map((user) => user
|
|
35
|
+
userKeys = users.update.map((user) => user['id']).filter((id) => id);
|
|
36
36
|
}
|
|
37
37
|
const usersThatWereInRoleBefore = (await this.knex.select('id').from('directus_users').where('role', '=', key)).map((user) => user.id);
|
|
38
38
|
const usersThatAreRemoved = usersThatWereInRoleBefore.filter((id) => Array.isArray(users) ? userKeys.includes(id) === false : users.delete.includes(id) === true);
|
|
@@ -49,7 +49,7 @@ class RolesService extends items_1.ItemsService {
|
|
|
49
49
|
.andWhere({ 'directus_roles.admin_access': true })
|
|
50
50
|
.leftJoin('directus_roles', 'directus_users.role', 'directus_roles.id')
|
|
51
51
|
.first();
|
|
52
|
-
const otherAdminUsersCount = +(
|
|
52
|
+
const otherAdminUsersCount = +(otherAdminUsers?.count || 0);
|
|
53
53
|
if (otherAdminUsersCount === 0) {
|
|
54
54
|
throw new exceptions_1.UnprocessableEntityException(`You can't remove the last admin user from the admin role.`);
|
|
55
55
|
}
|
|
@@ -58,7 +58,7 @@ class RolesService extends items_1.ItemsService {
|
|
|
58
58
|
async updateOne(key, data, opts) {
|
|
59
59
|
try {
|
|
60
60
|
if ('users' in data) {
|
|
61
|
-
await this.checkForOtherAdminUsers(key, data
|
|
61
|
+
await this.checkForOtherAdminUsers(key, data['users']);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
catch (err) {
|
|
@@ -69,7 +69,7 @@ class RolesService extends items_1.ItemsService {
|
|
|
69
69
|
async updateBatch(data, opts) {
|
|
70
70
|
const primaryKeyField = this.schema.collections[this.collection].primary;
|
|
71
71
|
const keys = data.map((item) => item[primaryKeyField]);
|
|
72
|
-
const setsToNoAdmin = data.some((item) => item
|
|
72
|
+
const setsToNoAdmin = data.some((item) => item['admin_access'] === false);
|
|
73
73
|
try {
|
|
74
74
|
if (setsToNoAdmin) {
|
|
75
75
|
await this.checkForOtherAdminRoles(keys);
|
|
@@ -82,7 +82,7 @@ class RolesService extends items_1.ItemsService {
|
|
|
82
82
|
}
|
|
83
83
|
async updateMany(keys, data, opts) {
|
|
84
84
|
try {
|
|
85
|
-
if ('admin_access' in data && data
|
|
85
|
+
if ('admin_access' in data && data['admin_access'] === false) {
|
|
86
86
|
await this.checkForOtherAdminRoles(keys);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Accountability } from '@directus/shared/types';
|
|
2
|
-
import { Knex } from 'knex';
|
|
3
|
-
import { AbstractServiceOptions, Snapshot, SnapshotDiff, SnapshotDiffWithHash, SnapshotWithHash } from '../types';
|
|
1
|
+
import type { Accountability } from '@directus/shared/types';
|
|
2
|
+
import type { Knex } from 'knex';
|
|
3
|
+
import type { AbstractServiceOptions, Snapshot, SnapshotDiff, SnapshotDiffWithHash, SnapshotWithHash } from '../types';
|
|
4
4
|
export declare class SchemaService {
|
|
5
5
|
knex: Knex;
|
|
6
6
|
accountability: Accountability | null;
|
package/dist/services/schema.js
CHANGED
|
@@ -13,21 +13,20 @@ const get_versioned_hash_1 = require("../utils/get-versioned-hash");
|
|
|
13
13
|
const validate_diff_1 = require("../utils/validate-diff");
|
|
14
14
|
const validate_snapshot_1 = require("../utils/validate-snapshot");
|
|
15
15
|
class SchemaService {
|
|
16
|
+
knex;
|
|
17
|
+
accountability;
|
|
16
18
|
constructor(options) {
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
this.accountability = (_b = options.accountability) !== null && _b !== void 0 ? _b : null;
|
|
19
|
+
this.knex = options.knex ?? (0, database_1.default)();
|
|
20
|
+
this.accountability = options.accountability ?? null;
|
|
20
21
|
}
|
|
21
22
|
async snapshot() {
|
|
22
|
-
|
|
23
|
-
if (((_a = this.accountability) === null || _a === void 0 ? void 0 : _a.admin) !== true)
|
|
23
|
+
if (this.accountability?.admin !== true)
|
|
24
24
|
throw new exceptions_1.ForbiddenException();
|
|
25
25
|
const currentSnapshot = await (0, get_snapshot_1.getSnapshot)({ database: this.knex });
|
|
26
26
|
return currentSnapshot;
|
|
27
27
|
}
|
|
28
28
|
async apply(payload) {
|
|
29
|
-
|
|
30
|
-
if (((_a = this.accountability) === null || _a === void 0 ? void 0 : _a.admin) !== true)
|
|
29
|
+
if (this.accountability?.admin !== true)
|
|
31
30
|
throw new exceptions_1.ForbiddenException();
|
|
32
31
|
const currentSnapshot = await this.snapshot();
|
|
33
32
|
const snapshotWithHash = this.getHashedSnapshot(currentSnapshot);
|
|
@@ -36,11 +35,10 @@ class SchemaService {
|
|
|
36
35
|
await (0, apply_diff_1.applyDiff)(currentSnapshot, payload.diff, { database: this.knex });
|
|
37
36
|
}
|
|
38
37
|
async diff(snapshot, options) {
|
|
39
|
-
|
|
40
|
-
if (((_a = this.accountability) === null || _a === void 0 ? void 0 : _a.admin) !== true)
|
|
38
|
+
if (this.accountability?.admin !== true)
|
|
41
39
|
throw new exceptions_1.ForbiddenException();
|
|
42
|
-
(0, validate_snapshot_1.validateSnapshot)(snapshot, options
|
|
43
|
-
const currentSnapshot =
|
|
40
|
+
(0, validate_snapshot_1.validateSnapshot)(snapshot, options?.force);
|
|
41
|
+
const currentSnapshot = options?.currentSnapshot ?? (await (0, get_snapshot_1.getSnapshot)({ database: this.knex }));
|
|
44
42
|
const diff = (0, get_snapshot_diff_1.getSnapshotDiff)(currentSnapshot, snapshot);
|
|
45
43
|
if (diff.collections.length === 0 && diff.fields.length === 0 && diff.relations.length === 0) {
|
|
46
44
|
return null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Knex } from 'knex';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import type { Accountability, SchemaOverview } from '@directus/shared/types';
|
|
3
|
+
import type { AbstractServiceOptions } from '../types';
|
|
4
4
|
import { SettingsService } from './settings';
|
|
5
5
|
export declare class ServerService {
|
|
6
6
|
knex: Knex;
|
package/dist/services/server.js
CHANGED
|
@@ -30,20 +30,25 @@ exports.ServerService = void 0;
|
|
|
30
30
|
const lodash_1 = require("lodash");
|
|
31
31
|
const os_1 = __importDefault(require("os"));
|
|
32
32
|
const perf_hooks_1 = require("perf_hooks");
|
|
33
|
+
const utils_1 = require("@directus/shared/utils");
|
|
34
|
+
const node_stream_1 = require("node:stream");
|
|
33
35
|
// @ts-ignore
|
|
34
36
|
const package_json_1 = require("../../package.json");
|
|
35
37
|
const cache_1 = require("../cache");
|
|
36
38
|
const database_1 = __importStar(require("../database"));
|
|
37
39
|
const env_1 = __importDefault(require("../env"));
|
|
38
40
|
const logger_1 = __importDefault(require("../logger"));
|
|
39
|
-
const rate_limiter_1 = require("../middleware/rate-limiter");
|
|
40
|
-
const storage_1 = require("../storage");
|
|
41
|
-
const utils_1 = require("@directus/shared/utils");
|
|
42
41
|
const mailer_1 = __importDefault(require("../mailer"));
|
|
43
|
-
const
|
|
42
|
+
const rate_limiter_global_1 = require("../middleware/rate-limiter-global");
|
|
43
|
+
const rate_limiter_ip_1 = require("../middleware/rate-limiter-ip");
|
|
44
|
+
const storage_1 = require("../storage");
|
|
44
45
|
const get_os_info_1 = require("../utils/get-os-info");
|
|
45
|
-
const
|
|
46
|
+
const settings_1 = require("./settings");
|
|
46
47
|
class ServerService {
|
|
48
|
+
knex;
|
|
49
|
+
accountability;
|
|
50
|
+
settingsService;
|
|
51
|
+
schema;
|
|
47
52
|
constructor(options) {
|
|
48
53
|
this.knex = options.knex || (0, database_1.default)();
|
|
49
54
|
this.accountability = options.accountability || null;
|
|
@@ -51,7 +56,6 @@ class ServerService {
|
|
|
51
56
|
this.settingsService = new settings_1.SettingsService({ knex: this.knex, schema: this.schema });
|
|
52
57
|
}
|
|
53
58
|
async serverInfo() {
|
|
54
|
-
var _a, _b;
|
|
55
59
|
const info = {};
|
|
56
60
|
const projectInfo = await this.settingsService.readSingleton({
|
|
57
61
|
fields: [
|
|
@@ -66,31 +70,40 @@ class ServerService {
|
|
|
66
70
|
'custom_css',
|
|
67
71
|
],
|
|
68
72
|
});
|
|
69
|
-
info
|
|
70
|
-
if (
|
|
71
|
-
if (env_1.default
|
|
72
|
-
info
|
|
73
|
-
points: env_1.default
|
|
74
|
-
duration: env_1.default
|
|
73
|
+
info['project'] = projectInfo;
|
|
74
|
+
if (this.accountability?.user) {
|
|
75
|
+
if (env_1.default['RATE_LIMITER_ENABLED']) {
|
|
76
|
+
info['rateLimit'] = {
|
|
77
|
+
points: env_1.default['RATE_LIMITER_POINTS'],
|
|
78
|
+
duration: env_1.default['RATE_LIMITER_DURATION'],
|
|
75
79
|
};
|
|
76
80
|
}
|
|
77
81
|
else {
|
|
78
|
-
info
|
|
82
|
+
info['rateLimit'] = false;
|
|
79
83
|
}
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
if (env_1.default['RATE_LIMITER_GLOBAL_ENABLED']) {
|
|
85
|
+
info['rateLimitGlobal'] = {
|
|
86
|
+
points: env_1.default['RATE_LIMITER_GLOBAL_POINTS'],
|
|
87
|
+
duration: env_1.default['RATE_LIMITER_GLOBAL_DURATION'],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
info['rateLimitGlobal'] = false;
|
|
92
|
+
}
|
|
93
|
+
info['flows'] = {
|
|
94
|
+
execAllowedModules: env_1.default['FLOWS_EXEC_ALLOWED_MODULES'] ? (0, utils_1.toArray)(env_1.default['FLOWS_EXEC_ALLOWED_MODULES']) : [],
|
|
82
95
|
};
|
|
83
96
|
}
|
|
84
|
-
if (
|
|
97
|
+
if (this.accountability?.admin === true) {
|
|
85
98
|
const { osType, osVersion } = (0, get_os_info_1.getOSInfo)();
|
|
86
|
-
info
|
|
99
|
+
info['directus'] = {
|
|
87
100
|
version: package_json_1.version,
|
|
88
101
|
};
|
|
89
|
-
info
|
|
102
|
+
info['node'] = {
|
|
90
103
|
version: process.versions.node,
|
|
91
104
|
uptime: Math.round(process.uptime()),
|
|
92
105
|
};
|
|
93
|
-
info
|
|
106
|
+
info['os'] = {
|
|
94
107
|
type: osType,
|
|
95
108
|
version: osVersion,
|
|
96
109
|
uptime: Math.round(os_1.default.uptime()),
|
|
@@ -100,14 +113,20 @@ class ServerService {
|
|
|
100
113
|
return info;
|
|
101
114
|
}
|
|
102
115
|
async health() {
|
|
103
|
-
var _a;
|
|
104
116
|
const { nanoid } = await import('nanoid');
|
|
105
117
|
const checkID = nanoid(5);
|
|
106
118
|
const data = {
|
|
107
119
|
status: 'ok',
|
|
108
120
|
releaseId: package_json_1.version,
|
|
109
|
-
serviceId: env_1.default
|
|
110
|
-
checks: (0, lodash_1.merge)(...(await Promise.all([
|
|
121
|
+
serviceId: env_1.default['KEY'],
|
|
122
|
+
checks: (0, lodash_1.merge)(...(await Promise.all([
|
|
123
|
+
testDatabase(),
|
|
124
|
+
testCache(),
|
|
125
|
+
testRateLimiter(),
|
|
126
|
+
testRateLimiterGlobal(),
|
|
127
|
+
testStorage(),
|
|
128
|
+
testEmail(),
|
|
129
|
+
]))),
|
|
111
130
|
};
|
|
112
131
|
for (const [service, healthData] of Object.entries(data.checks)) {
|
|
113
132
|
for (const healthCheck of healthData) {
|
|
@@ -126,7 +145,7 @@ class ServerService {
|
|
|
126
145
|
if (data.status === 'error')
|
|
127
146
|
break;
|
|
128
147
|
}
|
|
129
|
-
if (
|
|
148
|
+
if (this.accountability?.admin !== true) {
|
|
130
149
|
return { status: data.status };
|
|
131
150
|
}
|
|
132
151
|
else {
|
|
@@ -134,7 +153,7 @@ class ServerService {
|
|
|
134
153
|
}
|
|
135
154
|
async function testDatabase() {
|
|
136
155
|
const database = (0, database_1.default)();
|
|
137
|
-
const client = env_1.default
|
|
156
|
+
const client = env_1.default['DB_CLIENT'];
|
|
138
157
|
const checks = {};
|
|
139
158
|
// Response time
|
|
140
159
|
// ----------------------------------------------------------------------------------------
|
|
@@ -144,7 +163,7 @@ class ServerService {
|
|
|
144
163
|
componentType: 'datastore',
|
|
145
164
|
observedUnit: 'ms',
|
|
146
165
|
observedValue: 0,
|
|
147
|
-
threshold: env_1.default
|
|
166
|
+
threshold: env_1.default['DB_HEALTHCHECK_THRESHOLD'] ? +env_1.default['DB_HEALTHCHECK_THRESHOLD'] : 150,
|
|
148
167
|
},
|
|
149
168
|
];
|
|
150
169
|
const startTime = perf_hooks_1.performance.now();
|
|
@@ -178,7 +197,7 @@ class ServerService {
|
|
|
178
197
|
return checks;
|
|
179
198
|
}
|
|
180
199
|
async function testCache() {
|
|
181
|
-
if (env_1.default
|
|
200
|
+
if (env_1.default['CACHE_ENABLED'] !== true) {
|
|
182
201
|
return {};
|
|
183
202
|
}
|
|
184
203
|
const { cache } = (0, cache_1.getCache)();
|
|
@@ -189,7 +208,7 @@ class ServerService {
|
|
|
189
208
|
componentType: 'cache',
|
|
190
209
|
observedValue: 0,
|
|
191
210
|
observedUnit: 'ms',
|
|
192
|
-
threshold: env_1.default
|
|
211
|
+
threshold: env_1.default['CACHE_HEALTHCHECK_THRESHOLD'] ? +env_1.default['CACHE_HEALTHCHECK_THRESHOLD'] : 150,
|
|
193
212
|
},
|
|
194
213
|
],
|
|
195
214
|
};
|
|
@@ -213,7 +232,7 @@ class ServerService {
|
|
|
213
232
|
return checks;
|
|
214
233
|
}
|
|
215
234
|
async function testRateLimiter() {
|
|
216
|
-
if (env_1.default
|
|
235
|
+
if (env_1.default['RATE_LIMITER_ENABLED'] !== true) {
|
|
217
236
|
return {};
|
|
218
237
|
}
|
|
219
238
|
const checks = {
|
|
@@ -223,14 +242,14 @@ class ServerService {
|
|
|
223
242
|
componentType: 'ratelimiter',
|
|
224
243
|
observedValue: 0,
|
|
225
244
|
observedUnit: 'ms',
|
|
226
|
-
threshold: env_1.default
|
|
245
|
+
threshold: env_1.default['RATE_LIMITER_HEALTHCHECK_THRESHOLD'] ? +env_1.default['RATE_LIMITER_HEALTHCHECK_THRESHOLD'] : 150,
|
|
227
246
|
},
|
|
228
247
|
],
|
|
229
248
|
};
|
|
230
249
|
const startTime = perf_hooks_1.performance.now();
|
|
231
250
|
try {
|
|
232
|
-
await
|
|
233
|
-
await
|
|
251
|
+
await rate_limiter_ip_1.rateLimiter.consume(`health-${checkID}`, 1);
|
|
252
|
+
await rate_limiter_ip_1.rateLimiter.delete(`health-${checkID}`);
|
|
234
253
|
}
|
|
235
254
|
catch (err) {
|
|
236
255
|
checks['rateLimiter:responseTime'][0].status = 'error';
|
|
@@ -246,10 +265,47 @@ class ServerService {
|
|
|
246
265
|
}
|
|
247
266
|
return checks;
|
|
248
267
|
}
|
|
268
|
+
async function testRateLimiterGlobal() {
|
|
269
|
+
if (env_1.default['RATE_LIMITER_GLOBAL_ENABLED'] !== true) {
|
|
270
|
+
return {};
|
|
271
|
+
}
|
|
272
|
+
const checks = {
|
|
273
|
+
'rateLimiterGlobal:responseTime': [
|
|
274
|
+
{
|
|
275
|
+
status: 'ok',
|
|
276
|
+
componentType: 'ratelimiter',
|
|
277
|
+
observedValue: 0,
|
|
278
|
+
observedUnit: 'ms',
|
|
279
|
+
threshold: env_1.default['RATE_LIMITER_GLOBAL_HEALTHCHECK_THRESHOLD']
|
|
280
|
+
? +env_1.default['RATE_LIMITER_GLOBAL_HEALTHCHECK_THRESHOLD']
|
|
281
|
+
: 150,
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
};
|
|
285
|
+
const startTime = perf_hooks_1.performance.now();
|
|
286
|
+
try {
|
|
287
|
+
await rate_limiter_global_1.rateLimiterGlobal.consume(`health-${checkID}`, 1);
|
|
288
|
+
await rate_limiter_global_1.rateLimiterGlobal.delete(`health-${checkID}`);
|
|
289
|
+
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
checks['rateLimiterGlobal:responseTime'][0].status = 'error';
|
|
292
|
+
checks['rateLimiterGlobal:responseTime'][0].output = err;
|
|
293
|
+
}
|
|
294
|
+
finally {
|
|
295
|
+
const endTime = perf_hooks_1.performance.now();
|
|
296
|
+
checks['rateLimiterGlobal:responseTime'][0].observedValue = +(endTime - startTime).toFixed(3);
|
|
297
|
+
if (checks['rateLimiterGlobal:responseTime'][0].observedValue >
|
|
298
|
+
checks['rateLimiterGlobal:responseTime'][0].threshold &&
|
|
299
|
+
checks['rateLimiterGlobal:responseTime'][0].status !== 'error') {
|
|
300
|
+
checks['rateLimiterGlobal:responseTime'][0].status = 'warn';
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return checks;
|
|
304
|
+
}
|
|
249
305
|
async function testStorage() {
|
|
250
306
|
const storage = await (0, storage_1.getStorage)();
|
|
251
307
|
const checks = {};
|
|
252
|
-
for (const location of (0, utils_1.toArray)(env_1.default
|
|
308
|
+
for (const location of (0, utils_1.toArray)(env_1.default['STORAGE_LOCATIONS'])) {
|
|
253
309
|
const disk = storage.location(location);
|
|
254
310
|
const envThresholdKey = `STORAGE_${location}_HEALTHCHECK_THRESHOLD`.toUpperCase();
|
|
255
311
|
checks[`storage:${location}:responseTime`] = [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractServiceOptions, Item, LoginResult, MutationOptions, PrimaryKey } from '../types';
|
|
1
|
+
import type { AbstractServiceOptions, Item, LoginResult, MutationOptions, PrimaryKey } from '../types';
|
|
2
2
|
import { AuthorizationService } from './authorization';
|
|
3
3
|
import { ItemsService } from './items';
|
|
4
4
|
export declare class SharesService extends ItemsService {
|