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
|
@@ -10,17 +10,17 @@ const collections_1 = require("../database/system-data/collections");
|
|
|
10
10
|
const exceptions_1 = require("../exceptions");
|
|
11
11
|
const async_handler_1 = __importDefault(require("../utils/async-handler"));
|
|
12
12
|
const collectionExists = (0, async_handler_1.default)(async (req, res, next) => {
|
|
13
|
-
if (!req.params
|
|
13
|
+
if (!req.params['collection'])
|
|
14
14
|
return next();
|
|
15
|
-
if (req.params
|
|
15
|
+
if (req.params['collection'] in req.schema.collections === false) {
|
|
16
16
|
throw new exceptions_1.ForbiddenException();
|
|
17
17
|
}
|
|
18
|
-
req.collection = req.params
|
|
18
|
+
req.collection = req.params['collection'];
|
|
19
19
|
if (req.collection.startsWith('directus_')) {
|
|
20
20
|
const systemRow = collections_1.systemCollectionRows.find((collection) => {
|
|
21
|
-
return
|
|
21
|
+
return collection?.collection === req.collection;
|
|
22
22
|
});
|
|
23
|
-
req.singleton = !!
|
|
23
|
+
req.singleton = !!systemRow?.singleton;
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
26
|
req.singleton = req.schema.collections[req.collection].singleton;
|
package/dist/middleware/cors.js
CHANGED
|
@@ -6,14 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const cors_1 = __importDefault(require("cors"));
|
|
7
7
|
const env_1 = __importDefault(require("../env"));
|
|
8
8
|
let corsMiddleware = (req, res, next) => next();
|
|
9
|
-
if (env_1.default
|
|
9
|
+
if (env_1.default['CORS_ENABLED'] === true) {
|
|
10
10
|
corsMiddleware = (0, cors_1.default)({
|
|
11
|
-
origin: env_1.default
|
|
12
|
-
methods: env_1.default
|
|
13
|
-
allowedHeaders: env_1.default
|
|
14
|
-
exposedHeaders: env_1.default
|
|
15
|
-
credentials: env_1.default
|
|
16
|
-
maxAge: env_1.default
|
|
11
|
+
origin: env_1.default['CORS_ORIGIN'] || true,
|
|
12
|
+
methods: env_1.default['CORS_METHODS'] || 'GET,POST,PATCH,DELETE',
|
|
13
|
+
allowedHeaders: env_1.default['CORS_ALLOWED_HEADERS'],
|
|
14
|
+
exposedHeaders: env_1.default['CORS_EXPOSED_HEADERS'],
|
|
15
|
+
credentials: env_1.default['CORS_CREDENTIALS'] || undefined,
|
|
16
|
+
maxAge: env_1.default['CORS_MAX_AGE'] || undefined,
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
exports.default = corsMiddleware;
|
|
@@ -3,22 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const exceptions_1 = require("@directus/shared/exceptions");
|
|
7
|
+
const utils_1 = require("@directus/shared/utils");
|
|
8
|
+
const database_1 = __importDefault(require("../database"));
|
|
6
9
|
const emitter_1 = __importDefault(require("../emitter"));
|
|
7
10
|
const env_1 = __importDefault(require("../env"));
|
|
8
|
-
const
|
|
9
|
-
const exceptions_2 = require("@directus/shared/exceptions");
|
|
11
|
+
const exceptions_2 = require("../exceptions");
|
|
10
12
|
const logger_1 = __importDefault(require("../logger"));
|
|
11
|
-
const utils_1 = require("@directus/shared/utils");
|
|
12
|
-
const database_1 = __importDefault(require("../database"));
|
|
13
13
|
// Note: keep all 4 parameters here. That's how Express recognizes it's the error handler, even if
|
|
14
14
|
// we don't use next
|
|
15
15
|
const errorHandler = (err, req, res, _next) => {
|
|
16
|
-
var _a, _b;
|
|
17
16
|
let payload = {
|
|
18
17
|
errors: [],
|
|
19
18
|
};
|
|
20
19
|
const errors = (0, utils_1.toArray)(err);
|
|
21
|
-
if (errors.some((err) => err instanceof
|
|
20
|
+
if (errors.some((err) => err instanceof exceptions_1.BaseException === false)) {
|
|
22
21
|
res.status(500);
|
|
23
22
|
}
|
|
24
23
|
else {
|
|
@@ -33,13 +32,13 @@ const errorHandler = (err, req, res, _next) => {
|
|
|
33
32
|
res.status(status);
|
|
34
33
|
}
|
|
35
34
|
for (const err of errors) {
|
|
36
|
-
if (env_1.default
|
|
35
|
+
if (env_1.default['NODE_ENV'] === 'development') {
|
|
37
36
|
err.extensions = {
|
|
38
37
|
...(err.extensions || {}),
|
|
39
38
|
stack: err.stack,
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
|
-
if (err instanceof
|
|
41
|
+
if (err instanceof exceptions_1.BaseException) {
|
|
43
42
|
logger_1.default.debug(err);
|
|
44
43
|
res.status(err.status);
|
|
45
44
|
payload.errors.push({
|
|
@@ -49,14 +48,14 @@ const errorHandler = (err, req, res, _next) => {
|
|
|
49
48
|
...err.extensions,
|
|
50
49
|
},
|
|
51
50
|
});
|
|
52
|
-
if (err instanceof
|
|
53
|
-
res.header('Allow', err.extensions
|
|
51
|
+
if (err instanceof exceptions_2.MethodNotAllowedException) {
|
|
52
|
+
res.header('Allow', err.extensions['allow'].join(', '));
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
else {
|
|
57
56
|
logger_1.default.error(err);
|
|
58
57
|
res.status(500);
|
|
59
|
-
if (
|
|
58
|
+
if (req.accountability?.admin === true) {
|
|
60
59
|
payload = {
|
|
61
60
|
errors: [
|
|
62
61
|
{
|
|
@@ -87,7 +86,7 @@ const errorHandler = (err, req, res, _next) => {
|
|
|
87
86
|
.emitFilter('request.error', payload.errors, {}, {
|
|
88
87
|
database: (0, database_1.default)(),
|
|
89
88
|
schema: req.schema,
|
|
90
|
-
accountability:
|
|
89
|
+
accountability: req.accountability ?? null,
|
|
91
90
|
})
|
|
92
91
|
.then(() => {
|
|
93
92
|
return res.json(payload);
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
const extractToken = (req, res, next) => {
|
|
12
12
|
let token = null;
|
|
13
|
-
if (req.query && req.query
|
|
14
|
-
token = req.query
|
|
13
|
+
if (req.query && req.query['access_token']) {
|
|
14
|
+
token = req.query['access_token'];
|
|
15
15
|
}
|
|
16
16
|
if (req.headers && req.headers.authorization) {
|
|
17
17
|
const parts = req.headers.authorization.split(' ');
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RequestHandler } from 'express';
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
2
|
export declare const parseGraphQL: RequestHandler;
|
|
@@ -17,10 +17,10 @@ exports.parseGraphQL = (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
17
17
|
let operationName = null;
|
|
18
18
|
let document;
|
|
19
19
|
if (req.method === 'GET') {
|
|
20
|
-
query = req.query
|
|
21
|
-
if (req.query
|
|
20
|
+
query = req.query['query'] || null;
|
|
21
|
+
if (req.query['variables']) {
|
|
22
22
|
try {
|
|
23
|
-
variables = (0, utils_1.parseJSON)(req.query
|
|
23
|
+
variables = (0, utils_1.parseJSON)(req.query['variables']);
|
|
24
24
|
}
|
|
25
25
|
catch {
|
|
26
26
|
throw new exceptions_1.InvalidQueryException(`Variables are invalid JSON.`);
|
|
@@ -29,7 +29,7 @@ exports.parseGraphQL = (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
29
29
|
else {
|
|
30
30
|
variables = {};
|
|
31
31
|
}
|
|
32
|
-
operationName = req.query
|
|
32
|
+
operationName = req.query['operationName'] || null;
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
35
|
query = req.body.query || null;
|
|
@@ -49,15 +49,21 @@ exports.parseGraphQL = (0, async_handler_1.default)(async (req, res, next) => {
|
|
|
49
49
|
}
|
|
50
50
|
const operationAST = (0, graphql_1.getOperationAST)(document, operationName);
|
|
51
51
|
// You can only do `query` through GET
|
|
52
|
-
if (req.method === 'GET' &&
|
|
53
|
-
throw new exceptions_1.MethodNotAllowedException(`Can only perform a ${operationAST
|
|
52
|
+
if (req.method === 'GET' && operationAST?.operation !== 'query') {
|
|
53
|
+
throw new exceptions_1.MethodNotAllowedException(`Can only perform a ${operationAST?.operation} from a POST request.`, {
|
|
54
54
|
allow: ['POST'],
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
// Prevent caching responses when mutations are made
|
|
58
|
-
if (
|
|
59
|
-
res.locals
|
|
58
|
+
if (operationAST?.operation === 'mutation') {
|
|
59
|
+
res.locals['cache'] = false;
|
|
60
60
|
}
|
|
61
|
-
res.locals
|
|
61
|
+
res.locals['graphqlParams'] = {
|
|
62
|
+
document,
|
|
63
|
+
query,
|
|
64
|
+
variables,
|
|
65
|
+
operationName,
|
|
66
|
+
contextValue: { req, res },
|
|
67
|
+
};
|
|
62
68
|
return next();
|
|
63
69
|
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
|
+
import type { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
|
|
3
|
+
declare let checkRateLimit: RequestHandler;
|
|
4
|
+
export declare let rateLimiterGlobal: RateLimiterRedis | RateLimiterMemcache | RateLimiterMemory;
|
|
5
|
+
export default checkRateLimit;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.rateLimiterGlobal = void 0;
|
|
7
|
+
const ms_1 = __importDefault(require("ms"));
|
|
8
|
+
const env_1 = __importDefault(require("../env"));
|
|
9
|
+
const index_1 = require("../exceptions/index");
|
|
10
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
11
|
+
const rate_limiter_1 = require("../rate-limiter");
|
|
12
|
+
const async_handler_1 = __importDefault(require("../utils/async-handler"));
|
|
13
|
+
const validate_env_1 = require("../utils/validate-env");
|
|
14
|
+
const RATE_LIMITER_GLOBAL_KEY = 'global-rate-limit';
|
|
15
|
+
let checkRateLimit = (_req, _res, next) => next();
|
|
16
|
+
if (env_1.default['RATE_LIMITER_GLOBAL_ENABLED'] === true) {
|
|
17
|
+
(0, validate_env_1.validateEnv)(['RATE_LIMITER_GLOBAL_STORE', 'RATE_LIMITER_GLOBAL_DURATION', 'RATE_LIMITER_GLOBAL_POINTS']);
|
|
18
|
+
validateConfiguration();
|
|
19
|
+
exports.rateLimiterGlobal = (0, rate_limiter_1.createRateLimiter)('RATE_LIMITER_GLOBAL');
|
|
20
|
+
checkRateLimit = (0, async_handler_1.default)(async (_req, res, next) => {
|
|
21
|
+
try {
|
|
22
|
+
await exports.rateLimiterGlobal.consume(RATE_LIMITER_GLOBAL_KEY, 1);
|
|
23
|
+
}
|
|
24
|
+
catch (rateLimiterRes) {
|
|
25
|
+
if (rateLimiterRes instanceof Error)
|
|
26
|
+
throw rateLimiterRes;
|
|
27
|
+
res.set('Retry-After', String(Math.round(rateLimiterRes.msBeforeNext / 1000)));
|
|
28
|
+
throw new index_1.HitRateLimitException(`Too many requests, retry after ${(0, ms_1.default)(rateLimiterRes.msBeforeNext)}.`, {
|
|
29
|
+
limit: +env_1.default['RATE_LIMITER_GLOBAL_POINTS'],
|
|
30
|
+
reset: new Date(Date.now() + rateLimiterRes.msBeforeNext),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
next();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.default = checkRateLimit;
|
|
37
|
+
function validateConfiguration() {
|
|
38
|
+
if (env_1.default['RATE_LIMITER_ENABLED'] !== true) {
|
|
39
|
+
logger_1.default.error(`The IP based rate limiter needs to be enabled when using the global rate limiter.`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const globalPointsPerSec = Number(env_1.default['RATE_LIMITER_GLOBAL_POINTS']) / Math.max(Number(env_1.default['RATE_LIMITER_GLOBAL_DURATION']), 1);
|
|
43
|
+
const regularPointsPerSec = Number(env_1.default['RATE_LIMITER_POINTS']) / Math.max(Number(env_1.default['RATE_LIMITER_DURATION']), 1);
|
|
44
|
+
if (globalPointsPerSec <= regularPointsPerSec) {
|
|
45
|
+
logger_1.default.error(`The global rate limiter needs to allow more requests per second than the IP based rate limiter.`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RequestHandler } from 'express';
|
|
2
|
-
import { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
|
+
import type { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
|
|
3
3
|
declare let checkRateLimit: RequestHandler;
|
|
4
4
|
export declare let rateLimiter: RateLimiterRedis | RateLimiterMemcache | RateLimiterMemory;
|
|
5
5
|
export default checkRateLimit;
|
|
@@ -11,10 +11,10 @@ const rate_limiter_1 = require("../rate-limiter");
|
|
|
11
11
|
const async_handler_1 = __importDefault(require("../utils/async-handler"));
|
|
12
12
|
const get_ip_from_req_1 = require("../utils/get-ip-from-req");
|
|
13
13
|
const validate_env_1 = require("../utils/validate-env");
|
|
14
|
-
let checkRateLimit = (
|
|
15
|
-
if (env_1.default
|
|
14
|
+
let checkRateLimit = (_req, _res, next) => next();
|
|
15
|
+
if (env_1.default['RATE_LIMITER_ENABLED'] === true) {
|
|
16
16
|
(0, validate_env_1.validateEnv)(['RATE_LIMITER_STORE', 'RATE_LIMITER_DURATION', 'RATE_LIMITER_POINTS']);
|
|
17
|
-
exports.rateLimiter = (0, rate_limiter_1.createRateLimiter)();
|
|
17
|
+
exports.rateLimiter = (0, rate_limiter_1.createRateLimiter)('RATE_LIMITER');
|
|
18
18
|
checkRateLimit = (0, async_handler_1.default)(async (req, res, next) => {
|
|
19
19
|
try {
|
|
20
20
|
await exports.rateLimiter.consume((0, get_ip_from_req_1.getIPFromReq)(req), 1);
|
|
@@ -22,9 +22,9 @@ if (env_1.default.RATE_LIMITER_ENABLED === true) {
|
|
|
22
22
|
catch (rateLimiterRes) {
|
|
23
23
|
if (rateLimiterRes instanceof Error)
|
|
24
24
|
throw rateLimiterRes;
|
|
25
|
-
res.set('Retry-After', String(rateLimiterRes.msBeforeNext / 1000));
|
|
25
|
+
res.set('Retry-After', String(Math.round(rateLimiterRes.msBeforeNext / 1000)));
|
|
26
26
|
throw new exceptions_1.HitRateLimitException(`Too many requests, retry after ${(0, ms_1.default)(rateLimiterRes.msBeforeNext)}.`, {
|
|
27
|
-
limit: +env_1.default
|
|
27
|
+
limit: +env_1.default['RATE_LIMITER_POINTS'],
|
|
28
28
|
reset: new Date(Date.now() + rateLimiterRes.msBeforeNext),
|
|
29
29
|
});
|
|
30
30
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RequestHandler } from 'express';
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
2
|
export declare const respond: RequestHandler;
|
|
@@ -16,29 +16,28 @@ const get_date_formatted_1 = require("../utils/get-date-formatted");
|
|
|
16
16
|
const get_milliseconds_1 = require("../utils/get-milliseconds");
|
|
17
17
|
const get_string_byte_size_1 = require("../utils/get-string-byte-size");
|
|
18
18
|
exports.respond = (0, async_handler_1.default)(async (req, res) => {
|
|
19
|
-
var _a, _b, _c, _d, _e;
|
|
20
19
|
const { cache } = (0, cache_1.getCache)();
|
|
21
20
|
let exceedsMaxSize = false;
|
|
22
|
-
if (env_1.default
|
|
23
|
-
const valueSize = res.locals
|
|
24
|
-
const maxSize = (0, bytes_1.parse)(env_1.default
|
|
21
|
+
if (env_1.default['CACHE_VALUE_MAX_SIZE'] !== false) {
|
|
22
|
+
const valueSize = res.locals['payload'] ? (0, get_string_byte_size_1.stringByteSize)(JSON.stringify(res.locals['payload'])) : 0;
|
|
23
|
+
const maxSize = (0, bytes_1.parse)(env_1.default['CACHE_VALUE_MAX_SIZE']);
|
|
25
24
|
exceedsMaxSize = valueSize > maxSize;
|
|
26
25
|
}
|
|
27
|
-
if ((req.method.toLowerCase() === 'get' ||
|
|
28
|
-
env_1.default
|
|
26
|
+
if ((req.method.toLowerCase() === 'get' || req.originalUrl?.startsWith('/graphql')) &&
|
|
27
|
+
env_1.default['CACHE_ENABLED'] === true &&
|
|
29
28
|
cache &&
|
|
30
29
|
!req.sanitizedQuery.export &&
|
|
31
|
-
res.locals
|
|
30
|
+
res.locals['cache'] !== false &&
|
|
32
31
|
exceedsMaxSize === false) {
|
|
33
32
|
const key = (0, get_cache_key_1.getCacheKey)(req);
|
|
34
33
|
try {
|
|
35
|
-
await (0, cache_1.setCacheValue)(cache, key, res.locals
|
|
36
|
-
await (0, cache_1.setCacheValue)(cache, `${key}__expires_at`, { exp: Date.now() + (0, get_milliseconds_1.getMilliseconds)(env_1.default
|
|
34
|
+
await (0, cache_1.setCacheValue)(cache, key, res.locals['payload'], (0, get_milliseconds_1.getMilliseconds)(env_1.default['CACHE_TTL']));
|
|
35
|
+
await (0, cache_1.setCacheValue)(cache, `${key}__expires_at`, { exp: Date.now() + (0, get_milliseconds_1.getMilliseconds)(env_1.default['CACHE_TTL'], 0) });
|
|
37
36
|
}
|
|
38
37
|
catch (err) {
|
|
39
38
|
logger_1.default.warn(err, `[cache] Couldn't set key ${key}. ${err}`);
|
|
40
39
|
}
|
|
41
|
-
res.setHeader('Cache-Control', (0, get_cache_headers_1.getCacheControlHeader)(req, (0, get_milliseconds_1.getMilliseconds)(env_1.default
|
|
40
|
+
res.setHeader('Cache-Control', (0, get_cache_headers_1.getCacheControlHeader)(req, (0, get_milliseconds_1.getMilliseconds)(env_1.default['CACHE_TTL']), true, true));
|
|
42
41
|
res.setHeader('Vary', 'Origin, Cache-Control');
|
|
43
42
|
}
|
|
44
43
|
else {
|
|
@@ -47,7 +46,7 @@ exports.respond = (0, async_handler_1.default)(async (req, res) => {
|
|
|
47
46
|
res.setHeader('Vary', 'Origin, Cache-Control');
|
|
48
47
|
}
|
|
49
48
|
if (req.sanitizedQuery.export) {
|
|
50
|
-
const exportService = new services_1.ExportService({ accountability: req.accountability, schema: req.schema });
|
|
49
|
+
const exportService = new services_1.ExportService({ accountability: req.accountability ?? null, schema: req.schema });
|
|
51
50
|
let filename = '';
|
|
52
51
|
if (req.collection) {
|
|
53
52
|
filename += req.collection;
|
|
@@ -59,29 +58,29 @@ exports.respond = (0, async_handler_1.default)(async (req, res) => {
|
|
|
59
58
|
if (req.sanitizedQuery.export === 'json') {
|
|
60
59
|
res.attachment(`${filename}.json`);
|
|
61
60
|
res.set('Content-Type', 'application/json');
|
|
62
|
-
return res.status(200).send(exportService.transform(
|
|
61
|
+
return res.status(200).send(exportService.transform(res.locals['payload']?.data, 'json'));
|
|
63
62
|
}
|
|
64
63
|
if (req.sanitizedQuery.export === 'xml') {
|
|
65
64
|
res.attachment(`${filename}.xml`);
|
|
66
65
|
res.set('Content-Type', 'text/xml');
|
|
67
|
-
return res.status(200).send(exportService.transform(
|
|
66
|
+
return res.status(200).send(exportService.transform(res.locals['payload']?.data, 'xml'));
|
|
68
67
|
}
|
|
69
68
|
if (req.sanitizedQuery.export === 'csv') {
|
|
70
69
|
res.attachment(`${filename}.csv`);
|
|
71
70
|
res.set('Content-Type', 'text/csv');
|
|
72
|
-
return res.status(200).send(exportService.transform(
|
|
71
|
+
return res.status(200).send(exportService.transform(res.locals['payload']?.data, 'csv'));
|
|
73
72
|
}
|
|
74
73
|
if (req.sanitizedQuery.export === 'yaml') {
|
|
75
74
|
res.attachment(`${filename}.yaml`);
|
|
76
75
|
res.set('Content-Type', 'text/yaml');
|
|
77
|
-
return res.status(200).send(exportService.transform(
|
|
76
|
+
return res.status(200).send(exportService.transform(res.locals['payload']?.data, 'yaml'));
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
|
-
if (Buffer.isBuffer(res.locals
|
|
81
|
-
return res.end(res.locals
|
|
79
|
+
if (Buffer.isBuffer(res.locals['payload'])) {
|
|
80
|
+
return res.end(res.locals['payload']);
|
|
82
81
|
}
|
|
83
|
-
else if (res.locals
|
|
84
|
-
return res.json(res.locals
|
|
82
|
+
else if (res.locals['payload']) {
|
|
83
|
+
return res.json(res.locals['payload']);
|
|
85
84
|
}
|
|
86
85
|
else {
|
|
87
86
|
return res.status(204).end();
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Sanitize query parameters.
|
|
3
3
|
* This ensures that query params are formatted and ready to go for the services.
|
|
4
4
|
*/
|
|
5
|
-
import { RequestHandler } from 'express';
|
|
5
|
+
import type { RequestHandler } from 'express';
|
|
6
6
|
declare const sanitizeQueryMiddleware: RequestHandler;
|
|
7
7
|
export default sanitizeQueryMiddleware;
|
|
@@ -11,7 +11,7 @@ const sanitizeQueryMiddleware = (req, _res, next) => {
|
|
|
11
11
|
if (!req.query)
|
|
12
12
|
return;
|
|
13
13
|
req.sanitizedQuery = (0, sanitize_query_1.sanitizeQuery)({
|
|
14
|
-
fields: req.query
|
|
14
|
+
fields: req.query['fields'] || '*',
|
|
15
15
|
...req.query,
|
|
16
16
|
}, req.accountability || null);
|
|
17
17
|
Object.freeze(req.sanitizedQuery);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Set req.collection for use in other middleware. Used as an alternative on validate-collection for
|
|
3
3
|
* system collections
|
|
4
4
|
*/
|
|
5
|
-
import { RequestHandler } from 'express';
|
|
5
|
+
import type { RequestHandler } from 'express';
|
|
6
6
|
declare const useCollection: (collection: string) => RequestHandler;
|
|
7
7
|
export default useCollection;
|
|
@@ -2,21 +2,32 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const utils_1 = require("@directus/shared/utils");
|
|
4
4
|
const vm2_1 = require("vm2");
|
|
5
|
+
const node_module_1 = require("node:module");
|
|
5
6
|
exports.default = (0, utils_1.defineOperationApi)({
|
|
6
7
|
id: 'exec',
|
|
7
8
|
handler: async ({ code }, { data, env }) => {
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const allowedModules = env['FLOWS_EXEC_ALLOWED_MODULES'] ? (0, utils_1.toArray)(env['FLOWS_EXEC_ALLOWED_MODULES']) : [];
|
|
10
|
+
const allowedModulesBuiltIn = [];
|
|
11
|
+
const allowedModulesExternal = [];
|
|
12
|
+
const allowedEnv = data['$env'] ?? {};
|
|
11
13
|
const opts = {
|
|
12
14
|
eval: false,
|
|
13
15
|
wasm: false,
|
|
14
16
|
env: allowedEnv,
|
|
15
17
|
};
|
|
18
|
+
for (const module of allowedModules) {
|
|
19
|
+
if ((0, node_module_1.isBuiltin)(module)) {
|
|
20
|
+
allowedModulesBuiltIn.push(module);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
allowedModulesExternal.push(module);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
16
26
|
if (allowedModules.length > 0) {
|
|
17
27
|
opts.require = {
|
|
28
|
+
builtin: allowedModulesBuiltIn,
|
|
18
29
|
external: {
|
|
19
|
-
modules:
|
|
30
|
+
modules: allowedModulesExternal,
|
|
20
31
|
transitive: false,
|
|
21
32
|
},
|
|
22
33
|
};
|
|
@@ -6,7 +6,6 @@ const get_accountability_for_role_1 = require("../../utils/get-accountability-fo
|
|
|
6
6
|
exports.default = (0, utils_1.defineOperationApi)({
|
|
7
7
|
id: 'item-create',
|
|
8
8
|
handler: async ({ collection, payload, emitEvents, permissions }, { accountability, database, getSchema }) => {
|
|
9
|
-
var _a;
|
|
10
9
|
const schema = await getSchema({ database });
|
|
11
10
|
let customAccountability;
|
|
12
11
|
if (!permissions || permissions === '$trigger') {
|
|
@@ -26,7 +25,7 @@ exports.default = (0, utils_1.defineOperationApi)({
|
|
|
26
25
|
accountability: customAccountability,
|
|
27
26
|
knex: database,
|
|
28
27
|
});
|
|
29
|
-
const payloadObject = (
|
|
28
|
+
const payloadObject = (0, utils_1.optionToObject)(payload) ?? null;
|
|
30
29
|
let result;
|
|
31
30
|
if (!payloadObject) {
|
|
32
31
|
result = null;
|
|
@@ -7,7 +7,6 @@ const sanitize_query_1 = require("../../utils/sanitize-query");
|
|
|
7
7
|
exports.default = (0, utils_1.defineOperationApi)({
|
|
8
8
|
id: 'item-update',
|
|
9
9
|
handler: async ({ collection, key, payload, query, emitEvents, permissions }, { accountability, database, getSchema }) => {
|
|
10
|
-
var _a;
|
|
11
10
|
const schema = await getSchema({ database });
|
|
12
11
|
let customAccountability;
|
|
13
12
|
if (!permissions || permissions === '$trigger') {
|
|
@@ -27,7 +26,7 @@ exports.default = (0, utils_1.defineOperationApi)({
|
|
|
27
26
|
accountability: customAccountability,
|
|
28
27
|
knex: database,
|
|
29
28
|
});
|
|
30
|
-
const payloadObject = (
|
|
29
|
+
const payloadObject = (0, utils_1.optionToObject)(payload) ?? null;
|
|
31
30
|
const queryObject = query ? (0, utils_1.optionToObject)(query) : {};
|
|
32
31
|
const sanitizedQueryObject = (0, sanitize_query_1.sanitizeQuery)(queryObject, customAccountability);
|
|
33
32
|
if (!payloadObject) {
|
|
@@ -27,10 +27,9 @@ exports.default = (0, utils_1.defineOperationApi)({
|
|
|
27
27
|
});
|
|
28
28
|
const messageString = message ? (0, utils_1.optionToString)(message) : null;
|
|
29
29
|
const payload = (0, utils_1.toArray)(recipient).map((userId) => {
|
|
30
|
-
var _a;
|
|
31
30
|
return {
|
|
32
31
|
recipient: userId,
|
|
33
|
-
sender:
|
|
32
|
+
sender: customAccountability?.user ?? null,
|
|
34
33
|
subject,
|
|
35
34
|
message: messageString,
|
|
36
35
|
};
|
|
@@ -9,30 +9,30 @@ const index_1 = require("../../request/index");
|
|
|
9
9
|
exports.default = (0, utils_1.defineOperationApi)({
|
|
10
10
|
id: 'request',
|
|
11
11
|
handler: async ({ url, method, body, headers }) => {
|
|
12
|
-
|
|
13
|
-
const customHeaders = (_a = headers === null || headers === void 0 ? void 0 : headers.reduce((acc, { header, value }) => {
|
|
12
|
+
const customHeaders = headers?.reduce((acc, { header, value }) => {
|
|
14
13
|
acc[header] = value;
|
|
15
14
|
return acc;
|
|
16
|
-
}, {})
|
|
17
|
-
if (!customHeaders['Content-Type'] && isValidJSON(body)) {
|
|
15
|
+
}, {}) ?? {};
|
|
16
|
+
if (!customHeaders['Content-Type'] && (typeof body === 'object' || (0, utils_1.isValidJSON)(body))) {
|
|
18
17
|
customHeaders['Content-Type'] = 'application/json';
|
|
19
18
|
}
|
|
20
19
|
const axios = await (0, index_1.getAxios)();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
try {
|
|
21
|
+
const result = await axios({
|
|
22
|
+
url: (0, encodeurl_1.default)(url),
|
|
23
|
+
method,
|
|
24
|
+
data: body,
|
|
25
|
+
headers: customHeaders,
|
|
26
|
+
});
|
|
27
|
+
return { status: result.status, statusText: result.statusText, headers: result.headers, data: result.data };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw JSON.stringify({
|
|
31
|
+
status: error.response.status,
|
|
32
|
+
statusText: error.response.statusText,
|
|
33
|
+
headers: error.response.headers,
|
|
34
|
+
data: error.response.data,
|
|
35
|
+
});
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
});
|
|
@@ -6,9 +6,8 @@ const flows_1 = require("../../flows");
|
|
|
6
6
|
exports.default = (0, utils_1.defineOperationApi)({
|
|
7
7
|
id: 'trigger',
|
|
8
8
|
handler: async ({ flow, payload, iterationMode, batchSize }, context) => {
|
|
9
|
-
var _a;
|
|
10
9
|
const flowManager = (0, flows_1.getFlowManager)();
|
|
11
|
-
const payloadObject = (
|
|
10
|
+
const payloadObject = (0, utils_1.optionToObject)(payload) ?? null;
|
|
12
11
|
if (Array.isArray(payloadObject)) {
|
|
13
12
|
if (iterationMode === 'serial') {
|
|
14
13
|
const result = [];
|
|
@@ -18,7 +17,7 @@ exports.default = (0, utils_1.defineOperationApi)({
|
|
|
18
17
|
return result;
|
|
19
18
|
}
|
|
20
19
|
if (iterationMode === 'batch') {
|
|
21
|
-
const size = batchSize
|
|
20
|
+
const size = batchSize ?? 10;
|
|
22
21
|
const result = [];
|
|
23
22
|
for (let i = 0; i < payloadObject.length; i += size) {
|
|
24
23
|
const batch = payloadObject.slice(i, i + size);
|
package/dist/rate-limiter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IRateLimiterOptions, IRateLimiterStoreOptions, RateLimiterAbstract } from 'rate-limiter-flexible';
|
|
2
2
|
type IRateLimiterOptionsOverrides = Partial<IRateLimiterOptions> | Partial<IRateLimiterStoreOptions>;
|
|
3
|
-
export declare function createRateLimiter(configOverrides?: IRateLimiterOptionsOverrides): RateLimiterAbstract;
|
|
3
|
+
export declare function createRateLimiter(configPrefix?: string, configOverrides?: IRateLimiterOptionsOverrides): RateLimiterAbstract;
|
|
4
4
|
export {};
|