directus 9.4.0 → 9.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +1 -1
  2. package/dist/app.js +20 -1
  3. package/dist/auth/auth.d.ts +2 -1
  4. package/dist/auth/drivers/ldap.js +2 -1
  5. package/dist/auth/drivers/local.js +2 -1
  6. package/dist/auth/drivers/oauth2.js +12 -21
  7. package/dist/auth/drivers/openid.js +14 -3
  8. package/dist/cache.js +1 -3
  9. package/dist/cli/commands/init/questions.d.ts +3 -0
  10. package/dist/cli/commands/init/questions.js +2 -0
  11. package/dist/cli/index.js +1 -1
  12. package/dist/cli/utils/create-db-connection.d.ts +1 -1
  13. package/dist/cli/utils/create-db-connection.js +11 -1
  14. package/dist/cli/utils/drivers.d.ts +1 -0
  15. package/dist/cli/utils/drivers.js +2 -1
  16. package/dist/controllers/activity.js +2 -1
  17. package/dist/controllers/auth.js +5 -4
  18. package/dist/controllers/extensions.js +1 -1
  19. package/dist/controllers/files.js +1 -1
  20. package/dist/controllers/shares.js +2 -2
  21. package/dist/controllers/utils.js +2 -0
  22. package/dist/database/helpers/date/index.d.ts +1 -0
  23. package/dist/database/helpers/date/index.js +3 -1
  24. package/dist/database/helpers/geometry/index.d.ts +1 -0
  25. package/dist/database/helpers/geometry/index.js +3 -1
  26. package/dist/database/helpers/index.d.ts +2 -0
  27. package/dist/database/helpers/index.js +2 -0
  28. package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +16 -0
  29. package/dist/database/helpers/schema/dialects/cockroachdb.js +16 -0
  30. package/dist/database/helpers/schema/dialects/default.d.ts +3 -0
  31. package/dist/database/helpers/schema/dialects/default.js +7 -0
  32. package/dist/database/helpers/schema/dialects/oracle.d.ts +12 -0
  33. package/dist/database/helpers/schema/dialects/oracle.js +13 -0
  34. package/dist/database/helpers/schema/index.d.ts +7 -0
  35. package/dist/database/helpers/schema/index.js +17 -0
  36. package/dist/database/helpers/schema/types.d.ts +25 -0
  37. package/dist/database/helpers/schema/types.js +89 -0
  38. package/dist/database/index.d.ts +1 -1
  39. package/dist/database/index.js +36 -16
  40. package/dist/database/migrations/20201105B-change-webhook-url-type.js +6 -25
  41. package/dist/database/migrations/20210312A-webhooks-collections-text.js +6 -25
  42. package/dist/database/migrations/20210415A-make-filesize-nullable.js +9 -4
  43. package/dist/database/migrations/20210506A-rename-interfaces.js +1 -1
  44. package/dist/database/migrations/20210510A-restructure-relations.js +12 -4
  45. package/dist/database/migrations/20210525A-add-insights.js +2 -2
  46. package/dist/database/migrations/20210626A-change-filesize-bigint.js +5 -7
  47. package/dist/database/migrations/20210903A-add-auth-provider.js +11 -2
  48. package/dist/database/migrations/20210907A-webhooks-collections-not-null.js +6 -20
  49. package/dist/database/migrations/20210920A-webhooks-url-not-null.js +10 -14
  50. package/dist/database/migrations/20211211A-add-shares.js +5 -4
  51. package/dist/database/migrations/20211230A-add-project-descriptor.d.ts +3 -0
  52. package/dist/database/migrations/20211230A-add-project-descriptor.js +15 -0
  53. package/dist/database/migrations/run.js +1 -1
  54. package/dist/database/run-ast.d.ts +1 -1
  55. package/dist/database/seeds/01-collections.yaml +1 -0
  56. package/dist/database/seeds/02-roles.yaml +1 -0
  57. package/dist/database/seeds/03-users.yaml +1 -0
  58. package/dist/database/system-data/fields/_defaults.yaml +2 -0
  59. package/dist/database/system-data/fields/settings.yaml +20 -1
  60. package/dist/database/system-data/fields/shares.yaml +4 -0
  61. package/dist/database/system-data/relations/index.d.ts +1 -1
  62. package/dist/emitter.d.ts +3 -4
  63. package/dist/emitter.js +2 -8
  64. package/dist/env.js +4 -1
  65. package/dist/exceptions/database/translate.js +1 -0
  66. package/dist/exceptions/index.d.ts +1 -0
  67. package/dist/exceptions/index.js +1 -0
  68. package/dist/exceptions/unsupported-media-type.d.ts +4 -0
  69. package/dist/exceptions/unsupported-media-type.js +10 -0
  70. package/dist/extensions.d.ts +14 -8
  71. package/dist/extensions.js +136 -69
  72. package/dist/logger.js +22 -1
  73. package/dist/middleware/authenticate.js +2 -1
  74. package/dist/middleware/rate-limiter.js +2 -1
  75. package/dist/services/assets.js +3 -3
  76. package/dist/services/authentication.d.ts +2 -2
  77. package/dist/services/authentication.js +10 -5
  78. package/dist/services/authorization.d.ts +2 -3
  79. package/dist/services/collections.d.ts +2 -2
  80. package/dist/services/collections.js +10 -6
  81. package/dist/services/fields.d.ts +2 -3
  82. package/dist/services/fields.js +8 -4
  83. package/dist/services/graphql.d.ts +3 -2
  84. package/dist/services/graphql.js +35 -5
  85. package/dist/services/import.d.ts +2 -2
  86. package/dist/services/import.js +2 -1
  87. package/dist/services/items.d.ts +2 -2
  88. package/dist/services/items.js +22 -18
  89. package/dist/services/mail/index.d.ts +2 -2
  90. package/dist/services/meta.d.ts +2 -2
  91. package/dist/services/payload.d.ts +2 -2
  92. package/dist/services/relations.d.ts +2 -2
  93. package/dist/services/server.d.ts +2 -2
  94. package/dist/services/server.js +1 -0
  95. package/dist/services/shares.js +2 -2
  96. package/dist/services/specifications.d.ts +2 -2
  97. package/dist/services/users.d.ts +2 -3
  98. package/dist/services/utils.d.ts +2 -2
  99. package/dist/types/ast.d.ts +1 -2
  100. package/dist/types/auth.d.ts +1 -3
  101. package/dist/types/index.d.ts +0 -3
  102. package/dist/types/index.js +0 -3
  103. package/dist/types/services.d.ts +1 -3
  104. package/dist/types/snapshot.d.ts +1 -2
  105. package/dist/utils/apply-query.d.ts +1 -2
  106. package/dist/utils/apply-query.js +1 -1
  107. package/dist/utils/apply-snapshot.d.ts +2 -1
  108. package/dist/utils/get-ast-from-query.d.ts +2 -3
  109. package/dist/utils/get-default-value.js +3 -1
  110. package/dist/utils/get-ip-from-req.d.ts +2 -0
  111. package/dist/utils/get-ip-from-req.js +24 -0
  112. package/dist/utils/get-local-type.js +1 -1
  113. package/dist/utils/get-permissions.d.ts +1 -2
  114. package/dist/utils/get-relation-type.d.ts +1 -1
  115. package/dist/utils/get-schema.d.ts +1 -2
  116. package/dist/utils/get-snapshot.d.ts +2 -1
  117. package/dist/utils/merge-permissions-for-share.d.ts +1 -2
  118. package/dist/utils/reduce-schema.d.ts +1 -2
  119. package/example.env +9 -1
  120. package/package.json +18 -15
  121. package/dist/cli/index.test.d.ts +0 -1
  122. package/dist/cli/index.test.js +0 -58
  123. package/dist/middleware/cache.test.d.ts +0 -1
  124. package/dist/middleware/cache.test.js +0 -62
  125. package/dist/tests/database/migrations/run.test.d.ts +0 -1
  126. package/dist/tests/database/migrations/run.test.js +0 -29
  127. package/dist/types/extensions.d.ts +0 -43
  128. package/dist/types/extensions.js +0 -2
  129. package/dist/types/relation.d.ts +0 -21
  130. package/dist/types/relation.js +0 -2
  131. package/dist/types/schema.d.ts +0 -32
  132. package/dist/types/schema.js +0 -2
  133. package/dist/utils/get-cache-key.test.d.ts +0 -1
  134. package/dist/utils/get-cache-key.test.js +0 -53
@@ -27,6 +27,7 @@ const database_1 = __importDefault(require("../database"));
27
27
  const env_1 = __importDefault(require("../env"));
28
28
  const exceptions_1 = require("../exceptions");
29
29
  const async_handler_1 = __importDefault(require("../utils/async-handler"));
30
+ const get_ip_from_req_1 = require("../utils/get-ip-from-req");
30
31
  const is_directus_jwt_1 = __importDefault(require("../utils/is-directus-jwt"));
31
32
  /**
32
33
  * Verify the passed JWT and assign the user ID and role to `req`
@@ -37,7 +38,7 @@ const authenticate = (0, async_handler_1.default)(async (req, res, next) => {
37
38
  role: null,
38
39
  admin: false,
39
40
  app: false,
40
- ip: req.ip.startsWith('::ffff:') ? req.ip.substring(7) : req.ip,
41
+ ip: (0, get_ip_from_req_1.getIPFromReq)(req),
41
42
  userAgent: req.get('user-agent'),
42
43
  };
43
44
  const database = (0, database_1.default)();
@@ -9,6 +9,7 @@ const env_1 = __importDefault(require("../env"));
9
9
  const exceptions_1 = require("../exceptions");
10
10
  const rate_limiter_1 = require("../rate-limiter");
11
11
  const async_handler_1 = __importDefault(require("../utils/async-handler"));
12
+ const get_ip_from_req_1 = require("../utils/get-ip-from-req");
12
13
  const validate_env_1 = require("../utils/validate-env");
13
14
  let checkRateLimit = (req, res, next) => next();
14
15
  if (env_1.default.RATE_LIMITER_ENABLED === true) {
@@ -16,7 +17,7 @@ if (env_1.default.RATE_LIMITER_ENABLED === true) {
16
17
  exports.rateLimiter = (0, rate_limiter_1.createRateLimiter)();
17
18
  checkRateLimit = (0, async_handler_1.default)(async (req, res, next) => {
18
19
  try {
19
- await exports.rateLimiter.consume(req.ip, 1);
20
+ await exports.rateLimiter.consume((0, get_ip_from_req_1.getIPFromReq)(req), 1);
20
21
  }
21
22
  catch (rateLimiterRes) {
22
23
  if (rateLimiterRes instanceof Error)
@@ -52,9 +52,6 @@ class AssetsService {
52
52
  .from('directus_settings')
53
53
  .first();
54
54
  const systemPublicKeys = Object.values(publicSettings || {});
55
- if (systemPublicKeys.includes(id) === false && ((_a = this.accountability) === null || _a === void 0 ? void 0 : _a.admin) !== true) {
56
- await this.authorizationService.checkAccess('read', 'directus_files', id);
57
- }
58
55
  /**
59
56
  * This is a little annoying. Postgres will error out if you're trying to search in `where`
60
57
  * with a wrong type. In case of directus_files where id is a uuid, we'll have to verify the
@@ -63,6 +60,9 @@ class AssetsService {
63
60
  const isValidUUID = (0, uuid_validate_1.default)(id, 4);
64
61
  if (isValidUUID === false)
65
62
  throw new exceptions_1.ForbiddenException();
63
+ if (systemPublicKeys.includes(id) === false && ((_a = this.accountability) === null || _a === void 0 ? void 0 : _a.admin) !== true) {
64
+ await this.authorizationService.checkAccess('read', 'directus_files', id);
65
+ }
66
66
  const file = (await this.knex.select('*').from('directus_files').where({ id }).first());
67
67
  if (!file)
68
68
  throw new exceptions_1.ForbiddenException();
@@ -1,7 +1,7 @@
1
1
  import { Knex } from 'knex';
2
2
  import { ActivityService } from './activity';
3
- import { AbstractServiceOptions, SchemaOverview, LoginResult } from '../types';
4
- import { Accountability } from '@directus/shared/types';
3
+ import { AbstractServiceOptions, LoginResult } from '../types';
4
+ import { Accountability, SchemaOverview } from '@directus/shared/types';
5
5
  export declare class AuthenticationService {
6
6
  knex: Knex;
7
7
  accountability: Accountability | null;
@@ -43,7 +43,7 @@ class AuthenticationService {
43
43
  const user = await this.knex
44
44
  .select('u.id', 'u.first_name', 'u.last_name', 'u.email', 'u.password', 'u.status', 'u.role', 'r.admin_access', 'r.app_access', 'u.tfa_secret', 'u.provider', 'u.external_identifier', 'u.auth_data')
45
45
  .from('directus_users as u')
46
- .innerJoin('directus_roles as r', 'u.role', 'r.id')
46
+ .leftJoin('directus_roles as r', 'u.role', 'r.id')
47
47
  .where('u.id', await provider.getUserID((0, lodash_1.cloneDeep)(payload)))
48
48
  .andWhere('u.provider', providerName)
49
49
  .first();
@@ -204,14 +204,16 @@ class AuthenticationService {
204
204
  .from('directus_sessions AS s')
205
205
  .leftJoin('directus_users AS u', 's.user', 'u.id')
206
206
  .leftJoin('directus_shares AS d', 's.share', 'd.id')
207
- .joinRaw('LEFT JOIN directus_roles AS r ON r.id IN (u.role, d.role)')
207
+ .leftJoin('directus_roles AS r', (join) => {
208
+ join.onIn('r.id', [this.knex.ref('u.role'), this.knex.ref('d.role')]);
209
+ })
208
210
  .where('s.token', refreshToken)
209
- .andWhere('s.expires', '>=', this.knex.fn.now())
211
+ .andWhere('s.expires', '>=', new Date())
210
212
  .andWhere((subQuery) => {
211
- subQuery.whereNull('d.date_end').orWhere('d.date_end', '>=', this.knex.fn.now());
213
+ subQuery.whereNull('d.date_end').orWhere('d.date_end', '>=', new Date());
212
214
  })
213
215
  .andWhere((subQuery) => {
214
- subQuery.whereNull('d.date_start').orWhere('d.date_start', '<=', this.knex.fn.now());
216
+ subQuery.whereNull('d.date_start').orWhere('d.date_start', '<=', new Date());
215
217
  })
216
218
  .first();
217
219
  if (!record || (!record.share_id && !record.user_id)) {
@@ -247,6 +249,9 @@ class AuthenticationService {
247
249
  collection: record.share_collection,
248
250
  item: record.share_item,
249
251
  };
252
+ tokenPayload.app_access = false;
253
+ tokenPayload.admin_access = false;
254
+ delete tokenPayload.id;
250
255
  }
251
256
  const customClaims = await emitter_1.default.emitFilter('auth.jwt', tokenPayload, {
252
257
  status: 'pending',
@@ -1,7 +1,6 @@
1
1
  import { Knex } from 'knex';
2
- import { Accountability } from '@directus/shared/types';
3
- import { AbstractServiceOptions, AST, Item, PrimaryKey, SchemaOverview } from '../types';
4
- import { PermissionsAction } from '@directus/shared/types';
2
+ import { AbstractServiceOptions, AST, Item, PrimaryKey } from '../types';
3
+ import { PermissionsAction, Accountability, SchemaOverview } from '@directus/shared/types';
5
4
  import { PayloadService } from './payload';
6
5
  export declare class AuthorizationService {
7
6
  knex: Knex;
@@ -1,8 +1,8 @@
1
1
  import SchemaInspector from '@directus/schema';
2
2
  import { Knex } from 'knex';
3
3
  import Keyv from 'keyv';
4
- import { AbstractServiceOptions, Collection, CollectionMeta, SchemaOverview, MutationOptions } from '../types';
5
- import { Accountability, RawField } from '@directus/shared/types';
4
+ import { AbstractServiceOptions, Collection, CollectionMeta, MutationOptions } from '../types';
5
+ import { Accountability, RawField, SchemaOverview } from '@directus/shared/types';
6
6
  import { Table } from 'knex-schema-inspector/dist/types/table';
7
7
  export declare type RawCollection = {
8
8
  collection: string;
@@ -114,12 +114,14 @@ class CollectionsService {
114
114
  }
115
115
  return field;
116
116
  });
117
- await trx.schema.createTable(payload.collection, (table) => {
118
- for (const field of payload.fields) {
119
- if (field.type && constants_1.ALIAS_TYPES.includes(field.type) === false) {
120
- fieldsService.addColumnToTable(table, field);
117
+ await trx.transaction(async (schemaTrx) => {
118
+ await schemaTrx.schema.createTable(payload.collection, (table) => {
119
+ for (const field of payload.fields) {
120
+ if (field.type && constants_1.ALIAS_TYPES.includes(field.type) === false) {
121
+ fieldsService.addColumnToTable(table, field);
122
+ }
121
123
  }
122
- }
124
+ });
123
125
  });
124
126
  const fieldPayloads = payload.fields.filter((field) => field.meta).map((field) => field.meta);
125
127
  await fieldItemsService.createMany(fieldPayloads);
@@ -371,7 +373,9 @@ class CollectionsService {
371
373
  .update({ one_allowed_collections: newAllowedCollections })
372
374
  .where({ id: relation.meta.id });
373
375
  }
374
- await trx.schema.dropTable(collectionKey);
376
+ await trx.transaction(async (schemaTrx) => {
377
+ await schemaTrx.schema.dropTable(collectionKey);
378
+ });
375
379
  }
376
380
  });
377
381
  if (this.cache && env_1.default.CACHE_AUTO_PURGE && (opts === null || opts === void 0 ? void 0 : opts.autoPurgeCache) !== false) {
@@ -3,9 +3,8 @@ import { Knex } from 'knex';
3
3
  import { Column } from 'knex-schema-inspector/dist/types/column';
4
4
  import { ItemsService } from '../services/items';
5
5
  import { PayloadService } from '../services/payload';
6
- import { AbstractServiceOptions, SchemaOverview } from '../types';
7
- import { Accountability } from '@directus/shared/types';
8
- import { Field, RawField, Type } from '@directus/shared/types';
6
+ import { AbstractServiceOptions } from '../types';
7
+ import { Field, RawField, Type, Accountability, SchemaOverview } from '@directus/shared/types';
9
8
  import { Helpers } from '../database/helpers';
10
9
  import Keyv from 'keyv';
11
10
  export declare class FieldsService {
@@ -224,8 +224,10 @@ class FieldsService {
224
224
  this.addColumnToTable(table, hookAdjustedField);
225
225
  }
226
226
  else {
227
- await trx.schema.alterTable(collection, (table) => {
228
- this.addColumnToTable(table, hookAdjustedField);
227
+ await trx.transaction(async (schemaTrx) => {
228
+ await schemaTrx.schema.alterTable(collection, (table) => {
229
+ this.addColumnToTable(table, hookAdjustedField);
230
+ });
229
231
  });
230
232
  }
231
233
  }
@@ -387,8 +389,10 @@ class FieldsService {
387
389
  if (this.schema.collections[collection] &&
388
390
  field in this.schema.collections[collection].fields &&
389
391
  this.schema.collections[collection].fields[field].alias === false) {
390
- await trx.schema.table(collection, (table) => {
391
- table.dropColumn(field);
392
+ await trx.transaction(async (schemaTrx) => {
393
+ await schemaTrx.schema.table(collection, (table) => {
394
+ table.dropColumn(field);
395
+ });
392
396
  });
393
397
  }
394
398
  });
@@ -1,9 +1,10 @@
1
1
  import { ArgumentNode, FormattedExecutionResult, FragmentDefinitionNode, GraphQLError, GraphQLResolveInfo, GraphQLScalarType, GraphQLSchema, ObjectFieldNode, SelectionNode } from 'graphql';
2
+ import { SchemaOverview } from '@directus/shared/types';
2
3
  import { ObjectTypeComposer, SchemaComposer } from 'graphql-compose';
3
4
  import { Knex } from 'knex';
4
5
  import { BaseException } from '@directus/shared/exceptions';
5
6
  import { Accountability, Query } from '@directus/shared/types';
6
- import { AbstractServiceOptions, GraphQLParams, Item, SchemaOverview } from '../types';
7
+ import { AbstractServiceOptions, GraphQLParams, Item } from '../types';
7
8
  import { ItemsService } from './items';
8
9
  export declare const GraphQLGeoJSON: GraphQLScalarType;
9
10
  export declare const GraphQLDate: GraphQLScalarType;
@@ -70,7 +71,7 @@ export declare class GraphQLService {
70
71
  * Effectively merges the selections with the fragments used in those selections
71
72
  */
72
73
  replaceFragmentsInSelections(selections: readonly SelectionNode[] | undefined, fragments: Record<string, FragmentDefinitionNode>): readonly SelectionNode[] | null;
73
- injectSystemResolvers(schemaComposer: SchemaComposer<GraphQLParams['contextValue']>, { CreateCollectionTypes, ReadCollectionTypes, DeleteCollectionTypes, }: {
74
+ injectSystemResolvers(schemaComposer: SchemaComposer<GraphQLParams['contextValue']>, { CreateCollectionTypes, ReadCollectionTypes, UpdateCollectionTypes, DeleteCollectionTypes, }: {
74
75
  CreateCollectionTypes: Record<string, ObjectTypeComposer<any, any>>;
75
76
  ReadCollectionTypes: Record<string, ObjectTypeComposer<any, any>>;
76
77
  UpdateCollectionTypes: Record<string, ObjectTypeComposer<any, any>>;
@@ -334,6 +334,8 @@ class GraphQLService {
334
334
  }
335
335
  for (const relation of schema[action].relations) {
336
336
  if (relation.related_collection) {
337
+ if (SYSTEM_DENY_LIST.includes(relation.related_collection))
338
+ continue;
337
339
  (_a = CollectionTypes[relation.collection]) === null || _a === void 0 ? void 0 : _a.addFields({
338
340
  [relation.field]: {
339
341
  type: CollectionTypes[relation.related_collection],
@@ -768,6 +770,8 @@ class GraphQLService {
768
770
  }
769
771
  for (const relation of schema.read.relations) {
770
772
  if (relation.related_collection) {
773
+ if (SYSTEM_DENY_LIST.includes(relation.related_collection))
774
+ continue;
771
775
  (_a = ReadableCollectionFilterTypes[relation.collection]) === null || _a === void 0 ? void 0 : _a.addFields({
772
776
  [relation.field]: ReadableCollectionFilterTypes[relation.related_collection],
773
777
  });
@@ -1303,7 +1307,7 @@ class GraphQLService {
1303
1307
  })).filter((s) => s);
1304
1308
  return result;
1305
1309
  }
1306
- injectSystemResolvers(schemaComposer, { CreateCollectionTypes, ReadCollectionTypes, DeleteCollectionTypes, }, schema) {
1310
+ injectSystemResolvers(schemaComposer, { CreateCollectionTypes, ReadCollectionTypes, UpdateCollectionTypes, DeleteCollectionTypes, }, schema) {
1307
1311
  var _a, _b, _c, _d, _e;
1308
1312
  const AuthTokens = schemaComposer.createObjectTC({
1309
1313
  name: 'auth_tokens',
@@ -1393,10 +1397,10 @@ class GraphQLService {
1393
1397
  resolve: async () => {
1394
1398
  const extensionManager = (0, extensions_1.getExtensionManager)();
1395
1399
  return {
1396
- interfaces: extensionManager.listExtensions('interface'),
1397
- displays: extensionManager.listExtensions('display'),
1398
- layouts: extensionManager.listExtensions('layout'),
1399
- modules: extensionManager.listExtensions('module'),
1400
+ interfaces: extensionManager.getExtensionsList('interface'),
1401
+ displays: extensionManager.getExtensionsList('display'),
1402
+ layouts: extensionManager.getExtensionsList('layout'),
1403
+ modules: extensionManager.getExtensionsList('module'),
1400
1404
  };
1401
1405
  },
1402
1406
  },
@@ -2127,6 +2131,32 @@ class GraphQLService {
2127
2131
  },
2128
2132
  });
2129
2133
  }
2134
+ if ('directus_users' in schema.update.collections) {
2135
+ schemaComposer.Mutation.addFields({
2136
+ update_users_me: {
2137
+ type: ReadCollectionTypes['directus_users'],
2138
+ args: {
2139
+ data: (0, graphql_compose_1.toInputObjectType)(UpdateCollectionTypes['directus_users']),
2140
+ },
2141
+ resolve: async (_, args, __, info) => {
2142
+ var _a, _b, _c;
2143
+ if (!((_a = this.accountability) === null || _a === void 0 ? void 0 : _a.user))
2144
+ return null;
2145
+ const service = new users_1.UsersService({
2146
+ schema: this.schema,
2147
+ accountability: this.accountability,
2148
+ });
2149
+ await service.updateOne(this.accountability.user, args.data);
2150
+ if ('directus_users' in ReadCollectionTypes) {
2151
+ const selections = this.replaceFragmentsInSelections((_c = (_b = info.fieldNodes[0]) === null || _b === void 0 ? void 0 : _b.selectionSet) === null || _c === void 0 ? void 0 : _c.selections, info.fragments);
2152
+ const query = this.getQuery(args, selections || [], info.variableValues);
2153
+ return await service.readOne(this.accountability.user, query);
2154
+ }
2155
+ return true;
2156
+ },
2157
+ },
2158
+ });
2159
+ }
2130
2160
  if ('directus_activity' in schema.create.collections) {
2131
2161
  schemaComposer.Mutation.addFields({
2132
2162
  create_comment: {
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Knex } from 'knex';
3
- import { AbstractServiceOptions, SchemaOverview } from '../types';
4
- import { Accountability } from '@directus/shared/types';
3
+ import { AbstractServiceOptions } from '../types';
4
+ import { Accountability, SchemaOverview } from '@directus/shared/types';
5
5
  export declare class ImportService {
6
6
  knex: Knex;
7
7
  accountability: Accountability | null;
@@ -31,9 +31,10 @@ class ImportService {
31
31
  case 'application/json':
32
32
  return await this.importJSON(collection, stream);
33
33
  case 'text/csv':
34
+ case 'application/vnd.ms-excel':
34
35
  return await this.importCSV(collection, stream);
35
36
  default:
36
- throw new exceptions_1.InvalidPayloadException(`Can't import files of type "${mimetype}"`);
37
+ throw new exceptions_1.UnsupportedMediaTypeException(`Can't import files of type "${mimetype}"`);
37
38
  }
38
39
  }
39
40
  importJSON(collection, stream) {
@@ -1,7 +1,7 @@
1
1
  import { Knex } from 'knex';
2
2
  import Keyv from 'keyv';
3
- import { Accountability, Query, PermissionsAction } from '@directus/shared/types';
4
- import { AbstractService, AbstractServiceOptions, Item as AnyItem, PrimaryKey, SchemaOverview, MutationOptions } from '../types';
3
+ import { Accountability, Query, PermissionsAction, SchemaOverview } from '@directus/shared/types';
4
+ import { AbstractService, AbstractServiceOptions, Item as AnyItem, PrimaryKey, MutationOptions } from '../types';
5
5
  export declare type QueryOptions = {
6
6
  stripNonRequested?: boolean;
7
7
  permissionsAction?: PermissionsAction;
@@ -70,7 +70,9 @@ class ItemsService {
70
70
  // Run all hooks that are attached to this event so the end user has the chance to augment the
71
71
  // item that is about to be saved
72
72
  const payloadAfterHooks = (opts === null || opts === void 0 ? void 0 : opts.emitEvents) !== false
73
- ? await emitter_1.default.emitFilter(`${this.eventScope}.create`, payload, {
73
+ ? await emitter_1.default.emitFilter(this.eventScope === 'items'
74
+ ? ['items.create', `${this.collection}.items.create`]
75
+ : `${this.eventScope}.create`, payload, {
74
76
  collection: this.collection,
75
77
  }, {
76
78
  database: trx,
@@ -85,7 +87,7 @@ class ItemsService {
85
87
  const { payload: payloadWithA2O, revisions: revisionsA2O } = await payloadService.processA2O(payloadWithM2O);
86
88
  const payloadWithoutAliases = (0, lodash_1.pick)(payloadWithA2O, (0, lodash_1.without)(fields, ...aliases));
87
89
  const payloadWithTypeCasting = await payloadService.processValues('create', payloadWithoutAliases);
88
- // In case of manual string / UUID primary keys, they PK already exists in the object we're saving.
90
+ // In case of manual string / UUID primary keys, the PK already exists in the object we're saving.
89
91
  let primaryKey = payloadWithTypeCasting[primaryKeyField];
90
92
  try {
91
93
  const result = await trx.insert(payloadWithoutAliases).into(this.collection).returning(primaryKeyField);
@@ -146,14 +148,14 @@ class ItemsService {
146
148
  return primaryKey;
147
149
  });
148
150
  if ((opts === null || opts === void 0 ? void 0 : opts.emitEvents) !== false) {
149
- emitter_1.default.emitAction(`${this.eventScope}.create`, {
151
+ emitter_1.default.emitAction(this.eventScope === 'items' ? ['items.create', `${this.collection}.items.create`] : `${this.eventScope}.create`, {
150
152
  payload,
151
153
  key: primaryKey,
152
154
  collection: this.collection,
153
155
  }, {
154
156
  // This hook is called async. If we would pass the transaction here, the hook can be
155
157
  // called after the transaction is done #5460
156
- database: (0, database_1.default)(),
158
+ database: this.knex || (0, database_1.default)(),
157
159
  schema: this.schema,
158
160
  accountability: this.accountability,
159
161
  });
@@ -189,11 +191,6 @@ class ItemsService {
189
191
  * Get items by query
190
192
  */
191
193
  async readByQuery(query, opts) {
192
- const authorizationService = new authorization_1.AuthorizationService({
193
- accountability: this.accountability,
194
- knex: this.knex,
195
- schema: this.schema,
196
- });
197
194
  let ast = await (0, get_ast_from_query_1.default)(this.collection, query, this.schema, {
198
195
  accountability: this.accountability,
199
196
  // By setting the permissions action, you can read items using the permissions for another
@@ -203,6 +200,11 @@ class ItemsService {
203
200
  knex: this.knex,
204
201
  });
205
202
  if (this.accountability && this.accountability.admin !== true) {
203
+ const authorizationService = new authorization_1.AuthorizationService({
204
+ accountability: this.accountability,
205
+ knex: this.knex,
206
+ schema: this.schema,
207
+ });
206
208
  ast = await authorizationService.processAST(ast, opts === null || opts === void 0 ? void 0 : opts.permissionsAction);
207
209
  }
208
210
  const records = await (0, run_ast_1.default)(ast, this.schema, {
@@ -213,7 +215,7 @@ class ItemsService {
213
215
  if (records === null) {
214
216
  throw new exceptions_1.ForbiddenException();
215
217
  }
216
- const filteredRecords = await emitter_1.default.emitFilter(`${this.eventScope}.read`, records, {
218
+ const filteredRecords = await emitter_1.default.emitFilter(this.eventScope === 'items' ? ['items.read', `${this.collection}.items.read`] : `${this.eventScope}.read`, records, {
217
219
  query,
218
220
  collection: this.collection,
219
221
  }, {
@@ -221,12 +223,12 @@ class ItemsService {
221
223
  schema: this.schema,
222
224
  accountability: this.accountability,
223
225
  });
224
- emitter_1.default.emitAction(`${this.eventScope}.read`, {
226
+ emitter_1.default.emitAction(this.eventScope === 'items' ? ['items.read', `${this.collection}.items.read`] : `${this.eventScope}.read`, {
225
227
  payload: filteredRecords,
226
228
  query,
227
229
  collection: this.collection,
228
230
  }, {
229
- database: (0, database_1.default)(),
231
+ database: this.knex || (0, database_1.default)(),
230
232
  schema: this.schema,
231
233
  accountability: this.accountability,
232
234
  });
@@ -288,7 +290,9 @@ class ItemsService {
288
290
  // Run all hooks that are attached to this event so the end user has the chance to augment the
289
291
  // item that is about to be saved
290
292
  const payloadAfterHooks = (opts === null || opts === void 0 ? void 0 : opts.emitEvents) !== false
291
- ? await emitter_1.default.emitFilter(`${this.eventScope}.update`, payload, {
293
+ ? await emitter_1.default.emitFilter(this.eventScope === 'items'
294
+ ? ['items.update', `${this.collection}.items.update`]
295
+ : `${this.eventScope}.update`, payload, {
292
296
  keys,
293
297
  collection: this.collection,
294
298
  }, {
@@ -379,14 +383,14 @@ class ItemsService {
379
383
  await this.cache.clear();
380
384
  }
381
385
  if ((opts === null || opts === void 0 ? void 0 : opts.emitEvents) !== false) {
382
- emitter_1.default.emitAction(`${this.eventScope}.update`, {
386
+ emitter_1.default.emitAction(this.eventScope === 'items' ? ['items.update', `${this.collection}.items.update`] : `${this.eventScope}.update`, {
383
387
  payload,
384
388
  keys,
385
389
  collection: this.collection,
386
390
  }, {
387
391
  // This hook is called async. If we would pass the transaction here, the hook can be
388
392
  // called after the transaction is done #5460
389
- database: (0, database_1.default)(),
393
+ database: this.knex || (0, database_1.default)(),
390
394
  schema: this.schema,
391
395
  accountability: this.accountability,
392
396
  });
@@ -461,7 +465,7 @@ class ItemsService {
461
465
  await authorizationService.checkAccess('delete', this.collection, keys);
462
466
  }
463
467
  if ((opts === null || opts === void 0 ? void 0 : opts.emitEvents) !== false) {
464
- await emitter_1.default.emitFilter(`${this.eventScope}.delete`, keys, {
468
+ await emitter_1.default.emitFilter(this.eventScope === 'items' ? ['items.delete', `${this.collection}.items.delete`] : `${this.eventScope}.delete`, keys, {
465
469
  collection: this.collection,
466
470
  }, {
467
471
  database: this.knex,
@@ -490,13 +494,13 @@ class ItemsService {
490
494
  await this.cache.clear();
491
495
  }
492
496
  if ((opts === null || opts === void 0 ? void 0 : opts.emitEvents) !== false) {
493
- emitter_1.default.emitAction(`${this.eventScope}.delete`, {
497
+ emitter_1.default.emitAction(this.eventScope === 'items' ? ['items.delete', `${this.collection}.items.delete`] : `${this.eventScope}.delete`, {
494
498
  payload: keys,
495
499
  collection: this.collection,
496
500
  }, {
497
501
  // This hook is called async. If we would pass the transaction here, the hook can be
498
502
  // called after the transaction is done #5460
499
- database: (0, database_1.default)(),
503
+ database: this.knex || (0, database_1.default)(),
500
504
  schema: this.schema,
501
505
  accountability: this.accountability,
502
506
  });
@@ -1,6 +1,6 @@
1
1
  import { Knex } from 'knex';
2
- import { AbstractServiceOptions, SchemaOverview } from '../../types';
3
- import { Accountability } from '@directus/shared/types';
2
+ import { AbstractServiceOptions } from '../../types';
3
+ import { Accountability, SchemaOverview } from '@directus/shared/types';
4
4
  import { Transporter, SendMailOptions } from 'nodemailer';
5
5
  export declare type EmailOptions = SendMailOptions & {
6
6
  template?: {
@@ -1,6 +1,6 @@
1
1
  import { Knex } from 'knex';
2
- import { AbstractServiceOptions, SchemaOverview } from '../types';
3
- import { Accountability, Query } from '@directus/shared/types';
2
+ import { AbstractServiceOptions } from '../types';
3
+ import { Accountability, Query, SchemaOverview } from '@directus/shared/types';
4
4
  export declare class MetaService {
5
5
  knex: Knex;
6
6
  accountability: Accountability | null;
@@ -1,6 +1,6 @@
1
1
  import { Knex } from 'knex';
2
- import { AbstractServiceOptions, Item, PrimaryKey, SchemaOverview } from '../types';
3
- import { Accountability } from '@directus/shared/types';
2
+ import { AbstractServiceOptions, Item, PrimaryKey } from '../types';
3
+ import { Accountability, SchemaOverview } from '@directus/shared/types';
4
4
  import { Helpers } from '../database/helpers';
5
5
  declare type Action = 'create' | 'read' | 'update';
6
6
  declare type Transformers = {
@@ -1,10 +1,10 @@
1
1
  import { Knex } from 'knex';
2
- import { AbstractServiceOptions, SchemaOverview, Relation, RelationMeta } from '../types';
3
- import { Accountability } from '@directus/shared/types';
2
+ import { SchemaOverview, Relation, RelationMeta, Accountability } from '@directus/shared/types';
4
3
  import { ItemsService, QueryOptions } from './items';
5
4
  import { PermissionsService } from './permissions';
6
5
  import SchemaInspector from '@directus/schema';
7
6
  import Keyv from 'keyv';
7
+ import { AbstractServiceOptions } from '../types';
8
8
  export declare class RelationsService {
9
9
  knex: Knex;
10
10
  permissionsService: PermissionsService;
@@ -1,6 +1,6 @@
1
1
  import { Knex } from 'knex';
2
- import { AbstractServiceOptions, SchemaOverview } from '../types';
3
- import { Accountability } from '@directus/shared/types';
2
+ import { AbstractServiceOptions } from '../types';
3
+ import { Accountability, SchemaOverview } from '@directus/shared/types';
4
4
  import { SettingsService } from './settings';
5
5
  export declare class ServerService {
6
6
  knex: Knex;
@@ -52,6 +52,7 @@ class ServerService {
52
52
  const projectInfo = await this.settingsService.readSingleton({
53
53
  fields: [
54
54
  'project_name',
55
+ 'project_descriptor',
55
56
  'project_logo',
56
57
  'project_color',
57
58
  'public_foreground',
@@ -46,10 +46,10 @@ class SharesService extends items_1.ItemsService {
46
46
  .from('directus_shares')
47
47
  .where('id', payload.share)
48
48
  .andWhere((subQuery) => {
49
- subQuery.whereNull('date_end').orWhere('date_end', '>=', this.knex.fn.now());
49
+ subQuery.whereNull('date_end').orWhere('date_end', '>=', new Date());
50
50
  })
51
51
  .andWhere((subQuery) => {
52
- subQuery.whereNull('date_start').orWhere('date_start', '<=', this.knex.fn.now());
52
+ subQuery.whereNull('date_start').orWhere('date_start', '<=', new Date());
53
53
  })
54
54
  .andWhere((subQuery) => {
55
55
  subQuery.whereNull('max_uses').orWhere('max_uses', '>=', this.knex.ref('times_used'));
@@ -1,7 +1,7 @@
1
1
  import { Knex } from 'knex';
2
2
  import { OpenAPIObject } from 'openapi3-ts';
3
- import { AbstractServiceOptions, SchemaOverview } from '../types';
4
- import { Accountability } from '@directus/shared/types';
3
+ import { AbstractServiceOptions } from '../types';
4
+ import { Accountability, SchemaOverview } from '@directus/shared/types';
5
5
  import { CollectionsService } from './collections';
6
6
  import { FieldsService } from './fields';
7
7
  import { GraphQLService } from './graphql';
@@ -1,7 +1,6 @@
1
1
  import { Knex } from 'knex';
2
- import { AbstractServiceOptions, Item, PrimaryKey, SchemaOverview, MutationOptions } from '../types';
3
- import { Query } from '@directus/shared/types';
4
- import { Accountability } from '@directus/shared/types';
2
+ import { AbstractServiceOptions, Item, PrimaryKey, MutationOptions } from '../types';
3
+ import { Query, SchemaOverview, Accountability } from '@directus/shared/types';
5
4
  import { ItemsService } from './items';
6
5
  export declare class UsersService extends ItemsService {
7
6
  knex: Knex;
@@ -1,6 +1,6 @@
1
1
  import { Knex } from 'knex';
2
- import { AbstractServiceOptions, PrimaryKey, SchemaOverview } from '../types';
3
- import { Accountability } from '@directus/shared/types';
2
+ import { AbstractServiceOptions, PrimaryKey } from '../types';
3
+ import { Accountability, SchemaOverview } from '@directus/shared/types';
4
4
  export declare class UtilsService {
5
5
  knex: Knex;
6
6
  accountability: Accountability | null;
@@ -1,5 +1,4 @@
1
- import { Query } from '@directus/shared/types';
2
- import { Relation } from './relation';
1
+ import { Query, Relation } from '@directus/shared/types';
3
2
  export declare type M2ONode = {
4
3
  type: 'm2o';
5
4
  name: string;
@@ -1,5 +1,5 @@
1
+ import { SchemaOverview } from '@directus/shared/types';
1
2
  import { Knex } from 'knex';
2
- import { SchemaOverview } from './schema';
3
3
  export interface AuthDriverOptions {
4
4
  knex: Knex;
5
5
  schema: SchemaOverview;
@@ -22,10 +22,8 @@ export declare type AuthData = Record<string, any> | null;
22
22
  export interface Session {
23
23
  token: string;
24
24
  expires: Date;
25
- data: string | Record<string, unknown> | null;
26
25
  share: string;
27
26
  }
28
- export declare type SessionData = Record<string, any> | null;
29
27
  export declare type DirectusTokenPayload = {
30
28
  id?: string;
31
29
  role: string | null;
@@ -3,15 +3,12 @@ export * from './assets';
3
3
  export * from './ast';
4
4
  export * from './auth';
5
5
  export * from './collection';
6
- export * from './extensions';
7
6
  export * from './files';
8
7
  export * from './graphql';
9
8
  export * from './items';
10
9
  export * from './meta';
11
10
  export * from './migration';
12
- export * from './relation';
13
11
  export * from './revision';
14
- export * from './schema';
15
12
  export * from './services';
16
13
  export * from './snapshot';
17
14
  export * from './webhooks';