directus 9.20.4 → 9.21.2

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 (143) hide show
  1. package/dist/auth/drivers/openid.js +3 -1
  2. package/dist/cli/commands/schema/apply.js +0 -2
  3. package/dist/cli/commands/schema/snapshot.js +0 -2
  4. package/dist/cli/utils/create-db-connection.d.ts +1 -1
  5. package/dist/controllers/extensions.js +4 -13
  6. package/dist/database/helpers/date/dialects/sqlite.d.ts +1 -1
  7. package/dist/database/helpers/date/dialects/sqlite.js +4 -0
  8. package/dist/database/helpers/date/types.d.ts +1 -1
  9. package/dist/database/helpers/date/types.js +4 -0
  10. package/dist/database/helpers/fn/dialects/mssql.d.ts +8 -8
  11. package/dist/database/helpers/fn/dialects/mssql.js +22 -16
  12. package/dist/database/helpers/fn/dialects/mysql.d.ts +8 -8
  13. package/dist/database/helpers/fn/dialects/mysql.js +22 -16
  14. package/dist/database/helpers/fn/dialects/postgres.d.ts +8 -8
  15. package/dist/database/helpers/fn/dialects/postgres.js +22 -16
  16. package/dist/database/helpers/fn/types.d.ts +1 -1
  17. package/dist/database/helpers/index.d.ts +1 -1
  18. package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +1 -0
  19. package/dist/database/helpers/schema/dialects/cockroachdb.js +11 -0
  20. package/dist/database/helpers/schema/types.d.ts +3 -2
  21. package/dist/database/helpers/schema/types.js +5 -0
  22. package/dist/database/migrations/run.js +29 -3
  23. package/dist/database/run-ast.d.ts +1 -1
  24. package/dist/database/run-ast.js +1 -1
  25. package/dist/env.d.ts +4 -0
  26. package/dist/env.js +9 -4
  27. package/dist/env.test.d.ts +1 -8
  28. package/dist/exceptions/database/contains-null-values.d.ts +1 -1
  29. package/dist/exceptions/database/dialects/types.d.ts +6 -6
  30. package/dist/exceptions/database/invalid-foreign-key.d.ts +1 -1
  31. package/dist/exceptions/database/not-null-violation.d.ts +1 -1
  32. package/dist/exceptions/database/record-not-unique.d.ts +1 -1
  33. package/dist/exceptions/database/value-out-of-range.d.ts +1 -1
  34. package/dist/exceptions/database/value-too-long.d.ts +1 -1
  35. package/dist/exceptions/hit-rate-limit.d.ts +1 -1
  36. package/dist/exceptions/method-not-allowed.d.ts +1 -1
  37. package/dist/exceptions/service-unavailable.d.ts +1 -1
  38. package/dist/extensions.d.ts +7 -7
  39. package/dist/extensions.js +92 -89
  40. package/dist/logger.d.ts +1 -0
  41. package/dist/messenger.d.ts +1 -1
  42. package/dist/middleware/authenticate.d.ts +1 -0
  43. package/dist/middleware/schema.js +1 -1
  44. package/dist/middleware/validate-batch.d.ts +2 -0
  45. package/dist/operations/condition/index.d.ts +1 -1
  46. package/dist/operations/condition/index.js +1 -1
  47. package/dist/operations/condition/index.test.d.ts +1 -0
  48. package/dist/operations/exec/index.d.ts +1 -1
  49. package/dist/operations/item-create/index.d.ts +1 -1
  50. package/dist/operations/item-delete/index.d.ts +1 -1
  51. package/dist/operations/item-read/index.d.ts +1 -1
  52. package/dist/operations/item-update/index.d.ts +1 -1
  53. package/dist/operations/log/index.d.ts +1 -1
  54. package/dist/operations/mail/index.d.ts +1 -1
  55. package/dist/operations/notification/index.d.ts +1 -1
  56. package/dist/operations/request/index.d.ts +1 -1
  57. package/dist/operations/sleep/index.d.ts +1 -1
  58. package/dist/operations/transform/index.d.ts +1 -1
  59. package/dist/operations/trigger/index.d.ts +1 -1
  60. package/dist/operations/trigger/index.js +5 -2
  61. package/dist/rate-limiter.d.ts +1 -1
  62. package/dist/services/authorization.js +7 -3
  63. package/dist/services/collections.d.ts +1 -1
  64. package/dist/services/collections.js +112 -13
  65. package/dist/services/fields.d.ts +5 -4
  66. package/dist/services/fields.js +118 -50
  67. package/dist/services/fields.test.d.ts +1 -0
  68. package/dist/services/graphql/index.js +4 -1
  69. package/dist/services/graphql/utils/process-error.d.ts +4 -0
  70. package/dist/services/graphql/utils/process-error.js +26 -0
  71. package/dist/services/graphql/utils/process-error.test.d.ts +1 -0
  72. package/dist/services/items.d.ts +1 -1
  73. package/dist/services/items.js +39 -13
  74. package/dist/services/mail/index.d.ts +2 -2
  75. package/dist/services/mail/index.js +2 -1
  76. package/dist/services/mail/templates/base.liquid +4 -4
  77. package/dist/services/notifications.js +9 -4
  78. package/dist/services/notifications.test.d.ts +1 -0
  79. package/dist/services/payload.d.ts +2 -2
  80. package/dist/services/payload.js +14 -12
  81. package/dist/services/relations.d.ts +4 -4
  82. package/dist/services/relations.js +66 -8
  83. package/dist/services/users.js +8 -2
  84. package/dist/services/users.test.d.ts +1 -0
  85. package/dist/types/assets.d.ts +7 -7
  86. package/dist/types/ast.d.ts +7 -7
  87. package/dist/types/auth.d.ts +4 -4
  88. package/dist/types/collection.d.ts +2 -2
  89. package/dist/types/events.d.ts +1 -1
  90. package/dist/types/files.d.ts +2 -2
  91. package/dist/types/items.d.ts +5 -5
  92. package/dist/types/migration.d.ts +1 -1
  93. package/dist/types/revision.d.ts +1 -1
  94. package/dist/types/services.d.ts +1 -1
  95. package/dist/types/snapshot.d.ts +4 -4
  96. package/dist/types/webhooks.d.ts +2 -2
  97. package/dist/utils/apply-snapshot.js +32 -13
  98. package/dist/utils/get-ast-from-query.d.ts +1 -1
  99. package/dist/utils/get-column-path.d.ts +2 -2
  100. package/dist/utils/get-module-default.d.ts +1 -1
  101. package/dist/utils/get-relation-info.d.ts +1 -1
  102. package/dist/utils/get-schema.d.ts +6 -2
  103. package/dist/utils/get-schema.js +1 -1
  104. package/dist/utils/get-snapshot.js +1 -1
  105. package/dist/utils/job-queue.d.ts +1 -1
  106. package/dist/utils/merge-permissions.d.ts +1 -0
  107. package/dist/utils/reduce-schema.js +3 -1
  108. package/package.json +69 -80
  109. package/dist/__mocks__/cache.d.ts +0 -5
  110. package/dist/__mocks__/cache.js +0 -7
  111. package/dist/__utils__/items-utils.d.ts +0 -2
  112. package/dist/__utils__/items-utils.js +0 -36
  113. package/dist/__utils__/schemas.d.ts +0 -13
  114. package/dist/__utils__/schemas.js +0 -304
  115. package/dist/__utils__/snapshots.d.ts +0 -5
  116. package/dist/__utils__/snapshots.js +0 -897
  117. package/dist/cli/index.test.js +0 -63
  118. package/dist/controllers/files.test.js +0 -49
  119. package/dist/database/migrations/run.test.js +0 -92
  120. package/dist/env.test.js +0 -40
  121. package/dist/middleware/authenticate.test.js +0 -214
  122. package/dist/middleware/extract-token.test.js +0 -60
  123. package/dist/middleware/validate-batch.test.js +0 -82
  124. package/dist/operations/exec/index.test.js +0 -95
  125. package/dist/services/files.test.js +0 -89
  126. package/dist/services/items.test.js +0 -765
  127. package/dist/services/payload.test.js +0 -196
  128. package/dist/services/specifications.test.js +0 -96
  129. package/dist/utils/apply-snapshot.test.js +0 -305
  130. package/dist/utils/async-handler.test.js +0 -18
  131. package/dist/utils/calculate-field-depth.test.js +0 -76
  132. package/dist/utils/filter-items.test.js +0 -60
  133. package/dist/utils/get-auth-providers.test.js +0 -72
  134. package/dist/utils/get-cache-key.test.js +0 -74
  135. package/dist/utils/get-column-path.test.js +0 -136
  136. package/dist/utils/get-config-from-env.test.js +0 -19
  137. package/dist/utils/get-relation-info.test.js +0 -88
  138. package/dist/utils/get-relation-type.test.js +0 -69
  139. package/dist/utils/get-string-byte-size.test.js +0 -8
  140. package/dist/utils/is-directus-jwt.test.js +0 -26
  141. package/dist/utils/jwt.test.js +0 -36
  142. package/dist/utils/merge-permissions.test.js +0 -80
  143. package/dist/utils/validate-keys.test.js +0 -97
@@ -1,95 +0,0 @@
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 vm2_1 = require("vm2");
7
- const index_1 = __importDefault(require("./index"));
8
- test('Rejects when modules are used without modules being allowed', async () => {
9
- const testCode = `
10
- const test = require('test');
11
- `;
12
- await expect(index_1.default.handler({ code: testCode }, {
13
- data: {},
14
- env: {
15
- FLOWS_EXEC_ALLOWED_MODULES: '',
16
- },
17
- })).rejects.toEqual(new vm2_1.VMError("Cannot find module 'test'"));
18
- });
19
- test('Rejects when code contains syntax errors', async () => {
20
- const testCode = `
21
- ~~
22
- `;
23
- await expect(index_1.default.handler({ code: testCode }, {
24
- data: {},
25
- env: {
26
- FLOWS_EXEC_ALLOWED_MODULES: '',
27
- },
28
- })).rejects.toEqual(new Error("Couldn't compile code: Unexpected end of input"));
29
- });
30
- test('Rejects when returned function does something illegal', async () => {
31
- const testCode = `
32
- module.exports = function() {
33
- return a + b;
34
- };
35
- `;
36
- await expect(index_1.default.handler({ code: testCode }, {
37
- data: {},
38
- env: {
39
- FLOWS_EXEC_ALLOWED_MODULES: '',
40
- },
41
- })).rejects.toEqual(new ReferenceError('a is not defined'));
42
- });
43
- test("Rejects when code doesn't return valid function", async () => {
44
- const testCode = `
45
- module.exports = false;
46
- `;
47
- await expect(index_1.default.handler({ code: testCode }, {
48
- data: {},
49
- env: {
50
- FLOWS_EXEC_ALLOWED_MODULES: '',
51
- },
52
- })).rejects.toEqual(new TypeError('fn is not a function'));
53
- });
54
- test('Rejects returned function throws errors', async () => {
55
- const testCode = `
56
- module.exports = function () {
57
- throw new Error('test');
58
- };
59
- `;
60
- await expect(index_1.default.handler({ code: testCode }, {
61
- data: {},
62
- env: {
63
- FLOWS_EXEC_ALLOWED_MODULES: '',
64
- },
65
- })).rejects.toEqual(new Error('test'));
66
- });
67
- test('Executes function when valid', () => {
68
- const testCode = `
69
- module.exports = function (data) {
70
- return { result: data.input + ' test' };
71
- };
72
- `;
73
- expect(index_1.default.handler({ code: testCode }, {
74
- data: {
75
- input: 'start',
76
- },
77
- env: {
78
- FLOWS_EXEC_ALLOWED_MODULES: '',
79
- },
80
- })).resolves.toEqual({ result: 'start test' });
81
- });
82
- test('Allows modules that are whitelisted', () => {
83
- const testCode = `
84
- const bytes = require('bytes');
85
-
86
- module.exports = function (data) {
87
- return { result: bytes(1000) };
88
- };
89
- `;
90
- expect(index_1.default.handler({ code: testCode }, {
91
- env: {
92
- FLOWS_EXEC_ALLOWED_MODULES: 'bytes',
93
- },
94
- })).resolves.toEqual({ result: '1000B' });
95
- });
@@ -1,89 +0,0 @@
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 exifr_1 = __importDefault(require("exifr"));
7
- const knex_1 = __importDefault(require("knex"));
8
- const knex_mock_client_1 = require("knex-mock-client");
9
- const _1 = require(".");
10
- const exceptions_1 = require("../exceptions");
11
- jest.mock('exifr');
12
- jest.mock('../../src/database/index', () => {
13
- return { getDatabaseClient: jest.fn().mockReturnValue('postgres') };
14
- });
15
- jest.requireMock('../../src/database/index');
16
- describe('Integration Tests', () => {
17
- let db;
18
- let tracker;
19
- beforeAll(async () => {
20
- db = (0, knex_1.default)({ client: knex_mock_client_1.MockClient });
21
- tracker = (0, knex_mock_client_1.getTracker)();
22
- });
23
- afterEach(() => {
24
- tracker.reset();
25
- jest.clearAllMocks();
26
- });
27
- describe('Services / Files', () => {
28
- describe('createOne', () => {
29
- let service;
30
- let superCreateOne;
31
- beforeEach(() => {
32
- service = new _1.FilesService({
33
- knex: db,
34
- schema: { collections: {}, relations: [] },
35
- });
36
- superCreateOne = jest.spyOn(_1.ItemsService.prototype, 'createOne').mockImplementation(jest.fn());
37
- });
38
- it('throws InvalidPayloadException when "type" is not provided', async () => {
39
- try {
40
- await service.createOne({
41
- title: 'Test File',
42
- storage: 'local',
43
- filename_download: 'test_file',
44
- });
45
- }
46
- catch (err) {
47
- expect(err).toBeInstanceOf(exceptions_1.InvalidPayloadException);
48
- expect(err.message).toBe('"type" is required');
49
- }
50
- expect(superCreateOne).not.toHaveBeenCalled();
51
- });
52
- it('creates a file entry when "type" is provided', async () => {
53
- await service.createOne({
54
- title: 'Test File',
55
- storage: 'local',
56
- filename_download: 'test_file',
57
- type: 'application/octet-stream',
58
- });
59
- expect(superCreateOne).toHaveBeenCalled();
60
- });
61
- });
62
- describe('getMetadata', () => {
63
- let service;
64
- let exifrParseSpy;
65
- const sampleMetadata = {
66
- CustomTagA: 'value a',
67
- CustomTagB: 'value b',
68
- CustomTagC: 'value c',
69
- };
70
- beforeEach(() => {
71
- exifrParseSpy = jest.spyOn(exifr_1.default, 'parse');
72
- service = new _1.FilesService({
73
- knex: db,
74
- schema: { collections: {}, relations: [] },
75
- });
76
- });
77
- it('accepts allowlist metadata tags', async () => {
78
- exifrParseSpy.mockReturnValue(Promise.resolve({ ...sampleMetadata }));
79
- const bufferContent = 'file buffer content';
80
- const allowList = ['CustomTagB', 'CustomTagA'];
81
- const metadata = await service.getMetadata(bufferContent, allowList);
82
- expect(exifrParseSpy).toHaveBeenCalled();
83
- expect(metadata.metadata.CustomTagA).toStrictEqual(sampleMetadata.CustomTagA);
84
- expect(metadata.metadata.CustomTagB).toStrictEqual(sampleMetadata.CustomTagB);
85
- expect(metadata.metadata.CustomTagC).toBeUndefined();
86
- });
87
- });
88
- });
89
- });