directus 9.10.0 → 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 (141) hide show
  1. package/dist/app.js +8 -1
  2. package/dist/auth/drivers/oauth2.d.ts +1 -1
  3. package/dist/auth/drivers/oauth2.js +14 -11
  4. package/dist/auth/drivers/openid.d.ts +1 -1
  5. package/dist/auth/drivers/openid.js +14 -11
  6. package/dist/cli/commands/schema/apply.js +4 -3
  7. package/dist/cli/utils/create-env/env-stub.liquid +266 -9
  8. package/dist/controllers/activity.js +1 -1
  9. package/dist/controllers/assets.js +8 -9
  10. package/dist/controllers/flows.d.ts +2 -0
  11. package/dist/controllers/flows.js +157 -0
  12. package/dist/controllers/folders.js +1 -1
  13. package/dist/controllers/notifications.js +1 -1
  14. package/dist/controllers/operations.d.ts +2 -0
  15. package/dist/controllers/operations.js +138 -0
  16. package/dist/database/helpers/date/dialects/sqlite.js +6 -2
  17. package/dist/database/index.js +15 -19
  18. package/dist/database/migrations/20210225A-add-relations-sort-field.js +2 -1
  19. package/dist/database/migrations/20210506A-rename-interfaces.js +2 -1
  20. package/dist/database/migrations/20210802A-replace-groups.js +2 -1
  21. package/dist/database/migrations/20210805A-update-groups.js +2 -1
  22. package/dist/database/migrations/20210805B-change-image-metadata-structure.js +3 -2
  23. package/dist/database/migrations/20211007A-update-presets.js +5 -4
  24. package/dist/database/migrations/20220429A-add-flows.d.ts +3 -0
  25. package/dist/database/migrations/20220429A-add-flows.js +83 -0
  26. package/dist/database/migrations/20220429B-add-color-to-insights-icon.d.ts +3 -0
  27. package/dist/database/migrations/20220429B-add-color-to-insights-icon.js +15 -0
  28. package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.d.ts +3 -0
  29. package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.js +15 -0
  30. package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.d.ts +3 -0
  31. package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.js +15 -0
  32. package/dist/database/run-ast.js +10 -14
  33. package/dist/database/seeds/05-activity.yaml +0 -1
  34. package/dist/database/system-data/collections/collections.yaml +4 -0
  35. package/dist/database/system-data/fields/activity.yaml +3 -0
  36. package/dist/database/system-data/fields/dashboards.yaml +3 -1
  37. package/dist/database/system-data/fields/flows.yaml +21 -0
  38. package/dist/database/system-data/fields/notifications.yaml +3 -1
  39. package/dist/database/system-data/fields/operations.yaml +19 -0
  40. package/dist/database/system-data/fields/panels.yaml +3 -1
  41. package/dist/database/system-data/fields/shares.yaml +3 -1
  42. package/dist/database/system-data/fields/users.yaml +2 -4
  43. package/dist/database/system-data/relations/relations.yaml +20 -0
  44. package/dist/env.d.ts +1 -1
  45. package/dist/env.js +167 -12
  46. package/dist/exceptions/index.d.ts +1 -0
  47. package/dist/exceptions/index.js +1 -0
  48. package/dist/exceptions/invalid-provider.d.ts +4 -0
  49. package/dist/exceptions/invalid-provider.js +10 -0
  50. package/dist/exceptions/range-not-satisfiable.d.ts +2 -2
  51. package/dist/exceptions/range-not-satisfiable.js +5 -1
  52. package/dist/extensions.d.ts +3 -0
  53. package/dist/extensions.js +73 -20
  54. package/dist/flows.d.ts +17 -0
  55. package/dist/flows.js +310 -0
  56. package/dist/messenger.d.ts +24 -0
  57. package/dist/messenger.js +64 -0
  58. package/dist/middleware/graphql.js +2 -1
  59. package/dist/operations/condition/index.d.ts +6 -0
  60. package/dist/operations/condition/index.js +15 -0
  61. package/dist/operations/item-create/index.d.ts +8 -0
  62. package/dist/operations/item-create/index.js +40 -0
  63. package/dist/operations/item-delete/index.d.ts +9 -0
  64. package/dist/operations/item-delete/index.js +45 -0
  65. package/dist/operations/item-read/index.d.ts +9 -0
  66. package/dist/operations/item-read/index.js +45 -0
  67. package/dist/operations/item-update/index.d.ts +10 -0
  68. package/dist/operations/item-update/index.js +50 -0
  69. package/dist/operations/log/index.d.ts +5 -0
  70. package/dist/operations/log/index.js +14 -0
  71. package/dist/operations/mail/index.d.ts +7 -0
  72. package/dist/operations/mail/index.js +16 -0
  73. package/dist/operations/notification/index.d.ts +8 -0
  74. package/dist/operations/notification/index.js +39 -0
  75. package/dist/operations/request/index.d.ts +9 -0
  76. package/dist/operations/request/index.js +14 -0
  77. package/dist/operations/sleep/index.d.ts +5 -0
  78. package/dist/operations/sleep/index.js +9 -0
  79. package/dist/operations/transform/index.d.ts +5 -0
  80. package/dist/operations/transform/index.js +10 -0
  81. package/dist/operations/trigger/index.d.ts +6 -0
  82. package/dist/operations/trigger/index.js +21 -0
  83. package/dist/services/activity.d.ts +1 -2
  84. package/dist/services/activity.js +10 -10
  85. package/dist/services/assets.js +27 -1
  86. package/dist/services/authentication.d.ts +2 -2
  87. package/dist/services/authentication.js +11 -8
  88. package/dist/services/authorization.js +12 -0
  89. package/dist/services/fields.js +15 -8
  90. package/dist/services/flows.d.ts +14 -0
  91. package/dist/services/flows.js +42 -0
  92. package/dist/services/graphql.js +56 -33
  93. package/dist/services/import-export.d.ts +1 -1
  94. package/dist/services/import-export.js +13 -12
  95. package/dist/services/index.d.ts +2 -0
  96. package/dist/services/index.js +2 -0
  97. package/dist/services/items.d.ts +3 -3
  98. package/dist/services/items.js +25 -2
  99. package/dist/services/mail/index.js +2 -1
  100. package/dist/services/notifications.d.ts +2 -1
  101. package/dist/services/notifications.js +4 -3
  102. package/dist/services/operations.d.ts +14 -0
  103. package/dist/services/operations.js +42 -0
  104. package/dist/services/payload.d.ts +2 -2
  105. package/dist/services/payload.js +8 -7
  106. package/dist/services/users.d.ts +4 -0
  107. package/dist/services/users.js +20 -0
  108. package/dist/services/webhooks.d.ts +2 -0
  109. package/dist/services/webhooks.js +8 -7
  110. package/dist/types/events.d.ts +18 -0
  111. package/dist/types/events.js +2 -0
  112. package/dist/types/index.d.ts +1 -1
  113. package/dist/types/index.js +1 -1
  114. package/dist/utils/apply-query.js +31 -4
  115. package/dist/utils/apply-snapshot.d.ts +3 -3
  116. package/dist/utils/apply-snapshot.js +64 -49
  117. package/dist/utils/construct-flow-tree.d.ts +2 -0
  118. package/dist/utils/construct-flow-tree.js +31 -0
  119. package/dist/utils/get-accountability-for-role.d.ts +7 -0
  120. package/dist/utils/get-accountability-for-role.js +36 -0
  121. package/dist/utils/get-ast-from-query.js +1 -7
  122. package/dist/utils/get-default-value.js +4 -3
  123. package/dist/utils/get-permissions.d.ts +1 -1
  124. package/dist/utils/get-permissions.js +9 -8
  125. package/dist/utils/get-schema.js +2 -1
  126. package/dist/utils/get-snapshot.js +22 -4
  127. package/dist/utils/operation-options.d.ts +3 -0
  128. package/dist/utils/operation-options.js +45 -0
  129. package/dist/utils/parse-json.d.ts +5 -0
  130. package/dist/utils/parse-json.js +19 -0
  131. package/dist/utils/sanitize-query.d.ts +1 -2
  132. package/dist/utils/sanitize-query.js +6 -5
  133. package/dist/utils/validate-keys.d.ts +6 -0
  134. package/dist/utils/validate-keys.js +28 -0
  135. package/dist/utils/validate-query.js +1 -1
  136. package/dist/webhooks.d.ts +2 -0
  137. package/dist/webhooks.js +17 -2
  138. package/package.json +18 -14
  139. package/dist/types/activity.d.ts +0 -9
  140. package/dist/types/activity.js +0 -13
  141. package/example.env +0 -202
@@ -0,0 +1,40 @@
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-create',
9
+ handler: async ({ collection, payload, emitEvents, 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
+ let result;
32
+ if (!payloadObject) {
33
+ result = null;
34
+ }
35
+ else {
36
+ result = await itemsService.createMany((0, utils_1.toArray)(payloadObject), { emitEvents });
37
+ }
38
+ return result;
39
+ },
40
+ });
@@ -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);
@@ -70,9 +70,35 @@ class AssetsService {
70
70
  if (!exists)
71
71
  throw new exceptions_1.ForbiddenException();
72
72
  if (range) {
73
- if (range.start >= file.filesize || (range.end && range.end >= file.filesize)) {
73
+ const missingRangeLimits = range.start === undefined && range.end === undefined;
74
+ const endBeforeStart = range.start !== undefined && range.end !== undefined && range.end <= range.start;
75
+ const startOverflow = range.start !== undefined && range.start >= file.filesize;
76
+ const endUnderflow = range.end !== undefined && range.end <= 0;
77
+ if (missingRangeLimits || endBeforeStart || startOverflow || endUnderflow) {
74
78
  throw new exceptions_1.RangeNotSatisfiableException(range);
75
79
  }
80
+ const lastByte = file.filesize - 1;
81
+ if (range.end) {
82
+ if (range.start === undefined) {
83
+ // fetch chunk from tail
84
+ range.start = file.filesize - range.end;
85
+ range.end = lastByte;
86
+ }
87
+ if (range.end >= file.filesize) {
88
+ // fetch entire file
89
+ range.end = lastByte;
90
+ }
91
+ }
92
+ if (range.start) {
93
+ if (range.end === undefined) {
94
+ // fetch entire file
95
+ range.end = lastByte;
96
+ }
97
+ if (range.start < 0) {
98
+ // fetch file from head
99
+ range.start = 0;
100
+ }
101
+ }
76
102
  }
77
103
  const type = file.type;
78
104
  const transforms = TransformationUtils.resolvePreset(transformation, file);
@@ -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) {
@@ -45,7 +45,6 @@ class AuthenticationService {
45
45
  .from('directus_users as u')
46
46
  .leftJoin('directus_roles as r', 'u.role', 'r.id')
47
47
  .where('u.id', await provider.getUserID((0, lodash_1.cloneDeep)(payload)))
48
- .andWhere('u.provider', providerName)
49
48
  .first();
50
49
  const updatedPayload = await emitter_1.default.emitFilter('auth.login', payload, {
51
50
  status: 'pending',
@@ -79,6 +78,10 @@ class AuthenticationService {
79
78
  throw new exceptions_1.InvalidCredentialsException();
80
79
  }
81
80
  }
81
+ else if (user.provider !== providerName) {
82
+ await (0, stall_1.stall)(STALL_TIME, timeStart);
83
+ throw new exceptions_1.InvalidProviderException();
84
+ }
82
85
  const settingsService = new settings_1.SettingsService({
83
86
  knex: this.knex,
84
87
  schema: this.schema,
@@ -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
  }
@@ -351,13 +351,6 @@ class FieldsService {
351
351
  });
352
352
  await this.knex.transaction(async (trx) => {
353
353
  var _a, _b;
354
- if (this.schema.collections[collection] &&
355
- field in this.schema.collections[collection].fields &&
356
- this.schema.collections[collection].fields[field].alias === false) {
357
- await trx.schema.table(collection, (table) => {
358
- table.dropColumn(field);
359
- });
360
- }
361
354
  const relations = this.schema.relations.filter((relation) => {
362
355
  var _a;
363
356
  return ((relation.collection === collection && relation.field === field) ||
@@ -389,6 +382,14 @@ class FieldsService {
389
382
  .where({ many_collection: relation.collection, many_field: relation.field });
390
383
  }
391
384
  }
385
+ // Delete field only after foreign key constraints are removed
386
+ if (this.schema.collections[collection] &&
387
+ field in this.schema.collections[collection].fields &&
388
+ this.schema.collections[collection].fields[field].alias === false) {
389
+ await trx.schema.table(collection, (table) => {
390
+ table.dropColumn(field);
391
+ });
392
+ }
392
393
  const collectionMeta = await trx
393
394
  .select('archive_field', 'sort_field')
394
395
  .from('directus_collections')
@@ -441,7 +442,13 @@ class FieldsService {
441
442
  if (field.type === 'alias' || field.type === 'unknown')
442
443
  return;
443
444
  if ((_a = field.schema) === null || _a === void 0 ? void 0 : _a.has_auto_increment) {
444
- column = table.increments(field.field);
445
+ if (field.type === 'bigInteger') {
446
+ // Create an auto-incremented big integer (MySQL, PostgreSQL) or an auto-incremented integer (other DBs)
447
+ column = table.bigIncrements(field.field);
448
+ }
449
+ else {
450
+ column = table.increments(field.field);
451
+ }
445
452
  }
446
453
  else if (field.type === 'string') {
447
454
  column = table.string(field.field, (_c = (_b = field.schema) === null || _b === void 0 ? void 0 : _b.max_length) !== null && _c !== void 0 ? _c : undefined);
@@ -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
+ }