directus 9.11.1 → 9.12.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 (91) hide show
  1. package/dist/app.js +8 -1
  2. package/dist/cli/utils/create-env/env-stub.liquid +266 -9
  3. package/dist/controllers/activity.js +1 -1
  4. package/dist/controllers/flows.d.ts +2 -0
  5. package/dist/controllers/flows.js +157 -0
  6. package/dist/controllers/folders.js +1 -1
  7. package/dist/controllers/notifications.js +1 -1
  8. package/dist/controllers/operations.d.ts +2 -0
  9. package/dist/controllers/operations.js +138 -0
  10. package/dist/database/index.js +10 -19
  11. package/dist/database/migrations/20220429A-add-flows.d.ts +3 -0
  12. package/dist/database/migrations/20220429A-add-flows.js +83 -0
  13. package/dist/database/migrations/20220429B-add-color-to-insights-icon.d.ts +3 -0
  14. package/dist/database/migrations/20220429B-add-color-to-insights-icon.js +15 -0
  15. package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.d.ts +3 -0
  16. package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.js +15 -0
  17. package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.d.ts +3 -0
  18. package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.js +15 -0
  19. package/dist/database/seeds/05-activity.yaml +0 -1
  20. package/dist/database/system-data/collections/collections.yaml +4 -0
  21. package/dist/database/system-data/fields/flows.yaml +21 -0
  22. package/dist/database/system-data/fields/operations.yaml +19 -0
  23. package/dist/database/system-data/fields/users.yaml +2 -4
  24. package/dist/database/system-data/relations/relations.yaml +20 -0
  25. package/dist/env.d.ts +1 -1
  26. package/dist/env.js +6 -30
  27. package/dist/extensions.d.ts +3 -0
  28. package/dist/extensions.js +73 -20
  29. package/dist/flows.d.ts +17 -0
  30. package/dist/flows.js +310 -0
  31. package/dist/messenger.d.ts +24 -0
  32. package/dist/messenger.js +64 -0
  33. package/dist/operations/condition/index.d.ts +6 -0
  34. package/dist/operations/condition/index.js +15 -0
  35. package/dist/operations/item-create/index.d.ts +8 -0
  36. package/dist/operations/item-create/index.js +40 -0
  37. package/dist/operations/item-delete/index.d.ts +9 -0
  38. package/dist/operations/item-delete/index.js +45 -0
  39. package/dist/operations/item-read/index.d.ts +9 -0
  40. package/dist/operations/item-read/index.js +45 -0
  41. package/dist/operations/item-update/index.d.ts +10 -0
  42. package/dist/operations/item-update/index.js +50 -0
  43. package/dist/operations/log/index.d.ts +5 -0
  44. package/dist/operations/log/index.js +14 -0
  45. package/dist/operations/mail/index.d.ts +7 -0
  46. package/dist/operations/mail/index.js +16 -0
  47. package/dist/operations/notification/index.d.ts +8 -0
  48. package/dist/operations/notification/index.js +39 -0
  49. package/dist/operations/request/index.d.ts +9 -0
  50. package/dist/operations/request/index.js +14 -0
  51. package/dist/operations/sleep/index.d.ts +5 -0
  52. package/dist/operations/sleep/index.js +9 -0
  53. package/dist/operations/transform/index.d.ts +5 -0
  54. package/dist/operations/transform/index.js +10 -0
  55. package/dist/operations/trigger/index.d.ts +6 -0
  56. package/dist/operations/trigger/index.js +21 -0
  57. package/dist/services/activity.d.ts +1 -2
  58. package/dist/services/activity.js +10 -10
  59. package/dist/services/authentication.d.ts +2 -2
  60. package/dist/services/authentication.js +7 -7
  61. package/dist/services/authorization.js +12 -0
  62. package/dist/services/flows.d.ts +14 -0
  63. package/dist/services/flows.js +42 -0
  64. package/dist/services/graphql.js +7 -1
  65. package/dist/services/index.d.ts +2 -0
  66. package/dist/services/index.js +2 -0
  67. package/dist/services/items.js +1 -1
  68. package/dist/services/mail/index.js +2 -1
  69. package/dist/services/notifications.d.ts +2 -1
  70. package/dist/services/notifications.js +4 -3
  71. package/dist/services/operations.d.ts +14 -0
  72. package/dist/services/operations.js +42 -0
  73. package/dist/services/webhooks.d.ts +2 -0
  74. package/dist/services/webhooks.js +8 -7
  75. package/dist/types/events.d.ts +18 -0
  76. package/dist/types/events.js +2 -0
  77. package/dist/types/index.d.ts +1 -1
  78. package/dist/types/index.js +1 -1
  79. package/dist/utils/construct-flow-tree.d.ts +2 -0
  80. package/dist/utils/construct-flow-tree.js +31 -0
  81. package/dist/utils/get-accountability-for-role.d.ts +7 -0
  82. package/dist/utils/get-accountability-for-role.js +36 -0
  83. package/dist/utils/operation-options.d.ts +3 -0
  84. package/dist/utils/operation-options.js +45 -0
  85. package/dist/utils/validate-query.js +1 -1
  86. package/dist/webhooks.d.ts +2 -0
  87. package/dist/webhooks.js +17 -2
  88. package/package.json +18 -14
  89. package/dist/types/activity.d.ts +0 -9
  90. package/dist/types/activity.js +0 -13
  91. package/example.env +0 -202
@@ -0,0 +1,9 @@
1
+ import { PrimaryKey } from '@directus/shared/types';
2
+ declare type Options = {
3
+ collection: string;
4
+ key?: PrimaryKey | PrimaryKey[] | null;
5
+ query?: Record<string, any> | string | null;
6
+ permissions: string;
7
+ };
8
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
9
+ export default _default;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@directus/shared/utils");
4
+ const services_1 = require("../../services");
5
+ const operation_options_1 = require("../../utils/operation-options");
6
+ const get_accountability_for_role_1 = require("../../utils/get-accountability-for-role");
7
+ exports.default = (0, utils_1.defineOperationApi)({
8
+ id: 'item-delete',
9
+ handler: async ({ collection, key, query, permissions }, { accountability, database, getSchema }) => {
10
+ const schema = await getSchema({ database });
11
+ let customAccountability;
12
+ if (!permissions || permissions === '$trigger') {
13
+ customAccountability = accountability;
14
+ }
15
+ else if (permissions === '$full') {
16
+ customAccountability = null;
17
+ }
18
+ else if (permissions === '$public') {
19
+ customAccountability = await (0, get_accountability_for_role_1.getAccountabilityForRole)(null, { database, schema, accountability });
20
+ }
21
+ else {
22
+ customAccountability = await (0, get_accountability_for_role_1.getAccountabilityForRole)(permissions, { database, schema, accountability });
23
+ }
24
+ const itemsService = new services_1.ItemsService(collection, {
25
+ schema: await getSchema({ database }),
26
+ accountability: customAccountability,
27
+ knex: database,
28
+ });
29
+ const queryObject = query ? (0, operation_options_1.optionToObject)(query) : {};
30
+ let result;
31
+ if (!key) {
32
+ result = await itemsService.deleteByQuery(queryObject);
33
+ }
34
+ else {
35
+ const keys = (0, utils_1.toArray)(key);
36
+ if (keys.length === 1) {
37
+ result = await itemsService.deleteOne(keys[0]);
38
+ }
39
+ else {
40
+ result = await itemsService.deleteMany(keys);
41
+ }
42
+ }
43
+ return result;
44
+ },
45
+ });
@@ -0,0 +1,9 @@
1
+ import { PrimaryKey } from '@directus/shared/types';
2
+ declare type Options = {
3
+ collection: string;
4
+ key?: PrimaryKey | PrimaryKey[] | null;
5
+ query?: Record<string, any> | string | null;
6
+ permissions: string;
7
+ };
8
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
9
+ export default _default;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@directus/shared/utils");
4
+ const services_1 = require("../../services");
5
+ const operation_options_1 = require("../../utils/operation-options");
6
+ const get_accountability_for_role_1 = require("../../utils/get-accountability-for-role");
7
+ exports.default = (0, utils_1.defineOperationApi)({
8
+ id: 'item-read',
9
+ handler: async ({ collection, key, query, permissions }, { accountability, database, getSchema }) => {
10
+ const schema = await getSchema({ database });
11
+ let customAccountability;
12
+ if (!permissions || permissions === '$trigger') {
13
+ customAccountability = accountability;
14
+ }
15
+ else if (permissions === '$full') {
16
+ customAccountability = null;
17
+ }
18
+ else if (permissions === '$public') {
19
+ customAccountability = await (0, get_accountability_for_role_1.getAccountabilityForRole)(null, { database, schema, accountability });
20
+ }
21
+ else {
22
+ customAccountability = await (0, get_accountability_for_role_1.getAccountabilityForRole)(permissions, { database, schema, accountability });
23
+ }
24
+ const itemsService = new services_1.ItemsService(collection, {
25
+ schema,
26
+ accountability: customAccountability,
27
+ knex: database,
28
+ });
29
+ const queryObject = query ? (0, operation_options_1.optionToObject)(query) : {};
30
+ let result;
31
+ if (!key) {
32
+ result = await itemsService.readByQuery(queryObject);
33
+ }
34
+ else {
35
+ const keys = (0, utils_1.toArray)(key);
36
+ if (keys.length === 1) {
37
+ result = await itemsService.readOne(keys[0], queryObject);
38
+ }
39
+ else {
40
+ result = await itemsService.readMany(keys, queryObject);
41
+ }
42
+ }
43
+ return result;
44
+ },
45
+ });
@@ -0,0 +1,10 @@
1
+ import { PrimaryKey } from '@directus/shared/types';
2
+ declare type Options = {
3
+ collection: string;
4
+ key?: PrimaryKey | PrimaryKey[] | null;
5
+ payload?: Record<string, any> | string | null;
6
+ query?: Record<string, any> | string | null;
7
+ permissions: string;
8
+ };
9
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
10
+ export default _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@directus/shared/utils");
4
+ const services_1 = require("../../services");
5
+ const operation_options_1 = require("../../utils/operation-options");
6
+ const get_accountability_for_role_1 = require("../../utils/get-accountability-for-role");
7
+ exports.default = (0, utils_1.defineOperationApi)({
8
+ id: 'item-update',
9
+ handler: async ({ collection, key, payload, query, permissions }, { accountability, database, getSchema }) => {
10
+ var _a;
11
+ const schema = await getSchema({ database });
12
+ let customAccountability;
13
+ if (!permissions || permissions === '$trigger') {
14
+ customAccountability = accountability;
15
+ }
16
+ else if (permissions === '$full') {
17
+ customAccountability = null;
18
+ }
19
+ else if (permissions === '$public') {
20
+ customAccountability = await (0, get_accountability_for_role_1.getAccountabilityForRole)(null, { database, schema, accountability });
21
+ }
22
+ else {
23
+ customAccountability = await (0, get_accountability_for_role_1.getAccountabilityForRole)(permissions, { database, schema, accountability });
24
+ }
25
+ const itemsService = new services_1.ItemsService(collection, {
26
+ schema: await getSchema({ database }),
27
+ accountability: customAccountability,
28
+ knex: database,
29
+ });
30
+ const payloadObject = (_a = (0, operation_options_1.optionToObject)(payload)) !== null && _a !== void 0 ? _a : null;
31
+ const queryObject = query ? (0, operation_options_1.optionToObject)(query) : {};
32
+ if (!payloadObject) {
33
+ return null;
34
+ }
35
+ let result;
36
+ if (!key) {
37
+ result = await itemsService.updateByQuery(queryObject, payloadObject);
38
+ }
39
+ else {
40
+ const keys = (0, utils_1.toArray)(key);
41
+ if (keys.length === 1) {
42
+ result = await itemsService.updateOne(keys[0], payloadObject);
43
+ }
44
+ else {
45
+ result = await itemsService.updateMany(keys, payloadObject);
46
+ }
47
+ }
48
+ return result;
49
+ },
50
+ });
@@ -0,0 +1,5 @@
1
+ declare type Options = {
2
+ message: unknown;
3
+ };
4
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
5
+ export default _default;
@@ -0,0 +1,14 @@
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
+ const utils_1 = require("@directus/shared/utils");
7
+ const logger_1 = __importDefault(require("../../logger"));
8
+ const operation_options_1 = require("../../utils/operation-options");
9
+ exports.default = (0, utils_1.defineOperationApi)({
10
+ id: 'log',
11
+ handler: ({ message }) => {
12
+ logger_1.default.info((0, operation_options_1.optionToString)(message));
13
+ },
14
+ });
@@ -0,0 +1,7 @@
1
+ declare type Options = {
2
+ body: string;
3
+ to: string;
4
+ subject: string;
5
+ };
6
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
7
+ export default _default;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@directus/shared/utils");
4
+ const services_1 = require("../../services");
5
+ const md_1 = require("../../utils/md");
6
+ exports.default = (0, utils_1.defineOperationApi)({
7
+ id: 'mail',
8
+ handler: async ({ body, to, subject }, { accountability, database, getSchema }) => {
9
+ const mailService = new services_1.MailService({ schema: await getSchema({ database }), accountability, knex: database });
10
+ await mailService.send({
11
+ html: (0, md_1.md)(body),
12
+ to,
13
+ subject,
14
+ });
15
+ },
16
+ });
@@ -0,0 +1,8 @@
1
+ declare type Options = {
2
+ recipient: string;
3
+ subject: string;
4
+ message?: unknown | null;
5
+ permissions: string;
6
+ };
7
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
8
+ export default _default;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@directus/shared/utils");
4
+ const services_1 = require("../../services");
5
+ const operation_options_1 = require("../../utils/operation-options");
6
+ const get_accountability_for_role_1 = require("../../utils/get-accountability-for-role");
7
+ exports.default = (0, utils_1.defineOperationApi)({
8
+ id: 'notification',
9
+ handler: async ({ recipient, subject, message, permissions }, { accountability, database, getSchema }) => {
10
+ var _a;
11
+ const schema = await getSchema({ database });
12
+ let customAccountability;
13
+ if (!permissions || permissions === '$trigger') {
14
+ customAccountability = accountability;
15
+ }
16
+ else if (permissions === '$full') {
17
+ customAccountability = null;
18
+ }
19
+ else if (permissions === '$public') {
20
+ customAccountability = await (0, get_accountability_for_role_1.getAccountabilityForRole)(null, { database, schema, accountability });
21
+ }
22
+ else {
23
+ customAccountability = await (0, get_accountability_for_role_1.getAccountabilityForRole)(permissions, { database, schema, accountability });
24
+ }
25
+ const notificationsService = new services_1.NotificationsService({
26
+ schema: await getSchema({ database }),
27
+ accountability: customAccountability,
28
+ knex: database,
29
+ });
30
+ const messageString = message ? (0, operation_options_1.optionToString)(message) : null;
31
+ const result = await notificationsService.createOne({
32
+ recipient,
33
+ sender: (_a = customAccountability === null || customAccountability === void 0 ? void 0 : customAccountability.user) !== null && _a !== void 0 ? _a : null,
34
+ subject,
35
+ message: messageString,
36
+ });
37
+ return result;
38
+ },
39
+ });
@@ -0,0 +1,9 @@
1
+ import { Method } from 'axios';
2
+ declare type Options = {
3
+ url: string;
4
+ method: Method;
5
+ body: Record<string, any> | string | null;
6
+ headers: Record<string, string>;
7
+ };
8
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
9
+ export default _default;
@@ -0,0 +1,14 @@
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
+ const utils_1 = require("@directus/shared/utils");
7
+ const axios_1 = __importDefault(require("axios"));
8
+ exports.default = (0, utils_1.defineOperationApi)({
9
+ id: 'request',
10
+ handler: async ({ url, method, body, headers }) => {
11
+ const result = await (0, axios_1.default)({ url, method, data: body, headers });
12
+ return { status: result.status, statusText: result.statusText, headers: result.headers, data: result.data };
13
+ },
14
+ });
@@ -0,0 +1,5 @@
1
+ declare type Options = {
2
+ milliseconds: string | number;
3
+ };
4
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
5
+ export default _default;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@directus/shared/utils");
4
+ exports.default = (0, utils_1.defineOperationApi)({
5
+ id: 'sleep',
6
+ handler: async ({ milliseconds }) => {
7
+ await new Promise((resolve) => setTimeout(resolve, Number(milliseconds)));
8
+ },
9
+ });
@@ -0,0 +1,5 @@
1
+ declare type Options = {
2
+ json: string;
3
+ };
4
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
5
+ export default _default;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@directus/shared/utils");
4
+ const parse_json_1 = require("../../utils/parse-json");
5
+ exports.default = (0, utils_1.defineOperationApi)({
6
+ id: 'transform',
7
+ handler: ({ json }) => {
8
+ return (0, parse_json_1.parseJSON)(json);
9
+ },
10
+ });
@@ -0,0 +1,6 @@
1
+ declare type Options = {
2
+ flow: string;
3
+ payload?: Record<string, any> | Record<string, any>[] | string | null;
4
+ };
5
+ declare const _default: import("@directus/shared/types").OperationApiConfig<Options>;
6
+ export default _default;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@directus/shared/utils");
4
+ const flows_1 = require("../../flows");
5
+ const operation_options_1 = require("../../utils/operation-options");
6
+ exports.default = (0, utils_1.defineOperationApi)({
7
+ id: 'trigger',
8
+ handler: async ({ flow, payload }, context) => {
9
+ var _a;
10
+ const flowManager = (0, flows_1.getFlowManager)();
11
+ const payloadObject = (_a = (0, operation_options_1.optionToObject)(payload)) !== null && _a !== void 0 ? _a : null;
12
+ let result;
13
+ if (Array.isArray(payloadObject)) {
14
+ result = await Promise.all(payloadObject.map((payload) => flowManager.runOperationFlow(flow, payload, context)));
15
+ }
16
+ else {
17
+ result = await flowManager.runOperationFlow(flow, payloadObject, context);
18
+ }
19
+ return result;
20
+ },
21
+ });
@@ -1,6 +1,5 @@
1
- import { AbstractServiceOptions, PrimaryKey, Item } from '../types';
1
+ import { AbstractServiceOptions, Item, MutationOptions, PrimaryKey } from '../types';
2
2
  import { ItemsService } from './items';
3
- import { MutationOptions } from '../types';
4
3
  import { NotificationsService } from './notifications';
5
4
  import { UsersService } from './users';
6
5
  export declare class ActivityService extends ItemsService {
@@ -4,19 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ActivityService = void 0;
7
- const types_1 = require("../types");
8
- const items_1 = require("./items");
9
- const notifications_1 = require("./notifications");
10
- const users_1 = require("./users");
11
- const authorization_1 = require("./authorization");
12
- const get_permissions_1 = require("../utils/get-permissions");
13
- const forbidden_1 = require("../exceptions/forbidden");
14
- const logger_1 = __importDefault(require("../logger"));
15
- const user_name_1 = require("../utils/user-name");
7
+ const types_1 = require("@directus/shared/types");
16
8
  const lodash_1 = require("lodash");
17
- const env_1 = __importDefault(require("../env"));
18
9
  const uuid_validate_1 = __importDefault(require("uuid-validate"));
10
+ const env_1 = __importDefault(require("../env"));
11
+ const forbidden_1 = require("../exceptions/forbidden");
12
+ const logger_1 = __importDefault(require("../logger"));
13
+ const get_permissions_1 = require("../utils/get-permissions");
19
14
  const url_1 = require("../utils/url");
15
+ const user_name_1 = require("../utils/user-name");
16
+ const authorization_1 = require("./authorization");
17
+ const items_1 = require("./items");
18
+ const notifications_1 = require("./notifications");
19
+ const users_1 = require("./users");
20
20
  class ActivityService extends items_1.ItemsService {
21
21
  constructor(options) {
22
22
  super('directus_activity', options);
@@ -1,7 +1,7 @@
1
+ import { Accountability, SchemaOverview } from '@directus/shared/types';
1
2
  import { Knex } from 'knex';
2
- import { ActivityService } from './activity';
3
3
  import { AbstractServiceOptions, LoginResult } from '../types';
4
- import { Accountability, SchemaOverview } from '@directus/shared/types';
4
+ import { ActivityService } from './activity';
5
5
  export declare class AuthenticationService {
6
6
  knex: Knex;
7
7
  accountability: Accountability | null;
@@ -4,23 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.AuthenticationService = void 0;
7
+ const types_1 = require("@directus/shared/types");
7
8
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
9
+ const lodash_1 = require("lodash");
8
10
  const ms_1 = __importDefault(require("ms"));
9
11
  const nanoid_1 = require("nanoid");
12
+ const perf_hooks_1 = require("perf_hooks");
13
+ const auth_1 = require("../auth");
14
+ const constants_1 = require("../constants");
10
15
  const database_1 = __importDefault(require("../database"));
11
16
  const emitter_1 = __importDefault(require("../emitter"));
12
17
  const env_1 = __importDefault(require("../env"));
13
- const auth_1 = require("../auth");
14
- const constants_1 = require("../constants");
15
18
  const exceptions_1 = require("../exceptions");
16
19
  const rate_limiter_1 = require("../rate-limiter");
20
+ const stall_1 = require("../utils/stall");
17
21
  const activity_1 = require("./activity");
18
- const tfa_1 = require("./tfa");
19
- const types_1 = require("../types");
20
22
  const settings_1 = require("./settings");
21
- const lodash_1 = require("lodash");
22
- const perf_hooks_1 = require("perf_hooks");
23
- const stall_1 = require("../utils/stall");
23
+ const tfa_1 = require("./tfa");
24
24
  const loginAttemptsLimiter = (0, rate_limiter_1.createRateLimiter)({ duration: 0 });
25
25
  class AuthenticationService {
26
26
  constructor(options) {
@@ -12,6 +12,7 @@ const exceptions_2 = require("../exceptions");
12
12
  const strip_function_1 = require("../utils/strip-function");
13
13
  const items_1 = require("./items");
14
14
  const payload_1 = require("./payload");
15
+ const get_relation_info_1 = require("../utils/get-relation-info");
15
16
  class AuthorizationService {
16
17
  constructor(options) {
17
18
  this.knex = options.knex || (0, database_1.default)();
@@ -161,6 +162,15 @@ class AuthorizationService {
161
162
  // Filter value is not a filter, so we should skip it
162
163
  return result;
163
164
  }
165
+ // virtual o2m/o2a filter in the form of `$FOLLOW(...)`
166
+ else if (collection && filterKey.startsWith('$FOLLOW')) {
167
+ (result[collection] || (result[collection] = new Set())).add(filterKey);
168
+ // add virtual relation to the required permissions
169
+ const { relation } = (0, get_relation_info_1.getRelationInfo)([], collection, filterKey);
170
+ if ((relation === null || relation === void 0 ? void 0 : relation.collection) && (relation === null || relation === void 0 ? void 0 : relation.field)) {
171
+ (result[relation.collection] || (result[relation.collection] = new Set())).add(relation.field);
172
+ }
173
+ }
164
174
  // m2a filter in the form of `item:collection`
165
175
  else if (filterKey.includes(':')) {
166
176
  const [field, collectionScope] = filterKey.split(':');
@@ -271,6 +281,8 @@ class AuthorizationService {
271
281
  if (allowedFields.length === 0)
272
282
  allowedFields.push(schema.collections[collection].primary);
273
283
  for (const field of requiredPermissions[collection]) {
284
+ if (field.startsWith('$FOLLOW'))
285
+ continue;
274
286
  if (!allowedFields.includes(field))
275
287
  throw new exceptions_2.ForbiddenException();
276
288
  }
@@ -0,0 +1,14 @@
1
+ import { FlowRaw } from '@directus/shared/types';
2
+ import { Messenger } from '../messenger';
3
+ import { AbstractServiceOptions, Item, MutationOptions, PrimaryKey } from '../types';
4
+ import { ItemsService } from './items';
5
+ export declare class FlowsService extends ItemsService<FlowRaw> {
6
+ messenger: Messenger;
7
+ constructor(options: AbstractServiceOptions);
8
+ createOne(data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey>;
9
+ createMany(data: Partial<Item>[], opts?: MutationOptions): Promise<PrimaryKey[]>;
10
+ updateOne(key: PrimaryKey, data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey>;
11
+ updateMany(keys: PrimaryKey[], data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey[]>;
12
+ deleteOne(key: PrimaryKey, opts?: MutationOptions): Promise<PrimaryKey>;
13
+ deleteMany(keys: PrimaryKey[], opts?: MutationOptions): Promise<PrimaryKey[]>;
14
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowsService = void 0;
4
+ const messenger_1 = require("../messenger");
5
+ const items_1 = require("./items");
6
+ class FlowsService extends items_1.ItemsService {
7
+ constructor(options) {
8
+ super('directus_flows', options);
9
+ this.messenger = (0, messenger_1.getMessenger)();
10
+ }
11
+ async createOne(data, opts) {
12
+ const result = await super.createOne(data, opts);
13
+ this.messenger.publish('flows', { type: 'reload' });
14
+ return result;
15
+ }
16
+ async createMany(data, opts) {
17
+ const result = await super.createMany(data, opts);
18
+ this.messenger.publish('flows', { type: 'reload' });
19
+ return result;
20
+ }
21
+ async updateOne(key, data, opts) {
22
+ const result = await super.updateOne(key, data, opts);
23
+ this.messenger.publish('flows', { type: 'reload' });
24
+ return result;
25
+ }
26
+ async updateMany(keys, data, opts) {
27
+ const result = await super.updateMany(keys, data, opts);
28
+ this.messenger.publish('flows', { type: 'reload' });
29
+ return result;
30
+ }
31
+ async deleteOne(key, opts) {
32
+ const result = await super.deleteOne(key, opts);
33
+ this.messenger.publish('flows', { type: 'reload' });
34
+ return result;
35
+ }
36
+ async deleteMany(keys, opts) {
37
+ const result = await super.deleteMany(keys, opts);
38
+ this.messenger.publish('flows', { type: 'reload' });
39
+ return result;
40
+ }
41
+ }
42
+ exports.FlowsService = FlowsService;
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.GraphQLService = exports.GraphQLDate = exports.GraphQLGeoJSON = void 0;
7
+ const types_1 = require("@directus/shared/types");
7
8
  const argon2_1 = __importDefault(require("argon2"));
8
9
  const graphql_1 = require("graphql");
9
10
  const graphql_compose_1 = require("graphql-compose");
@@ -15,7 +16,6 @@ const database_1 = __importDefault(require("../database"));
15
16
  const env_1 = __importDefault(require("../env"));
16
17
  const exceptions_1 = require("../exceptions");
17
18
  const extensions_1 = require("../extensions");
18
- const types_1 = require("../types");
19
19
  const generate_hash_1 = require("../utils/generate-hash");
20
20
  const get_graphql_type_1 = require("../utils/get-graphql-type");
21
21
  const reduce_schema_1 = require("../utils/reduce-schema");
@@ -26,9 +26,11 @@ const authentication_1 = require("./authentication");
26
26
  const collections_1 = require("./collections");
27
27
  const fields_1 = require("./fields");
28
28
  const files_1 = require("./files");
29
+ const flows_1 = require("./flows");
29
30
  const folders_1 = require("./folders");
30
31
  const items_1 = require("./items");
31
32
  const notifications_1 = require("./notifications");
33
+ const operations_1 = require("./operations");
32
34
  const permissions_1 = require("./permissions");
33
35
  const presets_1 = require("./presets");
34
36
  const relations_1 = require("./relations");
@@ -1354,6 +1356,10 @@ class GraphQLService {
1354
1356
  return new webhooks_1.WebhooksService(opts);
1355
1357
  case 'directus_shares':
1356
1358
  return new shares_1.SharesService(opts);
1359
+ case 'directus_flows':
1360
+ return new flows_1.FlowsService(opts);
1361
+ case 'directus_operations':
1362
+ return new operations_1.OperationsService(opts);
1357
1363
  default:
1358
1364
  return new items_1.ItemsService(collection, opts);
1359
1365
  }
@@ -7,12 +7,14 @@ export * from './collections';
7
7
  export * from './dashboards';
8
8
  export * from './fields';
9
9
  export * from './files';
10
+ export * from './flows';
10
11
  export * from './folders';
11
12
  export * from './graphql';
12
13
  export * from './import-export';
13
14
  export * from './mail';
14
15
  export * from './meta';
15
16
  export * from './notifications';
17
+ export * from './operations';
16
18
  export * from './panels';
17
19
  export * from './payload';
18
20
  export * from './permissions';
@@ -20,12 +20,14 @@ __exportStar(require("./collections"), exports);
20
20
  __exportStar(require("./dashboards"), exports);
21
21
  __exportStar(require("./fields"), exports);
22
22
  __exportStar(require("./files"), exports);
23
+ __exportStar(require("./flows"), exports);
23
24
  __exportStar(require("./folders"), exports);
24
25
  __exportStar(require("./graphql"), exports);
25
26
  __exportStar(require("./import-export"), exports);
26
27
  __exportStar(require("./mail"), exports);
27
28
  __exportStar(require("./meta"), exports);
28
29
  __exportStar(require("./notifications"), exports);
30
+ __exportStar(require("./operations"), exports);
29
31
  __exportStar(require("./panels"), exports);
30
32
  __exportStar(require("./payload"), exports);
31
33
  __exportStar(require("./permissions"), exports);
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ItemsService = void 0;
7
+ const types_1 = require("@directus/shared/types");
7
8
  const lodash_1 = require("lodash");
8
9
  const cache_1 = require("../cache");
9
10
  const database_1 = __importDefault(require("../database"));
@@ -12,7 +13,6 @@ const emitter_1 = __importDefault(require("../emitter"));
12
13
  const env_1 = __importDefault(require("../env"));
13
14
  const exceptions_1 = require("../exceptions");
14
15
  const translate_1 = require("../exceptions/database/translate");
15
- const types_1 = require("../types");
16
16
  const get_ast_from_query_1 = __importDefault(require("../utils/get-ast-from-query"));
17
17
  const authorization_1 = require("./authorization");
18
18
  const index_1 = require("./index");