directus 9.23.1 → 9.23.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (383) hide show
  1. package/dist/app.js +25 -21
  2. package/dist/auth/auth.d.ts +3 -3
  3. package/dist/auth/auth.js +2 -0
  4. package/dist/auth/drivers/ldap.d.ts +1 -1
  5. package/dist/auth/drivers/ldap.js +57 -46
  6. package/dist/auth/drivers/local.d.ts +1 -1
  7. package/dist/auth/drivers/local.js +20 -17
  8. package/dist/auth/drivers/oauth2.d.ts +1 -1
  9. package/dist/auth/drivers/oauth2.js +44 -35
  10. package/dist/auth/drivers/openid.d.ts +1 -1
  11. package/dist/auth/drivers/openid.js +50 -41
  12. package/dist/auth/drivers/saml.d.ts +1 -1
  13. package/dist/auth/drivers/saml.js +20 -17
  14. package/dist/auth.d.ts +1 -1
  15. package/dist/auth.js +8 -7
  16. package/dist/cache.d.ts +9 -1
  17. package/dist/cache.js +66 -18
  18. package/dist/cli/commands/bootstrap/index.js +7 -6
  19. package/dist/cli/commands/init/index.js +3 -3
  20. package/dist/cli/commands/schema/apply.js +14 -15
  21. package/dist/cli/commands/schema/snapshot.js +2 -2
  22. package/dist/cli/utils/create-db-connection.d.ts +1 -1
  23. package/dist/cli/utils/create-db-connection.js +3 -2
  24. package/dist/cli/utils/create-env/index.d.ts +2 -2
  25. package/dist/cli/utils/create-env/index.js +1 -1
  26. package/dist/cli/utils/drivers.d.ts +1 -1
  27. package/dist/constants.d.ts +3 -2
  28. package/dist/constants.js +7 -7
  29. package/dist/controllers/activity.js +10 -11
  30. package/dist/controllers/assets.js +31 -25
  31. package/dist/controllers/auth.js +40 -26
  32. package/dist/controllers/collections.js +10 -10
  33. package/dist/controllers/dashboards.js +14 -11
  34. package/dist/controllers/extensions.js +3 -3
  35. package/dist/controllers/fields.js +20 -20
  36. package/dist/controllers/files.js +26 -20
  37. package/dist/controllers/flows.js +16 -13
  38. package/dist/controllers/folders.js +14 -11
  39. package/dist/controllers/graphql.js +6 -8
  40. package/dist/controllers/items.js +22 -19
  41. package/dist/controllers/not-found.d.ts +1 -1
  42. package/dist/controllers/not-found.js +1 -2
  43. package/dist/controllers/notifications.js +14 -11
  44. package/dist/controllers/operations.js +14 -11
  45. package/dist/controllers/panels.js +14 -11
  46. package/dist/controllers/permissions.js +14 -11
  47. package/dist/controllers/presets.js +14 -11
  48. package/dist/controllers/relations.js +10 -10
  49. package/dist/controllers/revisions.js +3 -3
  50. package/dist/controllers/roles.js +14 -11
  51. package/dist/controllers/schema.js +5 -5
  52. package/dist/controllers/server.js +7 -7
  53. package/dist/controllers/settings.js +2 -2
  54. package/dist/controllers/shares.js +21 -18
  55. package/dist/controllers/users.js +32 -36
  56. package/dist/controllers/utils.js +10 -15
  57. package/dist/controllers/webhooks.js +14 -11
  58. package/dist/database/helpers/fn/dialects/mssql.d.ts +1 -1
  59. package/dist/database/helpers/fn/dialects/mssql.js +10 -11
  60. package/dist/database/helpers/fn/dialects/mysql.d.ts +1 -1
  61. package/dist/database/helpers/fn/dialects/mysql.js +2 -3
  62. package/dist/database/helpers/fn/dialects/oracle.d.ts +1 -1
  63. package/dist/database/helpers/fn/dialects/oracle.js +10 -11
  64. package/dist/database/helpers/fn/dialects/postgres.d.ts +1 -1
  65. package/dist/database/helpers/fn/dialects/postgres.js +10 -11
  66. package/dist/database/helpers/fn/dialects/sqlite.d.ts +1 -1
  67. package/dist/database/helpers/fn/dialects/sqlite.js +10 -11
  68. package/dist/database/helpers/fn/types.d.ts +5 -6
  69. package/dist/database/helpers/fn/types.js +4 -5
  70. package/dist/database/helpers/geometry/dialects/mssql.d.ts +3 -3
  71. package/dist/database/helpers/geometry/dialects/mysql.d.ts +1 -1
  72. package/dist/database/helpers/geometry/dialects/oracle.d.ts +3 -3
  73. package/dist/database/helpers/geometry/dialects/postgres.d.ts +3 -3
  74. package/dist/database/helpers/geometry/dialects/postgres.js +1 -2
  75. package/dist/database/helpers/geometry/dialects/redshift.d.ts +2 -2
  76. package/dist/database/helpers/geometry/dialects/sqlite.d.ts +1 -1
  77. package/dist/database/helpers/geometry/types.d.ts +2 -2
  78. package/dist/database/helpers/geometry/types.js +1 -2
  79. package/dist/database/helpers/index.d.ts +5 -5
  80. package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +1 -1
  81. package/dist/database/helpers/schema/dialects/mssql.d.ts +1 -1
  82. package/dist/database/helpers/schema/dialects/mysql.d.ts +1 -1
  83. package/dist/database/helpers/schema/dialects/mysql.js +1 -2
  84. package/dist/database/helpers/schema/dialects/oracle.d.ts +2 -2
  85. package/dist/database/helpers/schema/dialects/oracle.js +4 -6
  86. package/dist/database/helpers/schema/types.d.ts +4 -4
  87. package/dist/database/helpers/types.d.ts +1 -1
  88. package/dist/database/helpers/types.js +1 -0
  89. package/dist/database/index.d.ts +1 -1
  90. package/dist/database/index.js +13 -13
  91. package/dist/database/migrations/20201028A-remove-collection-foreign-keys.d.ts +1 -1
  92. package/dist/database/migrations/20201029A-remove-system-relations.d.ts +1 -1
  93. package/dist/database/migrations/20201029B-remove-system-collections.d.ts +1 -1
  94. package/dist/database/migrations/20201029C-remove-system-fields.d.ts +1 -1
  95. package/dist/database/migrations/20201105A-add-cascade-system-relations.d.ts +1 -1
  96. package/dist/database/migrations/20201105B-change-webhook-url-type.d.ts +1 -1
  97. package/dist/database/migrations/20210225A-add-relations-sort-field.d.ts +1 -1
  98. package/dist/database/migrations/20210225A-add-relations-sort-field.js +1 -2
  99. package/dist/database/migrations/20210304A-remove-locked-fields.d.ts +1 -1
  100. package/dist/database/migrations/20210312A-webhooks-collections-text.d.ts +1 -1
  101. package/dist/database/migrations/20210331A-add-refresh-interval.d.ts +1 -1
  102. package/dist/database/migrations/20210415A-make-filesize-nullable.d.ts +1 -1
  103. package/dist/database/migrations/20210416A-add-collections-accountability.d.ts +1 -1
  104. package/dist/database/migrations/20210422A-remove-files-interface.d.ts +1 -1
  105. package/dist/database/migrations/20210506A-rename-interfaces.d.ts +1 -1
  106. package/dist/database/migrations/20210510A-restructure-relations.d.ts +1 -1
  107. package/dist/database/migrations/20210518A-add-foreign-key-constraints.d.ts +1 -1
  108. package/dist/database/migrations/20210518A-add-foreign-key-constraints.js +1 -1
  109. package/dist/database/migrations/20210519A-add-system-fk-triggers.d.ts +1 -1
  110. package/dist/database/migrations/20210519A-add-system-fk-triggers.js +2 -2
  111. package/dist/database/migrations/20210521A-add-collections-icon-color.d.ts +1 -1
  112. package/dist/database/migrations/20210525A-add-insights.d.ts +1 -1
  113. package/dist/database/migrations/20210608A-add-deep-clone-config.d.ts +1 -1
  114. package/dist/database/migrations/20210626A-change-filesize-bigint.d.ts +1 -1
  115. package/dist/database/migrations/20210716A-add-conditions-to-fields.d.ts +1 -1
  116. package/dist/database/migrations/20210721A-add-default-folder.d.ts +1 -1
  117. package/dist/database/migrations/20210802A-replace-groups.d.ts +1 -1
  118. package/dist/database/migrations/20210803A-add-required-to-fields.d.ts +1 -1
  119. package/dist/database/migrations/20210805A-update-groups.d.ts +1 -1
  120. package/dist/database/migrations/20210805B-change-image-metadata-structure.d.ts +1 -1
  121. package/dist/database/migrations/20210805B-change-image-metadata-structure.js +15 -15
  122. package/dist/database/migrations/20210811A-add-geometry-config.d.ts +1 -1
  123. package/dist/database/migrations/20210831A-remove-limit-column.d.ts +1 -1
  124. package/dist/database/migrations/20210903A-add-auth-provider.d.ts +1 -1
  125. package/dist/database/migrations/20210907A-webhooks-collections-not-null.d.ts +1 -1
  126. package/dist/database/migrations/20210910A-move-module-setup.d.ts +1 -1
  127. package/dist/database/migrations/20210920A-webhooks-url-not-null.d.ts +1 -1
  128. package/dist/database/migrations/20210924A-add-collection-organization.d.ts +1 -1
  129. package/dist/database/migrations/20210927A-replace-fields-group.d.ts +1 -1
  130. package/dist/database/migrations/20210927B-replace-m2m-interface.d.ts +1 -1
  131. package/dist/database/migrations/20210929A-rename-login-action.d.ts +1 -1
  132. package/dist/database/migrations/20211007A-update-presets.d.ts +1 -1
  133. package/dist/database/migrations/20211007A-update-presets.js +7 -9
  134. package/dist/database/migrations/20211009A-add-auth-data.d.ts +1 -1
  135. package/dist/database/migrations/20211016A-add-webhook-headers.d.ts +1 -1
  136. package/dist/database/migrations/20211103A-set-unique-to-user-token.d.ts +1 -1
  137. package/dist/database/migrations/20211103B-update-special-geometry.d.ts +1 -1
  138. package/dist/database/migrations/20211104A-remove-collections-listing.d.ts +1 -1
  139. package/dist/database/migrations/20211118A-add-notifications.d.ts +1 -1
  140. package/dist/database/migrations/20211211A-add-shares.d.ts +1 -1
  141. package/dist/database/migrations/20211230A-add-project-descriptor.d.ts +1 -1
  142. package/dist/database/migrations/20220303A-remove-default-project-color.d.ts +1 -1
  143. package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.d.ts +1 -1
  144. package/dist/database/migrations/20220314A-add-translation-strings.d.ts +1 -1
  145. package/dist/database/migrations/20220322A-rename-field-typecast-flags.d.ts +1 -1
  146. package/dist/database/migrations/20220323A-add-field-validation.d.ts +1 -1
  147. package/dist/database/migrations/20220325A-fix-typecast-flags.d.ts +1 -1
  148. package/dist/database/migrations/20220325B-add-default-language.d.ts +1 -1
  149. package/dist/database/migrations/20220402A-remove-default-value-panel-icon.d.ts +1 -1
  150. package/dist/database/migrations/20220429A-add-flows.d.ts +1 -1
  151. package/dist/database/migrations/20220429B-add-color-to-insights-icon.d.ts +1 -1
  152. package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.d.ts +1 -1
  153. package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.d.ts +1 -1
  154. package/dist/database/migrations/20220614A-rename-hook-trigger-to-event.d.ts +1 -1
  155. package/dist/database/migrations/20220801A-update-notifications-timestamp-column.d.ts +1 -1
  156. package/dist/database/migrations/20220802A-add-custom-aspect-ratios.d.ts +1 -1
  157. package/dist/database/migrations/20220826A-add-origin-to-accountability.d.ts +1 -1
  158. package/dist/database/migrations/run.d.ts +1 -1
  159. package/dist/database/migrations/run.js +1 -1
  160. package/dist/database/run-ast.d.ts +3 -3
  161. package/dist/database/run-ast.js +21 -30
  162. package/dist/database/seeds/run.d.ts +1 -1
  163. package/dist/database/seeds/run.js +1 -2
  164. package/dist/database/system-data/app-access-permissions/index.d.ts +1 -1
  165. package/dist/database/system-data/collections/index.d.ts +1 -1
  166. package/dist/database/system-data/collections/index.js +2 -2
  167. package/dist/database/system-data/fields/collections.yaml +2 -0
  168. package/dist/database/system-data/fields/index.d.ts +1 -1
  169. package/dist/database/system-data/fields/index.js +3 -4
  170. package/dist/database/system-data/fields/settings.yaml +4 -0
  171. package/dist/database/system-data/relations/index.d.ts +1 -1
  172. package/dist/emitter.d.ts +1 -1
  173. package/dist/emitter.js +3 -0
  174. package/dist/env.js +11 -3
  175. package/dist/exceptions/database/dialects/mssql.d.ts +1 -1
  176. package/dist/exceptions/database/dialects/mssql.js +5 -6
  177. package/dist/exceptions/database/dialects/mysql.d.ts +1 -1
  178. package/dist/exceptions/database/dialects/mysql.js +19 -25
  179. package/dist/exceptions/database/dialects/oracle.d.ts +1 -1
  180. package/dist/exceptions/database/dialects/postgres.d.ts +1 -1
  181. package/dist/exceptions/database/dialects/sqlite.d.ts +1 -1
  182. package/dist/exceptions/database/translate.d.ts +1 -1
  183. package/dist/exceptions/database/value-out-of-range.js +1 -1
  184. package/dist/exceptions/range-not-satisfiable.js +2 -3
  185. package/dist/extensions.d.ts +1 -1
  186. package/dist/extensions.js +43 -33
  187. package/dist/flows.js +65 -46
  188. package/dist/logger.d.ts +2 -1
  189. package/dist/logger.js +35 -19
  190. package/dist/logger.test.d.ts +1 -0
  191. package/dist/mailer.js +16 -16
  192. package/dist/messenger.js +9 -7
  193. package/dist/middleware/authenticate.d.ts +1 -1
  194. package/dist/middleware/authenticate.js +13 -6
  195. package/dist/middleware/cache.d.ts +1 -1
  196. package/dist/middleware/cache.js +16 -16
  197. package/dist/middleware/check-ip.d.ts +1 -1
  198. package/dist/middleware/check-ip.js +1 -1
  199. package/dist/middleware/collection-exists.d.ts +1 -1
  200. package/dist/middleware/collection-exists.js +5 -5
  201. package/dist/middleware/cors.d.ts +1 -1
  202. package/dist/middleware/cors.js +7 -7
  203. package/dist/middleware/error-handler.d.ts +1 -1
  204. package/dist/middleware/error-handler.js +11 -12
  205. package/dist/middleware/extract-token.d.ts +1 -1
  206. package/dist/middleware/extract-token.js +2 -2
  207. package/dist/middleware/get-permissions.d.ts +1 -1
  208. package/dist/middleware/graphql.d.ts +1 -1
  209. package/dist/middleware/graphql.js +15 -9
  210. package/dist/middleware/rate-limiter-global.d.ts +5 -0
  211. package/dist/middleware/rate-limiter-global.js +48 -0
  212. package/dist/middleware/{rate-limiter.d.ts → rate-limiter-ip.d.ts} +2 -2
  213. package/dist/middleware/{rate-limiter.js → rate-limiter-ip.js} +5 -5
  214. package/dist/middleware/respond.d.ts +1 -1
  215. package/dist/middleware/respond.js +18 -19
  216. package/dist/middleware/sanitize-query.d.ts +1 -1
  217. package/dist/middleware/sanitize-query.js +1 -1
  218. package/dist/middleware/schema.d.ts +1 -1
  219. package/dist/middleware/use-collection.d.ts +1 -1
  220. package/dist/operations/condition/index.d.ts +1 -1
  221. package/dist/operations/exec/index.js +15 -4
  222. package/dist/operations/item-create/index.js +1 -2
  223. package/dist/operations/item-delete/index.d.ts +1 -1
  224. package/dist/operations/item-read/index.d.ts +1 -1
  225. package/dist/operations/item-update/index.d.ts +1 -1
  226. package/dist/operations/item-update/index.js +1 -2
  227. package/dist/operations/notification/index.js +1 -2
  228. package/dist/operations/request/index.js +19 -19
  229. package/dist/operations/trigger/index.js +2 -3
  230. package/dist/rate-limiter.d.ts +1 -1
  231. package/dist/rate-limiter.js +9 -9
  232. package/dist/request/validate-ip.js +2 -2
  233. package/dist/server.js +12 -13
  234. package/dist/services/activity.d.ts +1 -1
  235. package/dist/services/activity.js +17 -16
  236. package/dist/services/assets.d.ts +3 -3
  237. package/dist/services/assets.js +35 -37
  238. package/dist/services/authentication.d.ts +2 -2
  239. package/dist/services/authentication.js +22 -19
  240. package/dist/services/authorization.d.ts +3 -3
  241. package/dist/services/authorization.js +27 -31
  242. package/dist/services/collections.d.ts +5 -5
  243. package/dist/services/collections.js +54 -50
  244. package/dist/services/dashboards.d.ts +1 -1
  245. package/dist/services/fields.d.ts +5 -5
  246. package/dist/services/fields.js +50 -50
  247. package/dist/services/files.d.ts +1 -2
  248. package/dist/services/files.js +33 -27
  249. package/dist/services/flows.d.ts +2 -2
  250. package/dist/services/folders.d.ts +1 -1
  251. package/dist/services/graphql/index.d.ts +4 -4
  252. package/dist/services/graphql/index.js +259 -252
  253. package/dist/services/graphql/utils/add-path-to-validation-error.js +1 -2
  254. package/dist/services/graphql/utils/process-error.d.ts +2 -2
  255. package/dist/services/graphql/utils/process-error.js +11 -4
  256. package/dist/services/import-export.d.ts +3 -3
  257. package/dist/services/import-export.js +30 -27
  258. package/dist/services/items.d.ts +3 -3
  259. package/dist/services/items.js +42 -36
  260. package/dist/services/mail/index.d.ts +4 -4
  261. package/dist/services/mail/index.js +14 -10
  262. package/dist/services/meta.d.ts +3 -3
  263. package/dist/services/meta.js +11 -9
  264. package/dist/services/notifications.d.ts +3 -3
  265. package/dist/services/notifications.js +10 -9
  266. package/dist/services/operations.d.ts +2 -2
  267. package/dist/services/panels.d.ts +1 -1
  268. package/dist/services/payload.d.ts +3 -3
  269. package/dist/services/payload.js +124 -122
  270. package/dist/services/permissions.d.ts +3 -3
  271. package/dist/services/permissions.js +11 -11
  272. package/dist/services/presets.d.ts +1 -1
  273. package/dist/services/relations.d.ts +6 -6
  274. package/dist/services/relations.js +45 -43
  275. package/dist/services/revisions.d.ts +1 -1
  276. package/dist/services/revisions.js +3 -3
  277. package/dist/services/roles.d.ts +2 -2
  278. package/dist/services/roles.js +7 -7
  279. package/dist/services/schema.d.ts +3 -3
  280. package/dist/services/schema.js +9 -11
  281. package/dist/services/server.d.ts +3 -3
  282. package/dist/services/server.js +88 -32
  283. package/dist/services/settings.d.ts +1 -1
  284. package/dist/services/shares.d.ts +1 -1
  285. package/dist/services/shares.js +14 -15
  286. package/dist/services/specifications.d.ts +4 -4
  287. package/dist/services/specifications.js +137 -119
  288. package/dist/services/tfa.d.ts +2 -2
  289. package/dist/services/tfa.js +7 -5
  290. package/dist/services/users.d.ts +2 -6
  291. package/dist/services/users.js +37 -40
  292. package/dist/services/utils.d.ts +3 -3
  293. package/dist/services/utils.js +10 -8
  294. package/dist/services/webhooks.d.ts +2 -2
  295. package/dist/services/webhooks.js +2 -1
  296. package/dist/storage/register-locations.js +1 -1
  297. package/dist/types/assets.d.ts +1 -1
  298. package/dist/types/ast.d.ts +1 -1
  299. package/dist/types/auth.d.ts +2 -2
  300. package/dist/types/collection.d.ts +2 -2
  301. package/dist/types/events.d.ts +2 -2
  302. package/dist/types/graphql.d.ts +2 -2
  303. package/dist/types/items.d.ts +3 -3
  304. package/dist/types/services.d.ts +5 -5
  305. package/dist/types/snapshot.d.ts +4 -4
  306. package/dist/utils/apply-diff.d.ts +3 -3
  307. package/dist/utils/apply-diff.js +25 -28
  308. package/dist/utils/apply-query.d.ts +3 -3
  309. package/dist/utils/apply-query.js +10 -12
  310. package/dist/utils/apply-snapshot.d.ts +3 -3
  311. package/dist/utils/apply-snapshot.js +5 -6
  312. package/dist/utils/construct-flow-tree.d.ts +1 -1
  313. package/dist/utils/construct-flow-tree.js +2 -2
  314. package/dist/utils/dynamic-import.js +1 -1
  315. package/dist/utils/filter-items.d.ts +1 -1
  316. package/dist/utils/generate-hash.js +1 -1
  317. package/dist/utils/get-accountability-for-role.d.ts +2 -2
  318. package/dist/utils/get-accountability-for-role.js +1 -1
  319. package/dist/utils/get-ast-from-query.d.ts +3 -3
  320. package/dist/utils/get-ast-from-query.js +22 -28
  321. package/dist/utils/get-auth-providers.js +1 -1
  322. package/dist/utils/get-cache-headers.d.ts +1 -1
  323. package/dist/utils/get-cache-headers.js +6 -7
  324. package/dist/utils/get-cache-key.d.ts +1 -1
  325. package/dist/utils/get-cache-key.js +2 -3
  326. package/dist/utils/get-collection-from-alias.d.ts +1 -1
  327. package/dist/utils/get-collection-from-alias.js +1 -0
  328. package/dist/utils/get-column-path.d.ts +2 -2
  329. package/dist/utils/get-column-path.js +3 -4
  330. package/dist/utils/get-column.d.ts +4 -4
  331. package/dist/utils/get-column.js +4 -5
  332. package/dist/utils/get-default-value.d.ts +2 -2
  333. package/dist/utils/get-default-value.js +2 -3
  334. package/dist/utils/get-graphql-query-and-variables.d.ts +1 -1
  335. package/dist/utils/get-graphql-query-and-variables.js +1 -2
  336. package/dist/utils/get-graphql-type.d.ts +2 -2
  337. package/dist/utils/get-graphql-type.js +1 -1
  338. package/dist/utils/get-ip-from-req.d.ts +1 -1
  339. package/dist/utils/get-ip-from-req.js +2 -2
  340. package/dist/utils/get-local-type.d.ts +1 -1
  341. package/dist/utils/get-local-type.js +3 -3
  342. package/dist/utils/get-milliseconds.js +1 -2
  343. package/dist/utils/get-permissions.d.ts +1 -1
  344. package/dist/utils/get-permissions.js +12 -12
  345. package/dist/utils/get-relation-info.d.ts +1 -1
  346. package/dist/utils/get-relation-info.js +3 -5
  347. package/dist/utils/get-relation-type.d.ts +1 -1
  348. package/dist/utils/get-relation-type.js +3 -4
  349. package/dist/utils/get-schema.d.ts +2 -2
  350. package/dist/utils/get-schema.js +20 -22
  351. package/dist/utils/get-snapshot-diff.js +2 -3
  352. package/dist/utils/get-snapshot.d.ts +3 -3
  353. package/dist/utils/get-snapshot.js +6 -8
  354. package/dist/utils/is-directus-jwt.js +1 -1
  355. package/dist/utils/is-url-allowed.js +5 -2
  356. package/dist/utils/job-queue.js +2 -0
  357. package/dist/utils/jwt.d.ts +1 -1
  358. package/dist/utils/merge-permissions-for-share.d.ts +1 -1
  359. package/dist/utils/merge-permissions-for-share.js +3 -4
  360. package/dist/utils/merge-permissions.d.ts +3 -3
  361. package/dist/utils/reduce-schema.d.ts +1 -1
  362. package/dist/utils/reduce-schema.js +12 -12
  363. package/dist/utils/sanitize-query.d.ts +1 -1
  364. package/dist/utils/sanitize-query.js +27 -27
  365. package/dist/utils/sanitize-schema.d.ts +2 -2
  366. package/dist/utils/should-skip-cache.d.ts +7 -0
  367. package/dist/utils/should-skip-cache.js +21 -0
  368. package/dist/utils/should-skip-cache.test.d.ts +1 -0
  369. package/dist/utils/track.js +16 -16
  370. package/dist/utils/transformations.d.ts +1 -1
  371. package/dist/utils/transformations.js +2 -4
  372. package/dist/utils/url.js +7 -2
  373. package/dist/utils/user-name.d.ts +1 -1
  374. package/dist/utils/validate-diff.js +7 -8
  375. package/dist/utils/validate-keys.d.ts +2 -2
  376. package/dist/utils/validate-keys.js +1 -1
  377. package/dist/utils/validate-query.d.ts +1 -1
  378. package/dist/utils/validate-query.js +3 -3
  379. package/dist/utils/validate-storage.js +8 -8
  380. package/dist/webhooks.js +3 -3
  381. package/package.json +36 -37
  382. package/dist/utils/with-timeout.d.ts +0 -1
  383. package/dist/utils/with-timeout.js +0 -16
@@ -10,17 +10,17 @@ const collections_1 = require("../database/system-data/collections");
10
10
  const exceptions_1 = require("../exceptions");
11
11
  const async_handler_1 = __importDefault(require("../utils/async-handler"));
12
12
  const collectionExists = (0, async_handler_1.default)(async (req, res, next) => {
13
- if (!req.params.collection)
13
+ if (!req.params['collection'])
14
14
  return next();
15
- if (req.params.collection in req.schema.collections === false) {
15
+ if (req.params['collection'] in req.schema.collections === false) {
16
16
  throw new exceptions_1.ForbiddenException();
17
17
  }
18
- req.collection = req.params.collection;
18
+ req.collection = req.params['collection'];
19
19
  if (req.collection.startsWith('directus_')) {
20
20
  const systemRow = collections_1.systemCollectionRows.find((collection) => {
21
- return (collection === null || collection === void 0 ? void 0 : collection.collection) === req.collection;
21
+ return collection?.collection === req.collection;
22
22
  });
23
- req.singleton = !!(systemRow === null || systemRow === void 0 ? void 0 : systemRow.singleton);
23
+ req.singleton = !!systemRow?.singleton;
24
24
  }
25
25
  else {
26
26
  req.singleton = req.schema.collections[req.collection].singleton;
@@ -1,3 +1,3 @@
1
- import { RequestHandler } from 'express';
1
+ import type { RequestHandler } from 'express';
2
2
  declare let corsMiddleware: RequestHandler;
3
3
  export default corsMiddleware;
@@ -6,14 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const cors_1 = __importDefault(require("cors"));
7
7
  const env_1 = __importDefault(require("../env"));
8
8
  let corsMiddleware = (req, res, next) => next();
9
- if (env_1.default.CORS_ENABLED === true) {
9
+ if (env_1.default['CORS_ENABLED'] === true) {
10
10
  corsMiddleware = (0, cors_1.default)({
11
- origin: env_1.default.CORS_ORIGIN || true,
12
- methods: env_1.default.CORS_METHODS || 'GET,POST,PATCH,DELETE',
13
- allowedHeaders: env_1.default.CORS_ALLOWED_HEADERS,
14
- exposedHeaders: env_1.default.CORS_EXPOSED_HEADERS,
15
- credentials: env_1.default.CORS_CREDENTIALS || undefined,
16
- maxAge: env_1.default.CORS_MAX_AGE || undefined,
11
+ origin: env_1.default['CORS_ORIGIN'] || true,
12
+ methods: env_1.default['CORS_METHODS'] || 'GET,POST,PATCH,DELETE',
13
+ allowedHeaders: env_1.default['CORS_ALLOWED_HEADERS'],
14
+ exposedHeaders: env_1.default['CORS_EXPOSED_HEADERS'],
15
+ credentials: env_1.default['CORS_CREDENTIALS'] || undefined,
16
+ maxAge: env_1.default['CORS_MAX_AGE'] || undefined,
17
17
  });
18
18
  }
19
19
  exports.default = corsMiddleware;
@@ -1,3 +1,3 @@
1
- import { ErrorRequestHandler } from 'express';
1
+ import type { ErrorRequestHandler } from 'express';
2
2
  declare const errorHandler: ErrorRequestHandler;
3
3
  export default errorHandler;
@@ -3,22 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const exceptions_1 = require("@directus/shared/exceptions");
7
+ const utils_1 = require("@directus/shared/utils");
8
+ const database_1 = __importDefault(require("../database"));
6
9
  const emitter_1 = __importDefault(require("../emitter"));
7
10
  const env_1 = __importDefault(require("../env"));
8
- const exceptions_1 = require("../exceptions");
9
- const exceptions_2 = require("@directus/shared/exceptions");
11
+ const exceptions_2 = require("../exceptions");
10
12
  const logger_1 = __importDefault(require("../logger"));
11
- const utils_1 = require("@directus/shared/utils");
12
- const database_1 = __importDefault(require("../database"));
13
13
  // Note: keep all 4 parameters here. That's how Express recognizes it's the error handler, even if
14
14
  // we don't use next
15
15
  const errorHandler = (err, req, res, _next) => {
16
- var _a, _b;
17
16
  let payload = {
18
17
  errors: [],
19
18
  };
20
19
  const errors = (0, utils_1.toArray)(err);
21
- if (errors.some((err) => err instanceof exceptions_2.BaseException === false)) {
20
+ if (errors.some((err) => err instanceof exceptions_1.BaseException === false)) {
22
21
  res.status(500);
23
22
  }
24
23
  else {
@@ -33,13 +32,13 @@ const errorHandler = (err, req, res, _next) => {
33
32
  res.status(status);
34
33
  }
35
34
  for (const err of errors) {
36
- if (env_1.default.NODE_ENV === 'development') {
35
+ if (env_1.default['NODE_ENV'] === 'development') {
37
36
  err.extensions = {
38
37
  ...(err.extensions || {}),
39
38
  stack: err.stack,
40
39
  };
41
40
  }
42
- if (err instanceof exceptions_2.BaseException) {
41
+ if (err instanceof exceptions_1.BaseException) {
43
42
  logger_1.default.debug(err);
44
43
  res.status(err.status);
45
44
  payload.errors.push({
@@ -49,14 +48,14 @@ const errorHandler = (err, req, res, _next) => {
49
48
  ...err.extensions,
50
49
  },
51
50
  });
52
- if (err instanceof exceptions_1.MethodNotAllowedException) {
53
- res.header('Allow', err.extensions.allow.join(', '));
51
+ if (err instanceof exceptions_2.MethodNotAllowedException) {
52
+ res.header('Allow', err.extensions['allow'].join(', '));
54
53
  }
55
54
  }
56
55
  else {
57
56
  logger_1.default.error(err);
58
57
  res.status(500);
59
- if (((_a = req.accountability) === null || _a === void 0 ? void 0 : _a.admin) === true) {
58
+ if (req.accountability?.admin === true) {
60
59
  payload = {
61
60
  errors: [
62
61
  {
@@ -87,7 +86,7 @@ const errorHandler = (err, req, res, _next) => {
87
86
  .emitFilter('request.error', payload.errors, {}, {
88
87
  database: (0, database_1.default)(),
89
88
  schema: req.schema,
90
- accountability: (_b = req.accountability) !== null && _b !== void 0 ? _b : null,
89
+ accountability: req.accountability ?? null,
91
90
  })
92
91
  .then(() => {
93
92
  return res.json(payload);
@@ -6,6 +6,6 @@
6
6
  *
7
7
  * and store in req.token
8
8
  */
9
- import { RequestHandler } from 'express';
9
+ import type { RequestHandler } from 'express';
10
10
  declare const extractToken: RequestHandler;
11
11
  export default extractToken;
@@ -10,8 +10,8 @@
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  const extractToken = (req, res, next) => {
12
12
  let token = null;
13
- if (req.query && req.query.access_token) {
14
- token = req.query.access_token;
13
+ if (req.query && req.query['access_token']) {
14
+ token = req.query['access_token'];
15
15
  }
16
16
  if (req.headers && req.headers.authorization) {
17
17
  const parts = req.headers.authorization.split(' ');
@@ -1,3 +1,3 @@
1
- import { RequestHandler } from 'express';
1
+ import type { RequestHandler } from 'express';
2
2
  declare const getPermissions: RequestHandler;
3
3
  export default getPermissions;
@@ -1,2 +1,2 @@
1
- import { RequestHandler } from 'express';
1
+ import type { RequestHandler } from 'express';
2
2
  export declare const parseGraphQL: RequestHandler;
@@ -17,10 +17,10 @@ exports.parseGraphQL = (0, async_handler_1.default)(async (req, res, next) => {
17
17
  let operationName = null;
18
18
  let document;
19
19
  if (req.method === 'GET') {
20
- query = req.query.query || null;
21
- if (req.query.variables) {
20
+ query = req.query['query'] || null;
21
+ if (req.query['variables']) {
22
22
  try {
23
- variables = (0, utils_1.parseJSON)(req.query.variables);
23
+ variables = (0, utils_1.parseJSON)(req.query['variables']);
24
24
  }
25
25
  catch {
26
26
  throw new exceptions_1.InvalidQueryException(`Variables are invalid JSON.`);
@@ -29,7 +29,7 @@ exports.parseGraphQL = (0, async_handler_1.default)(async (req, res, next) => {
29
29
  else {
30
30
  variables = {};
31
31
  }
32
- operationName = req.query.operationName || null;
32
+ operationName = req.query['operationName'] || null;
33
33
  }
34
34
  else {
35
35
  query = req.body.query || null;
@@ -49,15 +49,21 @@ exports.parseGraphQL = (0, async_handler_1.default)(async (req, res, next) => {
49
49
  }
50
50
  const operationAST = (0, graphql_1.getOperationAST)(document, operationName);
51
51
  // You can only do `query` through GET
52
- if (req.method === 'GET' && (operationAST === null || operationAST === void 0 ? void 0 : operationAST.operation) !== 'query') {
53
- throw new exceptions_1.MethodNotAllowedException(`Can only perform a ${operationAST === null || operationAST === void 0 ? void 0 : operationAST.operation} from a POST request.`, {
52
+ if (req.method === 'GET' && operationAST?.operation !== 'query') {
53
+ throw new exceptions_1.MethodNotAllowedException(`Can only perform a ${operationAST?.operation} from a POST request.`, {
54
54
  allow: ['POST'],
55
55
  });
56
56
  }
57
57
  // Prevent caching responses when mutations are made
58
- if ((operationAST === null || operationAST === void 0 ? void 0 : operationAST.operation) === 'mutation') {
59
- res.locals.cache = false;
58
+ if (operationAST?.operation === 'mutation') {
59
+ res.locals['cache'] = false;
60
60
  }
61
- res.locals.graphqlParams = { document, query, variables, operationName, contextValue: { req, res } };
61
+ res.locals['graphqlParams'] = {
62
+ document,
63
+ query,
64
+ variables,
65
+ operationName,
66
+ contextValue: { req, res },
67
+ };
62
68
  return next();
63
69
  });
@@ -0,0 +1,5 @@
1
+ import type { RequestHandler } from 'express';
2
+ import type { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
3
+ declare let checkRateLimit: RequestHandler;
4
+ export declare let rateLimiterGlobal: RateLimiterRedis | RateLimiterMemcache | RateLimiterMemory;
5
+ export default checkRateLimit;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.rateLimiterGlobal = void 0;
7
+ const ms_1 = __importDefault(require("ms"));
8
+ const env_1 = __importDefault(require("../env"));
9
+ const index_1 = require("../exceptions/index");
10
+ const logger_1 = __importDefault(require("../logger"));
11
+ const rate_limiter_1 = require("../rate-limiter");
12
+ const async_handler_1 = __importDefault(require("../utils/async-handler"));
13
+ const validate_env_1 = require("../utils/validate-env");
14
+ const RATE_LIMITER_GLOBAL_KEY = 'global-rate-limit';
15
+ let checkRateLimit = (_req, _res, next) => next();
16
+ if (env_1.default['RATE_LIMITER_GLOBAL_ENABLED'] === true) {
17
+ (0, validate_env_1.validateEnv)(['RATE_LIMITER_GLOBAL_STORE', 'RATE_LIMITER_GLOBAL_DURATION', 'RATE_LIMITER_GLOBAL_POINTS']);
18
+ validateConfiguration();
19
+ exports.rateLimiterGlobal = (0, rate_limiter_1.createRateLimiter)('RATE_LIMITER_GLOBAL');
20
+ checkRateLimit = (0, async_handler_1.default)(async (_req, res, next) => {
21
+ try {
22
+ await exports.rateLimiterGlobal.consume(RATE_LIMITER_GLOBAL_KEY, 1);
23
+ }
24
+ catch (rateLimiterRes) {
25
+ if (rateLimiterRes instanceof Error)
26
+ throw rateLimiterRes;
27
+ res.set('Retry-After', String(Math.round(rateLimiterRes.msBeforeNext / 1000)));
28
+ throw new index_1.HitRateLimitException(`Too many requests, retry after ${(0, ms_1.default)(rateLimiterRes.msBeforeNext)}.`, {
29
+ limit: +env_1.default['RATE_LIMITER_GLOBAL_POINTS'],
30
+ reset: new Date(Date.now() + rateLimiterRes.msBeforeNext),
31
+ });
32
+ }
33
+ next();
34
+ });
35
+ }
36
+ exports.default = checkRateLimit;
37
+ function validateConfiguration() {
38
+ if (env_1.default['RATE_LIMITER_ENABLED'] !== true) {
39
+ logger_1.default.error(`The IP based rate limiter needs to be enabled when using the global rate limiter.`);
40
+ process.exit(1);
41
+ }
42
+ const globalPointsPerSec = Number(env_1.default['RATE_LIMITER_GLOBAL_POINTS']) / Math.max(Number(env_1.default['RATE_LIMITER_GLOBAL_DURATION']), 1);
43
+ const regularPointsPerSec = Number(env_1.default['RATE_LIMITER_POINTS']) / Math.max(Number(env_1.default['RATE_LIMITER_DURATION']), 1);
44
+ if (globalPointsPerSec <= regularPointsPerSec) {
45
+ logger_1.default.error(`The global rate limiter needs to allow more requests per second than the IP based rate limiter.`);
46
+ process.exit(1);
47
+ }
48
+ }
@@ -1,5 +1,5 @@
1
- import { RequestHandler } from 'express';
2
- import { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
1
+ import type { RequestHandler } from 'express';
2
+ import type { RateLimiterMemcache, RateLimiterMemory, RateLimiterRedis } from 'rate-limiter-flexible';
3
3
  declare let checkRateLimit: RequestHandler;
4
4
  export declare let rateLimiter: RateLimiterRedis | RateLimiterMemcache | RateLimiterMemory;
5
5
  export default checkRateLimit;
@@ -11,10 +11,10 @@ const rate_limiter_1 = require("../rate-limiter");
11
11
  const async_handler_1 = __importDefault(require("../utils/async-handler"));
12
12
  const get_ip_from_req_1 = require("../utils/get-ip-from-req");
13
13
  const validate_env_1 = require("../utils/validate-env");
14
- let checkRateLimit = (req, res, next) => next();
15
- if (env_1.default.RATE_LIMITER_ENABLED === true) {
14
+ let checkRateLimit = (_req, _res, next) => next();
15
+ if (env_1.default['RATE_LIMITER_ENABLED'] === true) {
16
16
  (0, validate_env_1.validateEnv)(['RATE_LIMITER_STORE', 'RATE_LIMITER_DURATION', 'RATE_LIMITER_POINTS']);
17
- exports.rateLimiter = (0, rate_limiter_1.createRateLimiter)();
17
+ exports.rateLimiter = (0, rate_limiter_1.createRateLimiter)('RATE_LIMITER');
18
18
  checkRateLimit = (0, async_handler_1.default)(async (req, res, next) => {
19
19
  try {
20
20
  await exports.rateLimiter.consume((0, get_ip_from_req_1.getIPFromReq)(req), 1);
@@ -22,9 +22,9 @@ if (env_1.default.RATE_LIMITER_ENABLED === true) {
22
22
  catch (rateLimiterRes) {
23
23
  if (rateLimiterRes instanceof Error)
24
24
  throw rateLimiterRes;
25
- res.set('Retry-After', String(rateLimiterRes.msBeforeNext / 1000));
25
+ res.set('Retry-After', String(Math.round(rateLimiterRes.msBeforeNext / 1000)));
26
26
  throw new exceptions_1.HitRateLimitException(`Too many requests, retry after ${(0, ms_1.default)(rateLimiterRes.msBeforeNext)}.`, {
27
- limit: +env_1.default.RATE_LIMITER_POINTS,
27
+ limit: +env_1.default['RATE_LIMITER_POINTS'],
28
28
  reset: new Date(Date.now() + rateLimiterRes.msBeforeNext),
29
29
  });
30
30
  }
@@ -1,2 +1,2 @@
1
- import { RequestHandler } from 'express';
1
+ import type { RequestHandler } from 'express';
2
2
  export declare const respond: RequestHandler;
@@ -16,29 +16,28 @@ const get_date_formatted_1 = require("../utils/get-date-formatted");
16
16
  const get_milliseconds_1 = require("../utils/get-milliseconds");
17
17
  const get_string_byte_size_1 = require("../utils/get-string-byte-size");
18
18
  exports.respond = (0, async_handler_1.default)(async (req, res) => {
19
- var _a, _b, _c, _d, _e;
20
19
  const { cache } = (0, cache_1.getCache)();
21
20
  let exceedsMaxSize = false;
22
- if (env_1.default.CACHE_VALUE_MAX_SIZE !== false) {
23
- const valueSize = res.locals.payload ? (0, get_string_byte_size_1.stringByteSize)(JSON.stringify(res.locals.payload)) : 0;
24
- const maxSize = (0, bytes_1.parse)(env_1.default.CACHE_VALUE_MAX_SIZE);
21
+ if (env_1.default['CACHE_VALUE_MAX_SIZE'] !== false) {
22
+ const valueSize = res.locals['payload'] ? (0, get_string_byte_size_1.stringByteSize)(JSON.stringify(res.locals['payload'])) : 0;
23
+ const maxSize = (0, bytes_1.parse)(env_1.default['CACHE_VALUE_MAX_SIZE']);
25
24
  exceedsMaxSize = valueSize > maxSize;
26
25
  }
27
- if ((req.method.toLowerCase() === 'get' || ((_a = req.originalUrl) === null || _a === void 0 ? void 0 : _a.startsWith('/graphql'))) &&
28
- env_1.default.CACHE_ENABLED === true &&
26
+ if ((req.method.toLowerCase() === 'get' || req.originalUrl?.startsWith('/graphql')) &&
27
+ env_1.default['CACHE_ENABLED'] === true &&
29
28
  cache &&
30
29
  !req.sanitizedQuery.export &&
31
- res.locals.cache !== false &&
30
+ res.locals['cache'] !== false &&
32
31
  exceedsMaxSize === false) {
33
32
  const key = (0, get_cache_key_1.getCacheKey)(req);
34
33
  try {
35
- await (0, cache_1.setCacheValue)(cache, key, res.locals.payload, (0, get_milliseconds_1.getMilliseconds)(env_1.default.CACHE_TTL));
36
- await (0, cache_1.setCacheValue)(cache, `${key}__expires_at`, { exp: Date.now() + (0, get_milliseconds_1.getMilliseconds)(env_1.default.CACHE_TTL, 0) });
34
+ await (0, cache_1.setCacheValue)(cache, key, res.locals['payload'], (0, get_milliseconds_1.getMilliseconds)(env_1.default['CACHE_TTL']));
35
+ await (0, cache_1.setCacheValue)(cache, `${key}__expires_at`, { exp: Date.now() + (0, get_milliseconds_1.getMilliseconds)(env_1.default['CACHE_TTL'], 0) });
37
36
  }
38
37
  catch (err) {
39
38
  logger_1.default.warn(err, `[cache] Couldn't set key ${key}. ${err}`);
40
39
  }
41
- res.setHeader('Cache-Control', (0, get_cache_headers_1.getCacheControlHeader)(req, (0, get_milliseconds_1.getMilliseconds)(env_1.default.CACHE_TTL), true, true));
40
+ res.setHeader('Cache-Control', (0, get_cache_headers_1.getCacheControlHeader)(req, (0, get_milliseconds_1.getMilliseconds)(env_1.default['CACHE_TTL']), true, true));
42
41
  res.setHeader('Vary', 'Origin, Cache-Control');
43
42
  }
44
43
  else {
@@ -47,7 +46,7 @@ exports.respond = (0, async_handler_1.default)(async (req, res) => {
47
46
  res.setHeader('Vary', 'Origin, Cache-Control');
48
47
  }
49
48
  if (req.sanitizedQuery.export) {
50
- const exportService = new services_1.ExportService({ accountability: req.accountability, schema: req.schema });
49
+ const exportService = new services_1.ExportService({ accountability: req.accountability ?? null, schema: req.schema });
51
50
  let filename = '';
52
51
  if (req.collection) {
53
52
  filename += req.collection;
@@ -59,29 +58,29 @@ exports.respond = (0, async_handler_1.default)(async (req, res) => {
59
58
  if (req.sanitizedQuery.export === 'json') {
60
59
  res.attachment(`${filename}.json`);
61
60
  res.set('Content-Type', 'application/json');
62
- return res.status(200).send(exportService.transform((_b = res.locals.payload) === null || _b === void 0 ? void 0 : _b.data, 'json'));
61
+ return res.status(200).send(exportService.transform(res.locals['payload']?.data, 'json'));
63
62
  }
64
63
  if (req.sanitizedQuery.export === 'xml') {
65
64
  res.attachment(`${filename}.xml`);
66
65
  res.set('Content-Type', 'text/xml');
67
- return res.status(200).send(exportService.transform((_c = res.locals.payload) === null || _c === void 0 ? void 0 : _c.data, 'xml'));
66
+ return res.status(200).send(exportService.transform(res.locals['payload']?.data, 'xml'));
68
67
  }
69
68
  if (req.sanitizedQuery.export === 'csv') {
70
69
  res.attachment(`${filename}.csv`);
71
70
  res.set('Content-Type', 'text/csv');
72
- return res.status(200).send(exportService.transform((_d = res.locals.payload) === null || _d === void 0 ? void 0 : _d.data, 'csv'));
71
+ return res.status(200).send(exportService.transform(res.locals['payload']?.data, 'csv'));
73
72
  }
74
73
  if (req.sanitizedQuery.export === 'yaml') {
75
74
  res.attachment(`${filename}.yaml`);
76
75
  res.set('Content-Type', 'text/yaml');
77
- return res.status(200).send(exportService.transform((_e = res.locals.payload) === null || _e === void 0 ? void 0 : _e.data, 'yaml'));
76
+ return res.status(200).send(exportService.transform(res.locals['payload']?.data, 'yaml'));
78
77
  }
79
78
  }
80
- if (Buffer.isBuffer(res.locals.payload)) {
81
- return res.end(res.locals.payload);
79
+ if (Buffer.isBuffer(res.locals['payload'])) {
80
+ return res.end(res.locals['payload']);
82
81
  }
83
- else if (res.locals.payload) {
84
- return res.json(res.locals.payload);
82
+ else if (res.locals['payload']) {
83
+ return res.json(res.locals['payload']);
85
84
  }
86
85
  else {
87
86
  return res.status(204).end();
@@ -2,6 +2,6 @@
2
2
  * Sanitize query parameters.
3
3
  * This ensures that query params are formatted and ready to go for the services.
4
4
  */
5
- import { RequestHandler } from 'express';
5
+ import type { RequestHandler } from 'express';
6
6
  declare const sanitizeQueryMiddleware: RequestHandler;
7
7
  export default sanitizeQueryMiddleware;
@@ -11,7 +11,7 @@ const sanitizeQueryMiddleware = (req, _res, next) => {
11
11
  if (!req.query)
12
12
  return;
13
13
  req.sanitizedQuery = (0, sanitize_query_1.sanitizeQuery)({
14
- fields: req.query.fields || '*',
14
+ fields: req.query['fields'] || '*',
15
15
  ...req.query,
16
16
  }, req.accountability || null);
17
17
  Object.freeze(req.sanitizedQuery);
@@ -1,3 +1,3 @@
1
- import { RequestHandler } from 'express';
1
+ import type { RequestHandler } from 'express';
2
2
  declare const schema: RequestHandler;
3
3
  export default schema;
@@ -2,6 +2,6 @@
2
2
  * Set req.collection for use in other middleware. Used as an alternative on validate-collection for
3
3
  * system collections
4
4
  */
5
- import { RequestHandler } from 'express';
5
+ import type { RequestHandler } from 'express';
6
6
  declare const useCollection: (collection: string) => RequestHandler;
7
7
  export default useCollection;
@@ -1,4 +1,4 @@
1
- import { Filter } from '@directus/shared/types';
1
+ import type { Filter } from '@directus/shared/types';
2
2
  type Options = {
3
3
  filter: Filter;
4
4
  };
@@ -2,21 +2,32 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_1 = require("@directus/shared/utils");
4
4
  const vm2_1 = require("vm2");
5
+ const node_module_1 = require("node:module");
5
6
  exports.default = (0, utils_1.defineOperationApi)({
6
7
  id: 'exec',
7
8
  handler: async ({ code }, { data, env }) => {
8
- var _a;
9
- const allowedModules = env.FLOWS_EXEC_ALLOWED_MODULES ? (0, utils_1.toArray)(env.FLOWS_EXEC_ALLOWED_MODULES) : [];
10
- const allowedEnv = (_a = data.$env) !== null && _a !== void 0 ? _a : {};
9
+ const allowedModules = env['FLOWS_EXEC_ALLOWED_MODULES'] ? (0, utils_1.toArray)(env['FLOWS_EXEC_ALLOWED_MODULES']) : [];
10
+ const allowedModulesBuiltIn = [];
11
+ const allowedModulesExternal = [];
12
+ const allowedEnv = data['$env'] ?? {};
11
13
  const opts = {
12
14
  eval: false,
13
15
  wasm: false,
14
16
  env: allowedEnv,
15
17
  };
18
+ for (const module of allowedModules) {
19
+ if ((0, node_module_1.isBuiltin)(module)) {
20
+ allowedModulesBuiltIn.push(module);
21
+ }
22
+ else {
23
+ allowedModulesExternal.push(module);
24
+ }
25
+ }
16
26
  if (allowedModules.length > 0) {
17
27
  opts.require = {
28
+ builtin: allowedModulesBuiltIn,
18
29
  external: {
19
- modules: allowedModules,
30
+ modules: allowedModulesExternal,
20
31
  transitive: false,
21
32
  },
22
33
  };
@@ -6,7 +6,6 @@ const get_accountability_for_role_1 = require("../../utils/get-accountability-fo
6
6
  exports.default = (0, utils_1.defineOperationApi)({
7
7
  id: 'item-create',
8
8
  handler: async ({ collection, payload, emitEvents, permissions }, { accountability, database, getSchema }) => {
9
- var _a;
10
9
  const schema = await getSchema({ database });
11
10
  let customAccountability;
12
11
  if (!permissions || permissions === '$trigger') {
@@ -26,7 +25,7 @@ exports.default = (0, utils_1.defineOperationApi)({
26
25
  accountability: customAccountability,
27
26
  knex: database,
28
27
  });
29
- const payloadObject = (_a = (0, utils_1.optionToObject)(payload)) !== null && _a !== void 0 ? _a : null;
28
+ const payloadObject = (0, utils_1.optionToObject)(payload) ?? null;
30
29
  let result;
31
30
  if (!payloadObject) {
32
31
  result = null;
@@ -1,4 +1,4 @@
1
- import { PrimaryKey } from '@directus/shared/types';
1
+ import type { PrimaryKey } from '@directus/shared/types';
2
2
  type Options = {
3
3
  collection: string;
4
4
  key?: PrimaryKey | PrimaryKey[] | null;
@@ -1,4 +1,4 @@
1
- import { PrimaryKey } from '@directus/shared/types';
1
+ import type { PrimaryKey } from '@directus/shared/types';
2
2
  type Options = {
3
3
  collection: string;
4
4
  key?: PrimaryKey | PrimaryKey[] | null;
@@ -1,4 +1,4 @@
1
- import { PrimaryKey } from '@directus/shared/types';
1
+ import type { PrimaryKey } from '@directus/shared/types';
2
2
  type Options = {
3
3
  collection: string;
4
4
  key?: PrimaryKey | PrimaryKey[] | null;
@@ -7,7 +7,6 @@ const sanitize_query_1 = require("../../utils/sanitize-query");
7
7
  exports.default = (0, utils_1.defineOperationApi)({
8
8
  id: 'item-update',
9
9
  handler: async ({ collection, key, payload, query, emitEvents, permissions }, { accountability, database, getSchema }) => {
10
- var _a;
11
10
  const schema = await getSchema({ database });
12
11
  let customAccountability;
13
12
  if (!permissions || permissions === '$trigger') {
@@ -27,7 +26,7 @@ exports.default = (0, utils_1.defineOperationApi)({
27
26
  accountability: customAccountability,
28
27
  knex: database,
29
28
  });
30
- const payloadObject = (_a = (0, utils_1.optionToObject)(payload)) !== null && _a !== void 0 ? _a : null;
29
+ const payloadObject = (0, utils_1.optionToObject)(payload) ?? null;
31
30
  const queryObject = query ? (0, utils_1.optionToObject)(query) : {};
32
31
  const sanitizedQueryObject = (0, sanitize_query_1.sanitizeQuery)(queryObject, customAccountability);
33
32
  if (!payloadObject) {
@@ -27,10 +27,9 @@ exports.default = (0, utils_1.defineOperationApi)({
27
27
  });
28
28
  const messageString = message ? (0, utils_1.optionToString)(message) : null;
29
29
  const payload = (0, utils_1.toArray)(recipient).map((userId) => {
30
- var _a;
31
30
  return {
32
31
  recipient: userId,
33
- sender: (_a = customAccountability === null || customAccountability === void 0 ? void 0 : customAccountability.user) !== null && _a !== void 0 ? _a : null,
32
+ sender: customAccountability?.user ?? null,
34
33
  subject,
35
34
  message: messageString,
36
35
  };
@@ -9,30 +9,30 @@ const index_1 = require("../../request/index");
9
9
  exports.default = (0, utils_1.defineOperationApi)({
10
10
  id: 'request',
11
11
  handler: async ({ url, method, body, headers }) => {
12
- var _a;
13
- const customHeaders = (_a = headers === null || headers === void 0 ? void 0 : headers.reduce((acc, { header, value }) => {
12
+ const customHeaders = headers?.reduce((acc, { header, value }) => {
14
13
  acc[header] = value;
15
14
  return acc;
16
- }, {})) !== null && _a !== void 0 ? _a : {};
17
- if (!customHeaders['Content-Type'] && isValidJSON(body)) {
15
+ }, {}) ?? {};
16
+ if (!customHeaders['Content-Type'] && (typeof body === 'object' || (0, utils_1.isValidJSON)(body))) {
18
17
  customHeaders['Content-Type'] = 'application/json';
19
18
  }
20
19
  const axios = await (0, index_1.getAxios)();
21
- const result = await axios({
22
- url: (0, encodeurl_1.default)(url),
23
- method,
24
- data: body,
25
- headers: customHeaders,
26
- });
27
- return { status: result.status, statusText: result.statusText, headers: result.headers, data: result.data };
28
- function isValidJSON(value) {
29
- try {
30
- (0, utils_1.parseJSON)(value);
31
- return true;
32
- }
33
- catch {
34
- return false;
35
- }
20
+ try {
21
+ const result = await axios({
22
+ url: (0, encodeurl_1.default)(url),
23
+ method,
24
+ data: body,
25
+ headers: customHeaders,
26
+ });
27
+ return { status: result.status, statusText: result.statusText, headers: result.headers, data: result.data };
28
+ }
29
+ catch (error) {
30
+ throw JSON.stringify({
31
+ status: error.response.status,
32
+ statusText: error.response.statusText,
33
+ headers: error.response.headers,
34
+ data: error.response.data,
35
+ });
36
36
  }
37
37
  },
38
38
  });
@@ -6,9 +6,8 @@ const flows_1 = require("../../flows");
6
6
  exports.default = (0, utils_1.defineOperationApi)({
7
7
  id: 'trigger',
8
8
  handler: async ({ flow, payload, iterationMode, batchSize }, context) => {
9
- var _a;
10
9
  const flowManager = (0, flows_1.getFlowManager)();
11
- const payloadObject = (_a = (0, utils_1.optionToObject)(payload)) !== null && _a !== void 0 ? _a : null;
10
+ const payloadObject = (0, utils_1.optionToObject)(payload) ?? null;
12
11
  if (Array.isArray(payloadObject)) {
13
12
  if (iterationMode === 'serial') {
14
13
  const result = [];
@@ -18,7 +17,7 @@ exports.default = (0, utils_1.defineOperationApi)({
18
17
  return result;
19
18
  }
20
19
  if (iterationMode === 'batch') {
21
- const size = batchSize !== null && batchSize !== void 0 ? batchSize : 10;
20
+ const size = batchSize ?? 10;
22
21
  const result = [];
23
22
  for (let i = 0; i < payloadObject.length; i += size) {
24
23
  const batch = payloadObject.slice(i, i + size);
@@ -1,4 +1,4 @@
1
1
  import { IRateLimiterOptions, IRateLimiterStoreOptions, RateLimiterAbstract } from 'rate-limiter-flexible';
2
2
  type IRateLimiterOptionsOverrides = Partial<IRateLimiterOptions> | Partial<IRateLimiterStoreOptions>;
3
- export declare function createRateLimiter(configOverrides?: IRateLimiterOptionsOverrides): RateLimiterAbstract;
3
+ export declare function createRateLimiter(configPrefix?: string, configOverrides?: IRateLimiterOptionsOverrides): RateLimiterAbstract;
4
4
  export {};