@directus/api 9.25.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 (855) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +89 -0
  3. package/dist/app.d.ts +2 -0
  4. package/dist/app.js +223 -0
  5. package/dist/app.test.d.ts +1 -0
  6. package/dist/auth/auth.d.ts +46 -0
  7. package/dist/auth/auth.js +36 -0
  8. package/dist/auth/drivers/index.d.ts +5 -0
  9. package/dist/auth/drivers/index.js +5 -0
  10. package/dist/auth/drivers/ldap.d.ts +20 -0
  11. package/dist/auth/drivers/ldap.js +330 -0
  12. package/dist/auth/drivers/local.d.ts +9 -0
  13. package/dist/auth/drivers/local.js +83 -0
  14. package/dist/auth/drivers/oauth2.d.ts +19 -0
  15. package/dist/auth/drivers/oauth2.js +293 -0
  16. package/dist/auth/drivers/openid.d.ts +19 -0
  17. package/dist/auth/drivers/openid.js +316 -0
  18. package/dist/auth/drivers/saml.d.ts +15 -0
  19. package/dist/auth/drivers/saml.js +145 -0
  20. package/dist/auth.d.ts +3 -0
  21. package/dist/auth.js +62 -0
  22. package/dist/cache.d.ts +20 -0
  23. package/dist/cache.js +138 -0
  24. package/dist/cli/commands/bootstrap/index.d.ts +3 -0
  25. package/dist/cli/commands/bootstrap/index.js +71 -0
  26. package/dist/cli/commands/count/index.d.ts +1 -0
  27. package/dist/cli/commands/count/index.js +21 -0
  28. package/dist/cli/commands/database/install.d.ts +1 -0
  29. package/dist/cli/commands/database/install.js +16 -0
  30. package/dist/cli/commands/database/migrate.d.ts +1 -0
  31. package/dist/cli/commands/database/migrate.js +23 -0
  32. package/dist/cli/commands/init/index.d.ts +1 -0
  33. package/dist/cli/commands/init/index.js +102 -0
  34. package/dist/cli/commands/init/questions.d.ts +20 -0
  35. package/dist/cli/commands/init/questions.js +65 -0
  36. package/dist/cli/commands/roles/create.d.ts +4 -0
  37. package/dist/cli/commands/roles/create.js +23 -0
  38. package/dist/cli/commands/schema/apply.d.ts +4 -0
  39. package/dist/cli/commands/schema/apply.js +153 -0
  40. package/dist/cli/commands/schema/snapshot.d.ts +4 -0
  41. package/dist/cli/commands/schema/snapshot.js +56 -0
  42. package/dist/cli/commands/security/key.d.ts +1 -0
  43. package/dist/cli/commands/security/key.js +5 -0
  44. package/dist/cli/commands/security/secret.d.ts +1 -0
  45. package/dist/cli/commands/security/secret.js +5 -0
  46. package/dist/cli/commands/users/create.d.ts +5 -0
  47. package/dist/cli/commands/users/create.js +23 -0
  48. package/dist/cli/commands/users/passwd.d.ts +4 -0
  49. package/dist/cli/commands/users/passwd.js +35 -0
  50. package/dist/cli/index.d.ts +2 -0
  51. package/dist/cli/index.js +89 -0
  52. package/dist/cli/run.d.ts +1 -0
  53. package/dist/cli/run.js +8 -0
  54. package/dist/cli/utils/create-db-connection.d.ts +13 -0
  55. package/dist/cli/utils/create-db-connection.js +58 -0
  56. package/dist/cli/utils/create-env/env-stub.liquid +328 -0
  57. package/dist/cli/utils/create-env/index.d.ts +3 -0
  58. package/dist/cli/utils/create-env/index.js +41 -0
  59. package/dist/cli/utils/defaults.d.ts +11 -0
  60. package/dist/cli/utils/defaults.js +11 -0
  61. package/dist/cli/utils/drivers.d.ts +3 -0
  62. package/dist/cli/utils/drivers.js +15 -0
  63. package/dist/constants.d.ts +17 -0
  64. package/dist/constants.js +70 -0
  65. package/dist/controllers/activity.d.ts +2 -0
  66. package/dist/controllers/activity.js +131 -0
  67. package/dist/controllers/assets.d.ts +2 -0
  68. package/dist/controllers/assets.js +194 -0
  69. package/dist/controllers/auth.d.ts +2 -0
  70. package/dist/controllers/auth.js +163 -0
  71. package/dist/controllers/collections.d.ts +2 -0
  72. package/dist/controllers/collections.js +101 -0
  73. package/dist/controllers/dashboards.d.ts +2 -0
  74. package/dist/controllers/dashboards.js +140 -0
  75. package/dist/controllers/extensions.d.ts +2 -0
  76. package/dist/controllers/extensions.js +42 -0
  77. package/dist/controllers/fields.d.ts +2 -0
  78. package/dist/controllers/fields.js +155 -0
  79. package/dist/controllers/files.d.ts +4 -0
  80. package/dist/controllers/files.js +267 -0
  81. package/dist/controllers/files.test.d.ts +1 -0
  82. package/dist/controllers/flows.d.ts +2 -0
  83. package/dist/controllers/flows.js +159 -0
  84. package/dist/controllers/folders.d.ts +2 -0
  85. package/dist/controllers/folders.js +149 -0
  86. package/dist/controllers/graphql.d.ts +2 -0
  87. package/dist/controllers/graphql.js +31 -0
  88. package/dist/controllers/items.d.ts +2 -0
  89. package/dist/controllers/items.js +179 -0
  90. package/dist/controllers/not-found.d.ts +14 -0
  91. package/dist/controllers/not-found.js +31 -0
  92. package/dist/controllers/notifications.d.ts +2 -0
  93. package/dist/controllers/notifications.js +149 -0
  94. package/dist/controllers/operations.d.ts +2 -0
  95. package/dist/controllers/operations.js +140 -0
  96. package/dist/controllers/panels.d.ts +2 -0
  97. package/dist/controllers/panels.js +140 -0
  98. package/dist/controllers/permissions.d.ts +2 -0
  99. package/dist/controllers/permissions.js +151 -0
  100. package/dist/controllers/presets.d.ts +2 -0
  101. package/dist/controllers/presets.js +149 -0
  102. package/dist/controllers/relations.d.ts +2 -0
  103. package/dist/controllers/relations.js +112 -0
  104. package/dist/controllers/revisions.d.ts +2 -0
  105. package/dist/controllers/revisions.js +35 -0
  106. package/dist/controllers/roles.d.ts +2 -0
  107. package/dist/controllers/roles.js +140 -0
  108. package/dist/controllers/schema.d.ts +2 -0
  109. package/dist/controllers/schema.js +93 -0
  110. package/dist/controllers/server.d.ts +2 -0
  111. package/dist/controllers/server.js +57 -0
  112. package/dist/controllers/settings.d.ts +2 -0
  113. package/dist/controllers/settings.js +36 -0
  114. package/dist/controllers/shares.d.ts +2 -0
  115. package/dist/controllers/shares.js +213 -0
  116. package/dist/controllers/users.d.ts +2 -0
  117. package/dist/controllers/users.js +357 -0
  118. package/dist/controllers/utils.d.ts +2 -0
  119. package/dist/controllers/utils.js +118 -0
  120. package/dist/controllers/webhooks.d.ts +2 -0
  121. package/dist/controllers/webhooks.js +137 -0
  122. package/dist/database/helpers/date/dialects/default.d.ts +3 -0
  123. package/dist/database/helpers/date/dialects/default.js +3 -0
  124. package/dist/database/helpers/date/dialects/mssql.d.ts +4 -0
  125. package/dist/database/helpers/date/dialects/mssql.js +8 -0
  126. package/dist/database/helpers/date/dialects/mysql.d.ts +5 -0
  127. package/dist/database/helpers/date/dialects/mysql.js +12 -0
  128. package/dist/database/helpers/date/dialects/oracle.d.ts +4 -0
  129. package/dist/database/helpers/date/dialects/oracle.js +11 -0
  130. package/dist/database/helpers/date/dialects/sqlite.d.ts +5 -0
  131. package/dist/database/helpers/date/dialects/sqlite.js +26 -0
  132. package/dist/database/helpers/date/index.d.ts +7 -0
  133. package/dist/database/helpers/date/index.js +7 -0
  134. package/dist/database/helpers/date/types.d.ts +7 -0
  135. package/dist/database/helpers/date/types.js +20 -0
  136. package/dist/database/helpers/fn/dialects/mssql.d.ts +13 -0
  137. package/dist/database/helpers/fn/dialects/mssql.js +44 -0
  138. package/dist/database/helpers/fn/dialects/mysql.d.ts +13 -0
  139. package/dist/database/helpers/fn/dialects/mysql.js +38 -0
  140. package/dist/database/helpers/fn/dialects/oracle.d.ts +13 -0
  141. package/dist/database/helpers/fn/dialects/oracle.js +44 -0
  142. package/dist/database/helpers/fn/dialects/postgres.d.ts +13 -0
  143. package/dist/database/helpers/fn/dialects/postgres.js +48 -0
  144. package/dist/database/helpers/fn/dialects/sqlite.d.ts +13 -0
  145. package/dist/database/helpers/fn/dialects/sqlite.js +68 -0
  146. package/dist/database/helpers/fn/index.d.ts +7 -0
  147. package/dist/database/helpers/fn/index.js +7 -0
  148. package/dist/database/helpers/fn/types.d.ts +22 -0
  149. package/dist/database/helpers/fn/types.js +26 -0
  150. package/dist/database/helpers/geometry/dialects/mssql.d.ts +14 -0
  151. package/dist/database/helpers/geometry/dialects/mssql.js +32 -0
  152. package/dist/database/helpers/geometry/dialects/mysql.d.ts +7 -0
  153. package/dist/database/helpers/geometry/dialects/mysql.js +12 -0
  154. package/dist/database/helpers/geometry/dialects/oracle.d.ts +15 -0
  155. package/dist/database/helpers/geometry/dialects/oracle.js +35 -0
  156. package/dist/database/helpers/geometry/dialects/postgres.d.ts +10 -0
  157. package/dist/database/helpers/geometry/dialects/postgres.js +18 -0
  158. package/dist/database/helpers/geometry/dialects/redshift.d.ts +7 -0
  159. package/dist/database/helpers/geometry/dialects/redshift.js +12 -0
  160. package/dist/database/helpers/geometry/dialects/sqlite.d.ts +6 -0
  161. package/dist/database/helpers/geometry/dialects/sqlite.js +10 -0
  162. package/dist/database/helpers/geometry/index.d.ts +7 -0
  163. package/dist/database/helpers/geometry/index.js +7 -0
  164. package/dist/database/helpers/geometry/types.d.ts +20 -0
  165. package/dist/database/helpers/geometry/types.js +49 -0
  166. package/dist/database/helpers/index.d.ts +13 -0
  167. package/dist/database/helpers/index.js +17 -0
  168. package/dist/database/helpers/schema/dialects/cockroachdb.d.ts +6 -0
  169. package/dist/database/helpers/schema/dialects/cockroachdb.js +17 -0
  170. package/dist/database/helpers/schema/dialects/default.d.ts +3 -0
  171. package/dist/database/helpers/schema/dialects/default.js +3 -0
  172. package/dist/database/helpers/schema/dialects/mssql.d.ts +7 -0
  173. package/dist/database/helpers/schema/dialects/mssql.js +20 -0
  174. package/dist/database/helpers/schema/dialects/mysql.d.ts +5 -0
  175. package/dist/database/helpers/schema/dialects/mysql.js +14 -0
  176. package/dist/database/helpers/schema/dialects/oracle.d.ts +9 -0
  177. package/dist/database/helpers/schema/dialects/oracle.js +32 -0
  178. package/dist/database/helpers/schema/dialects/sqlite.d.ts +5 -0
  179. package/dist/database/helpers/schema/dialects/sqlite.js +13 -0
  180. package/dist/database/helpers/schema/index.d.ts +7 -0
  181. package/dist/database/helpers/schema/index.js +7 -0
  182. package/dist/database/helpers/schema/types.d.ts +26 -0
  183. package/dist/database/helpers/schema/types.js +91 -0
  184. package/dist/database/helpers/types.d.ts +5 -0
  185. package/dist/database/helpers/types.js +6 -0
  186. package/dist/database/index.d.ts +20 -0
  187. package/dist/database/index.js +267 -0
  188. package/dist/database/migrations/20201028A-remove-collection-foreign-keys.d.ts +3 -0
  189. package/dist/database/migrations/20201028A-remove-collection-foreign-keys.js +42 -0
  190. package/dist/database/migrations/20201029A-remove-system-relations.d.ts +3 -0
  191. package/dist/database/migrations/20201029A-remove-system-relations.js +122 -0
  192. package/dist/database/migrations/20201029B-remove-system-collections.d.ts +3 -0
  193. package/dist/database/migrations/20201029B-remove-system-collections.js +93 -0
  194. package/dist/database/migrations/20201029C-remove-system-fields.d.ts +3 -0
  195. package/dist/database/migrations/20201029C-remove-system-fields.js +1643 -0
  196. package/dist/database/migrations/20201105A-add-cascade-system-relations.d.ts +8 -0
  197. package/dist/database/migrations/20201105A-add-cascade-system-relations.js +131 -0
  198. package/dist/database/migrations/20201105B-change-webhook-url-type.d.ts +3 -0
  199. package/dist/database/migrations/20201105B-change-webhook-url-type.js +12 -0
  200. package/dist/database/migrations/20210225A-add-relations-sort-field.d.ts +3 -0
  201. package/dist/database/migrations/20210225A-add-relations-sort-field.js +28 -0
  202. package/dist/database/migrations/20210304A-remove-locked-fields.d.ts +3 -0
  203. package/dist/database/migrations/20210304A-remove-locked-fields.js +10 -0
  204. package/dist/database/migrations/20210312A-webhooks-collections-text.d.ts +3 -0
  205. package/dist/database/migrations/20210312A-webhooks-collections-text.js +12 -0
  206. package/dist/database/migrations/20210331A-add-refresh-interval.d.ts +3 -0
  207. package/dist/database/migrations/20210331A-add-refresh-interval.js +10 -0
  208. package/dist/database/migrations/20210415A-make-filesize-nullable.d.ts +3 -0
  209. package/dist/database/migrations/20210415A-make-filesize-nullable.js +15 -0
  210. package/dist/database/migrations/20210416A-add-collections-accountability.d.ts +3 -0
  211. package/dist/database/migrations/20210416A-add-collections-accountability.js +11 -0
  212. package/dist/database/migrations/20210422A-remove-files-interface.d.ts +3 -0
  213. package/dist/database/migrations/20210422A-remove-files-interface.js +6 -0
  214. package/dist/database/migrations/20210506A-rename-interfaces.d.ts +3 -0
  215. package/dist/database/migrations/20210506A-rename-interfaces.js +74 -0
  216. package/dist/database/migrations/20210510A-restructure-relations.d.ts +3 -0
  217. package/dist/database/migrations/20210510A-restructure-relations.js +27 -0
  218. package/dist/database/migrations/20210518A-add-foreign-key-constraints.d.ts +3 -0
  219. package/dist/database/migrations/20210518A-add-foreign-key-constraints.js +106 -0
  220. package/dist/database/migrations/20210519A-add-system-fk-triggers.d.ts +3 -0
  221. package/dist/database/migrations/20210519A-add-system-fk-triggers.js +164 -0
  222. package/dist/database/migrations/20210521A-add-collections-icon-color.d.ts +3 -0
  223. package/dist/database/migrations/20210521A-add-collections-icon-color.js +10 -0
  224. package/dist/database/migrations/20210525A-add-insights.d.ts +3 -0
  225. package/dist/database/migrations/20210525A-add-insights.js +31 -0
  226. package/dist/database/migrations/20210608A-add-deep-clone-config.d.ts +3 -0
  227. package/dist/database/migrations/20210608A-add-deep-clone-config.js +10 -0
  228. package/dist/database/migrations/20210626A-change-filesize-bigint.d.ts +3 -0
  229. package/dist/database/migrations/20210626A-change-filesize-bigint.js +19 -0
  230. package/dist/database/migrations/20210716A-add-conditions-to-fields.d.ts +3 -0
  231. package/dist/database/migrations/20210716A-add-conditions-to-fields.js +10 -0
  232. package/dist/database/migrations/20210721A-add-default-folder.d.ts +3 -0
  233. package/dist/database/migrations/20210721A-add-default-folder.js +18 -0
  234. package/dist/database/migrations/20210802A-replace-groups.d.ts +3 -0
  235. package/dist/database/migrations/20210802A-replace-groups.js +45 -0
  236. package/dist/database/migrations/20210803A-add-required-to-fields.d.ts +3 -0
  237. package/dist/database/migrations/20210803A-add-required-to-fields.js +10 -0
  238. package/dist/database/migrations/20210805A-update-groups.d.ts +3 -0
  239. package/dist/database/migrations/20210805A-update-groups.js +29 -0
  240. package/dist/database/migrations/20210805B-change-image-metadata-structure.d.ts +3 -0
  241. package/dist/database/migrations/20210805B-change-image-metadata-structure.js +84 -0
  242. package/dist/database/migrations/20210811A-add-geometry-config.d.ts +3 -0
  243. package/dist/database/migrations/20210811A-add-geometry-config.js +12 -0
  244. package/dist/database/migrations/20210831A-remove-limit-column.d.ts +3 -0
  245. package/dist/database/migrations/20210831A-remove-limit-column.js +10 -0
  246. package/dist/database/migrations/20210903A-add-auth-provider.d.ts +3 -0
  247. package/dist/database/migrations/20210903A-add-auth-provider.js +35 -0
  248. package/dist/database/migrations/20210907A-webhooks-collections-not-null.d.ts +3 -0
  249. package/dist/database/migrations/20210907A-webhooks-collections-not-null.js +13 -0
  250. package/dist/database/migrations/20210910A-move-module-setup.d.ts +3 -0
  251. package/dist/database/migrations/20210910A-move-module-setup.js +16 -0
  252. package/dist/database/migrations/20210920A-webhooks-url-not-null.d.ts +3 -0
  253. package/dist/database/migrations/20210920A-webhooks-url-not-null.js +21 -0
  254. package/dist/database/migrations/20210924A-add-collection-organization.d.ts +3 -0
  255. package/dist/database/migrations/20210924A-add-collection-organization.js +14 -0
  256. package/dist/database/migrations/20210927A-replace-fields-group.d.ts +3 -0
  257. package/dist/database/migrations/20210927A-replace-fields-group.js +48 -0
  258. package/dist/database/migrations/20210927B-replace-m2m-interface.d.ts +3 -0
  259. package/dist/database/migrations/20210927B-replace-m2m-interface.js +16 -0
  260. package/dist/database/migrations/20210929A-rename-login-action.d.ts +3 -0
  261. package/dist/database/migrations/20210929A-rename-login-action.js +14 -0
  262. package/dist/database/migrations/20211007A-update-presets.d.ts +3 -0
  263. package/dist/database/migrations/20211007A-update-presets.js +98 -0
  264. package/dist/database/migrations/20211009A-add-auth-data.d.ts +3 -0
  265. package/dist/database/migrations/20211009A-add-auth-data.js +10 -0
  266. package/dist/database/migrations/20211016A-add-webhook-headers.d.ts +3 -0
  267. package/dist/database/migrations/20211016A-add-webhook-headers.js +10 -0
  268. package/dist/database/migrations/20211103A-set-unique-to-user-token.d.ts +3 -0
  269. package/dist/database/migrations/20211103A-set-unique-to-user-token.js +10 -0
  270. package/dist/database/migrations/20211103B-update-special-geometry.d.ts +3 -0
  271. package/dist/database/migrations/20211103B-update-special-geometry.js +20 -0
  272. package/dist/database/migrations/20211104A-remove-collections-listing.d.ts +3 -0
  273. package/dist/database/migrations/20211104A-remove-collections-listing.js +10 -0
  274. package/dist/database/migrations/20211118A-add-notifications.d.ts +3 -0
  275. package/dist/database/migrations/20211118A-add-notifications.js +23 -0
  276. package/dist/database/migrations/20211211A-add-shares.d.ts +3 -0
  277. package/dist/database/migrations/20211211A-add-shares.js +33 -0
  278. package/dist/database/migrations/20211230A-add-project-descriptor.d.ts +3 -0
  279. package/dist/database/migrations/20211230A-add-project-descriptor.js +10 -0
  280. package/dist/database/migrations/20220303A-remove-default-project-color.d.ts +3 -0
  281. package/dist/database/migrations/20220303A-remove-default-project-color.js +17 -0
  282. package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.d.ts +3 -0
  283. package/dist/database/migrations/20220308A-add-bookmark-icon-and-color.js +12 -0
  284. package/dist/database/migrations/20220314A-add-translation-strings.d.ts +3 -0
  285. package/dist/database/migrations/20220314A-add-translation-strings.js +10 -0
  286. package/dist/database/migrations/20220322A-rename-field-typecast-flags.d.ts +3 -0
  287. package/dist/database/migrations/20220322A-rename-field-typecast-flags.js +72 -0
  288. package/dist/database/migrations/20220323A-add-field-validation.d.ts +3 -0
  289. package/dist/database/migrations/20220323A-add-field-validation.js +12 -0
  290. package/dist/database/migrations/20220325A-fix-typecast-flags.d.ts +3 -0
  291. package/dist/database/migrations/20220325A-fix-typecast-flags.js +44 -0
  292. package/dist/database/migrations/20220325B-add-default-language.d.ts +3 -0
  293. package/dist/database/migrations/20220325B-add-default-language.js +23 -0
  294. package/dist/database/migrations/20220402A-remove-default-value-panel-icon.d.ts +3 -0
  295. package/dist/database/migrations/20220402A-remove-default-value-panel-icon.js +17 -0
  296. package/dist/database/migrations/20220429A-add-flows.d.ts +3 -0
  297. package/dist/database/migrations/20220429A-add-flows.js +77 -0
  298. package/dist/database/migrations/20220429B-add-color-to-insights-icon.d.ts +3 -0
  299. package/dist/database/migrations/20220429B-add-color-to-insights-icon.js +10 -0
  300. package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.d.ts +3 -0
  301. package/dist/database/migrations/20220429C-drop-non-null-from-ip-of-activity.js +10 -0
  302. package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.d.ts +3 -0
  303. package/dist/database/migrations/20220429D-drop-non-null-from-sender-of-notifications.js +10 -0
  304. package/dist/database/migrations/20220614A-rename-hook-trigger-to-event.d.ts +3 -0
  305. package/dist/database/migrations/20220614A-rename-hook-trigger-to-event.js +6 -0
  306. package/dist/database/migrations/20220801A-update-notifications-timestamp-column.d.ts +3 -0
  307. package/dist/database/migrations/20220801A-update-notifications-timestamp-column.js +14 -0
  308. package/dist/database/migrations/20220802A-add-custom-aspect-ratios.d.ts +3 -0
  309. package/dist/database/migrations/20220802A-add-custom-aspect-ratios.js +10 -0
  310. package/dist/database/migrations/20220826A-add-origin-to-accountability.d.ts +3 -0
  311. package/dist/database/migrations/20220826A-add-origin-to-accountability.js +16 -0
  312. package/dist/database/migrations/20230401A-update-material-icons.d.ts +3 -0
  313. package/dist/database/migrations/20230401A-update-material-icons.js +19 -0
  314. package/dist/database/migrations/run.d.ts +2 -0
  315. package/dist/database/migrations/run.js +91 -0
  316. package/dist/database/migrations/run.test.d.ts +1 -0
  317. package/dist/database/run-ast.d.ts +26 -0
  318. package/dist/database/run-ast.js +445 -0
  319. package/dist/database/seeds/01-collections.yaml +42 -0
  320. package/dist/database/seeds/02-roles.yaml +36 -0
  321. package/dist/database/seeds/03-users.yaml +63 -0
  322. package/dist/database/seeds/04-fields.yaml +58 -0
  323. package/dist/database/seeds/05-activity.yaml +35 -0
  324. package/dist/database/seeds/06-folders.yaml +16 -0
  325. package/dist/database/seeds/07-files.yaml +74 -0
  326. package/dist/database/seeds/08-permissions.yaml +32 -0
  327. package/dist/database/seeds/09-presets.yaml +37 -0
  328. package/dist/database/seeds/10-relations.yaml +40 -0
  329. package/dist/database/seeds/11-revisions.yaml +33 -0
  330. package/dist/database/seeds/12-sessions.yaml +23 -0
  331. package/dist/database/seeds/13-settings.yaml +49 -0
  332. package/dist/database/seeds/14-webhooks.yaml +35 -0
  333. package/dist/database/seeds/15-migrations.yaml +14 -0
  334. package/dist/database/seeds/run.d.ts +2 -0
  335. package/dist/database/seeds/run.js +73 -0
  336. package/dist/database/system-data/app-access-permissions/app-access-permissions.yaml +102 -0
  337. package/dist/database/system-data/app-access-permissions/index.d.ts +3 -0
  338. package/dist/database/system-data/app-access-permissions/index.js +17 -0
  339. package/dist/database/system-data/app-access-permissions/schema-access-permissions.yaml +17 -0
  340. package/dist/database/system-data/collections/collections.yaml +74 -0
  341. package/dist/database/system-data/collections/index.d.ts +2 -0
  342. package/dist/database/system-data/collections/index.js +9 -0
  343. package/dist/database/system-data/fields/_defaults.yaml +16 -0
  344. package/dist/database/system-data/fields/activity.yaml +83 -0
  345. package/dist/database/system-data/fields/collections.yaml +214 -0
  346. package/dist/database/system-data/fields/dashboards.yaml +20 -0
  347. package/dist/database/system-data/fields/fields.yaml +104 -0
  348. package/dist/database/system-data/fields/files.yaml +144 -0
  349. package/dist/database/system-data/fields/flows.yaml +26 -0
  350. package/dist/database/system-data/fields/folders.yaml +14 -0
  351. package/dist/database/system-data/fields/index.d.ts +2 -0
  352. package/dist/database/system-data/fields/index.js +33 -0
  353. package/dist/database/system-data/fields/migrations.yaml +10 -0
  354. package/dist/database/system-data/fields/notifications.yaml +15 -0
  355. package/dist/database/system-data/fields/operations.yaml +23 -0
  356. package/dist/database/system-data/fields/panels.yaml +29 -0
  357. package/dist/database/system-data/fields/permissions.yaml +37 -0
  358. package/dist/database/system-data/fields/presets.yaml +56 -0
  359. package/dist/database/system-data/fields/relations.yaml +34 -0
  360. package/dist/database/system-data/fields/revisions.yaml +27 -0
  361. package/dist/database/system-data/fields/roles.yaml +61 -0
  362. package/dist/database/system-data/fields/sessions.yaml +16 -0
  363. package/dist/database/system-data/fields/settings.yaml +417 -0
  364. package/dist/database/system-data/fields/shares.yaml +83 -0
  365. package/dist/database/system-data/fields/users.yaml +182 -0
  366. package/dist/database/system-data/fields/webhooks.yaml +141 -0
  367. package/dist/database/system-data/relations/index.d.ts +2 -0
  368. package/dist/database/system-data/relations/index.js +9 -0
  369. package/dist/database/system-data/relations/relations.yaml +125 -0
  370. package/dist/emitter.d.ts +19 -0
  371. package/dist/emitter.js +79 -0
  372. package/dist/env.d.ts +15 -0
  373. package/dist/env.js +465 -0
  374. package/dist/env.test.d.ts +1 -0
  375. package/dist/exceptions/database/contains-null-values.d.ts +9 -0
  376. package/dist/exceptions/database/contains-null-values.js +6 -0
  377. package/dist/exceptions/database/dialects/mssql.d.ts +2 -0
  378. package/dist/exceptions/database/dialects/mssql.js +152 -0
  379. package/dist/exceptions/database/dialects/mysql.d.ts +2 -0
  380. package/dist/exceptions/database/dialects/mysql.js +144 -0
  381. package/dist/exceptions/database/dialects/oracle.d.ts +2 -0
  382. package/dist/exceptions/database/dialects/oracle.js +23 -0
  383. package/dist/exceptions/database/dialects/postgres.d.ts +2 -0
  384. package/dist/exceptions/database/dialects/postgres.js +102 -0
  385. package/dist/exceptions/database/dialects/sqlite.d.ts +2 -0
  386. package/dist/exceptions/database/dialects/sqlite.js +51 -0
  387. package/dist/exceptions/database/dialects/types.d.ts +41 -0
  388. package/dist/exceptions/database/dialects/types.js +1 -0
  389. package/dist/exceptions/database/invalid-foreign-key.d.ts +10 -0
  390. package/dist/exceptions/database/invalid-foreign-key.js +11 -0
  391. package/dist/exceptions/database/not-null-violation.d.ts +9 -0
  392. package/dist/exceptions/database/not-null-violation.js +6 -0
  393. package/dist/exceptions/database/record-not-unique.d.ts +10 -0
  394. package/dist/exceptions/database/record-not-unique.js +11 -0
  395. package/dist/exceptions/database/translate.d.ts +11 -0
  396. package/dist/exceptions/database/translate.js +44 -0
  397. package/dist/exceptions/database/value-out-of-range.d.ts +10 -0
  398. package/dist/exceptions/database/value-out-of-range.js +11 -0
  399. package/dist/exceptions/database/value-too-long.d.ts +9 -0
  400. package/dist/exceptions/database/value-too-long.js +11 -0
  401. package/dist/exceptions/forbidden.d.ts +6 -0
  402. package/dist/exceptions/forbidden.js +13 -0
  403. package/dist/exceptions/graphql-validation.d.ts +4 -0
  404. package/dist/exceptions/graphql-validation.js +6 -0
  405. package/dist/exceptions/hit-rate-limit.d.ts +9 -0
  406. package/dist/exceptions/hit-rate-limit.js +6 -0
  407. package/dist/exceptions/illegal-asset-transformation.d.ts +4 -0
  408. package/dist/exceptions/illegal-asset-transformation.js +6 -0
  409. package/dist/exceptions/index.d.ts +21 -0
  410. package/dist/exceptions/index.js +21 -0
  411. package/dist/exceptions/invalid-config.d.ts +4 -0
  412. package/dist/exceptions/invalid-config.js +6 -0
  413. package/dist/exceptions/invalid-credentials.d.ts +4 -0
  414. package/dist/exceptions/invalid-credentials.js +6 -0
  415. package/dist/exceptions/invalid-ip.d.ts +4 -0
  416. package/dist/exceptions/invalid-ip.js +6 -0
  417. package/dist/exceptions/invalid-otp.d.ts +4 -0
  418. package/dist/exceptions/invalid-otp.js +6 -0
  419. package/dist/exceptions/invalid-payload.d.ts +4 -0
  420. package/dist/exceptions/invalid-payload.js +6 -0
  421. package/dist/exceptions/invalid-provider.d.ts +4 -0
  422. package/dist/exceptions/invalid-provider.js +6 -0
  423. package/dist/exceptions/invalid-query.d.ts +4 -0
  424. package/dist/exceptions/invalid-query.js +6 -0
  425. package/dist/exceptions/invalid-token.d.ts +4 -0
  426. package/dist/exceptions/invalid-token.js +6 -0
  427. package/dist/exceptions/method-not-allowed.d.ts +8 -0
  428. package/dist/exceptions/method-not-allowed.js +6 -0
  429. package/dist/exceptions/range-not-satisfiable.d.ts +5 -0
  430. package/dist/exceptions/range-not-satisfiable.js +9 -0
  431. package/dist/exceptions/route-not-found.d.ts +4 -0
  432. package/dist/exceptions/route-not-found.js +6 -0
  433. package/dist/exceptions/service-unavailable.d.ts +9 -0
  434. package/dist/exceptions/service-unavailable.js +6 -0
  435. package/dist/exceptions/token-expired.d.ts +4 -0
  436. package/dist/exceptions/token-expired.js +6 -0
  437. package/dist/exceptions/unexpected-response.d.ts +4 -0
  438. package/dist/exceptions/unexpected-response.js +6 -0
  439. package/dist/exceptions/unprocessable-entity.d.ts +4 -0
  440. package/dist/exceptions/unprocessable-entity.js +6 -0
  441. package/dist/exceptions/unsupported-media-type.d.ts +4 -0
  442. package/dist/exceptions/unsupported-media-type.js +6 -0
  443. package/dist/exceptions/user-suspended.d.ts +4 -0
  444. package/dist/exceptions/user-suspended.js +6 -0
  445. package/dist/extensions.d.ts +51 -0
  446. package/dist/extensions.js +490 -0
  447. package/dist/flows.d.ts +22 -0
  448. package/dist/flows.js +350 -0
  449. package/dist/index.d.ts +3 -0
  450. package/dist/index.js +3 -0
  451. package/dist/logger.d.ts +7 -0
  452. package/dist/logger.js +105 -0
  453. package/dist/logger.test.d.ts +1 -0
  454. package/dist/mailer.d.ts +2 -0
  455. package/dist/mailer.js +67 -0
  456. package/dist/messenger.d.ts +24 -0
  457. package/dist/messenger.js +57 -0
  458. package/dist/middleware/authenticate.d.ts +8 -0
  459. package/dist/middleware/authenticate.js +75 -0
  460. package/dist/middleware/authenticate.test.d.ts +1 -0
  461. package/dist/middleware/cache.d.ts +3 -0
  462. package/dist/middleware/cache.js +56 -0
  463. package/dist/middleware/check-ip.d.ts +2 -0
  464. package/dist/middleware/check-ip.js +18 -0
  465. package/dist/middleware/collection-exists.d.ts +6 -0
  466. package/dist/middleware/collection-exists.js +25 -0
  467. package/dist/middleware/cors.d.ts +3 -0
  468. package/dist/middleware/cors.js +14 -0
  469. package/dist/middleware/error-handler.d.ts +3 -0
  470. package/dist/middleware/error-handler.js +90 -0
  471. package/dist/middleware/extract-token.d.ts +11 -0
  472. package/dist/middleware/extract-token.js +30 -0
  473. package/dist/middleware/extract-token.test.d.ts +1 -0
  474. package/dist/middleware/get-permissions.d.ts +3 -0
  475. package/dist/middleware/get-permissions.js +10 -0
  476. package/dist/middleware/graphql.d.ts +2 -0
  477. package/dist/middleware/graphql.js +63 -0
  478. package/dist/middleware/rate-limiter-global.d.ts +5 -0
  479. package/dist/middleware/rate-limiter-global.js +43 -0
  480. package/dist/middleware/rate-limiter-ip.d.ts +5 -0
  481. package/dist/middleware/rate-limiter-ip.js +29 -0
  482. package/dist/middleware/respond.d.ts +2 -0
  483. package/dist/middleware/respond.js +82 -0
  484. package/dist/middleware/sanitize-query.d.ts +7 -0
  485. package/dist/middleware/sanitize-query.js +19 -0
  486. package/dist/middleware/schema.d.ts +3 -0
  487. package/dist/middleware/schema.js +7 -0
  488. package/dist/middleware/use-collection.d.ts +7 -0
  489. package/dist/middleware/use-collection.js +6 -0
  490. package/dist/middleware/validate-batch.d.ts +3 -0
  491. package/dist/middleware/validate-batch.js +42 -0
  492. package/dist/middleware/validate-batch.test.d.ts +1 -0
  493. package/dist/operations/condition/index.d.ts +6 -0
  494. package/dist/operations/condition/index.js +13 -0
  495. package/dist/operations/condition/index.test.d.ts +1 -0
  496. package/dist/operations/exec/index.d.ts +5 -0
  497. package/dist/operations/exec/index.js +38 -0
  498. package/dist/operations/exec/index.test.d.ts +1 -0
  499. package/dist/operations/item-create/index.d.ts +8 -0
  500. package/dist/operations/item-create/index.js +36 -0
  501. package/dist/operations/item-create/index.test.d.ts +1 -0
  502. package/dist/operations/item-delete/index.d.ts +10 -0
  503. package/dist/operations/item-delete/index.js +44 -0
  504. package/dist/operations/item-delete/index.test.d.ts +1 -0
  505. package/dist/operations/item-read/index.d.ts +10 -0
  506. package/dist/operations/item-read/index.js +44 -0
  507. package/dist/operations/item-read/index.test.d.ts +1 -0
  508. package/dist/operations/item-update/index.d.ts +11 -0
  509. package/dist/operations/item-update/index.js +48 -0
  510. package/dist/operations/item-update/index.test.d.ts +1 -0
  511. package/dist/operations/log/index.d.ts +5 -0
  512. package/dist/operations/log/index.js +8 -0
  513. package/dist/operations/log/index.test.d.ts +1 -0
  514. package/dist/operations/mail/index.d.ts +8 -0
  515. package/dist/operations/mail/index.js +17 -0
  516. package/dist/operations/notification/index.d.ts +8 -0
  517. package/dist/operations/notification/index.js +38 -0
  518. package/dist/operations/notification/index.test.d.ts +1 -0
  519. package/dist/operations/request/index.d.ts +11 -0
  520. package/dist/operations/request/index.js +39 -0
  521. package/dist/operations/request/index.test.d.ts +1 -0
  522. package/dist/operations/sleep/index.d.ts +5 -0
  523. package/dist/operations/sleep/index.js +7 -0
  524. package/dist/operations/sleep/index.test.d.ts +1 -0
  525. package/dist/operations/transform/index.d.ts +5 -0
  526. package/dist/operations/transform/index.js +7 -0
  527. package/dist/operations/transform/index.test.d.ts +1 -0
  528. package/dist/operations/trigger/index.d.ts +8 -0
  529. package/dist/operations/trigger/index.js +37 -0
  530. package/dist/operations/trigger/index.test.d.ts +1 -0
  531. package/dist/rate-limiter.d.ts +4 -0
  532. package/dist/rate-limiter.js +33 -0
  533. package/dist/request/index.d.ts +5 -0
  534. package/dist/request/index.js +14 -0
  535. package/dist/request/index.test.d.ts +1 -0
  536. package/dist/request/request-interceptor.d.ts +2 -0
  537. package/dist/request/request-interceptor.js +26 -0
  538. package/dist/request/request-interceptor.test.d.ts +1 -0
  539. package/dist/request/response-interceptor.d.ts +2 -0
  540. package/dist/request/response-interceptor.js +5 -0
  541. package/dist/request/response-interceptor.test.d.ts +1 -0
  542. package/dist/request/validate-ip.d.ts +1 -0
  543. package/dist/request/validate-ip.js +20 -0
  544. package/dist/request/validate-ip.test.d.ts +1 -0
  545. package/dist/server.d.ts +5 -0
  546. package/dist/server.js +135 -0
  547. package/dist/services/activity.d.ts +10 -0
  548. package/dist/services/activity.js +94 -0
  549. package/dist/services/assets.d.ts +18 -0
  550. package/dist/services/assets.js +151 -0
  551. package/dist/services/authentication.d.ts +21 -0
  552. package/dist/services/authentication.js +338 -0
  553. package/dist/services/authorization.d.ts +17 -0
  554. package/dist/services/authorization.js +444 -0
  555. package/dist/services/collections.d.ts +63 -0
  556. package/dist/services/collections.js +568 -0
  557. package/dist/services/dashboards.d.ts +5 -0
  558. package/dist/services/dashboards.js +6 -0
  559. package/dist/services/fields.d.ts +31 -0
  560. package/dist/services/fields.js +596 -0
  561. package/dist/services/files.d.ts +34 -0
  562. package/dist/services/files.js +273 -0
  563. package/dist/services/files.test.d.ts +1 -0
  564. package/dist/services/flows.d.ts +11 -0
  565. package/dist/services/flows.js +39 -0
  566. package/dist/services/folders.d.ts +5 -0
  567. package/dist/services/folders.js +6 -0
  568. package/dist/services/graphql/index.d.ts +86 -0
  569. package/dist/services/graphql/index.js +2512 -0
  570. package/dist/services/graphql/types/bigint.d.ts +2 -0
  571. package/dist/services/graphql/types/bigint.js +36 -0
  572. package/dist/services/graphql/types/date.d.ts +2 -0
  573. package/dist/services/graphql/types/date.js +6 -0
  574. package/dist/services/graphql/types/geojson.d.ts +2 -0
  575. package/dist/services/graphql/types/geojson.js +7 -0
  576. package/dist/services/graphql/types/hash.d.ts +2 -0
  577. package/dist/services/graphql/types/hash.js +6 -0
  578. package/dist/services/graphql/types/string-or-float.d.ts +5 -0
  579. package/dist/services/graphql/types/string-or-float.js +31 -0
  580. package/dist/services/graphql/types/void.d.ts +2 -0
  581. package/dist/services/graphql/types/void.js +14 -0
  582. package/dist/services/graphql/utils/add-path-to-validation-error.d.ts +2 -0
  583. package/dist/services/graphql/utils/add-path-to-validation-error.js +15 -0
  584. package/dist/services/graphql/utils/process-error.d.ts +4 -0
  585. package/dist/services/graphql/utils/process-error.js +41 -0
  586. package/dist/services/graphql/utils/process-error.test.d.ts +1 -0
  587. package/dist/services/import-export.d.ts +37 -0
  588. package/dist/services/import-export.js +293 -0
  589. package/dist/services/index.d.ts +33 -0
  590. package/dist/services/index.js +33 -0
  591. package/dist/services/items.d.ts +88 -0
  592. package/dist/services/items.js +753 -0
  593. package/dist/services/items.test.d.ts +1 -0
  594. package/dist/services/mail/index.d.ts +20 -0
  595. package/dist/services/mail/index.js +91 -0
  596. package/dist/services/mail/templates/base.liquid +162 -0
  597. package/dist/services/mail/templates/password-reset.liquid +24 -0
  598. package/dist/services/mail/templates/user-invitation.liquid +19 -0
  599. package/dist/services/meta.d.ts +12 -0
  600. package/dist/services/meta.js +71 -0
  601. package/dist/services/notifications.d.ts +13 -0
  602. package/dist/services/notifications.js +52 -0
  603. package/dist/services/operations.d.ts +11 -0
  604. package/dist/services/operations.js +37 -0
  605. package/dist/services/panels.d.ts +5 -0
  606. package/dist/services/panels.js +6 -0
  607. package/dist/services/payload.d.ts +73 -0
  608. package/dist/services/payload.js +648 -0
  609. package/dist/services/payload.test.d.ts +1 -0
  610. package/dist/services/permissions.d.ts +17 -0
  611. package/dist/services/permissions.js +80 -0
  612. package/dist/services/presets.d.ts +5 -0
  613. package/dist/services/presets.js +6 -0
  614. package/dist/services/relations.d.ts +60 -0
  615. package/dist/services/relations.js +447 -0
  616. package/dist/services/revisions.d.ts +6 -0
  617. package/dist/services/revisions.js +20 -0
  618. package/dist/services/roles.d.ts +14 -0
  619. package/dist/services/roles.js +144 -0
  620. package/dist/services/roles.test.d.ts +1 -0
  621. package/dist/services/schema.d.ts +15 -0
  622. package/dist/services/schema.js +49 -0
  623. package/dist/services/schema.test.d.ts +1 -0
  624. package/dist/services/server.d.ts +13 -0
  625. package/dist/services/server.js +339 -0
  626. package/dist/services/settings.d.ts +5 -0
  627. package/dist/services/settings.js +6 -0
  628. package/dist/services/shares.d.ts +17 -0
  629. package/dist/services/shares.js +129 -0
  630. package/dist/services/specifications.d.ts +53 -0
  631. package/dist/services/specifications.js +492 -0
  632. package/dist/services/specifications.test.d.ts +1 -0
  633. package/dist/services/tfa.d.ts +12 -0
  634. package/dist/services/tfa.js +50 -0
  635. package/dist/services/users.d.ts +63 -0
  636. package/dist/services/users.js +399 -0
  637. package/dist/services/users.test.d.ts +1 -0
  638. package/dist/services/utils.d.ts +13 -0
  639. package/dist/services/utils.js +108 -0
  640. package/dist/services/webhooks.d.ts +11 -0
  641. package/dist/services/webhooks.js +29 -0
  642. package/dist/services/webhooks.test.d.ts +1 -0
  643. package/dist/start.d.ts +1 -0
  644. package/dist/start.js +2 -0
  645. package/dist/storage/get-storage-driver.d.ts +3 -0
  646. package/dist/storage/get-storage-driver.js +16 -0
  647. package/dist/storage/get-storage-driver.test.d.ts +1 -0
  648. package/dist/storage/index.d.ts +5 -0
  649. package/dist/storage/index.js +16 -0
  650. package/dist/storage/index.test.d.ts +1 -0
  651. package/dist/storage/register-drivers.d.ts +2 -0
  652. package/dist/storage/register-drivers.js +18 -0
  653. package/dist/storage/register-drivers.test.d.ts +1 -0
  654. package/dist/storage/register-locations.d.ts +2 -0
  655. package/dist/storage/register-locations.js +13 -0
  656. package/dist/storage/register-locations.test.d.ts +1 -0
  657. package/dist/types/assets.d.ts +15 -0
  658. package/dist/types/assets.js +51 -0
  659. package/dist/types/ast.d.ts +56 -0
  660. package/dist/types/ast.js +1 -0
  661. package/dist/types/auth.d.ts +54 -0
  662. package/dist/types/auth.js +1 -0
  663. package/dist/types/collection.d.ts +19 -0
  664. package/dist/types/collection.js +1 -0
  665. package/dist/types/database.d.ts +3 -0
  666. package/dist/types/database.js +1 -0
  667. package/dist/types/events.d.ts +18 -0
  668. package/dist/types/events.js +1 -0
  669. package/dist/types/files.d.ts +29 -0
  670. package/dist/types/files.js +1 -0
  671. package/dist/types/graphql.d.ts +14 -0
  672. package/dist/types/graphql.js +1 -0
  673. package/dist/types/index.d.ts +15 -0
  674. package/dist/types/index.js +15 -0
  675. package/dist/types/items.d.ts +55 -0
  676. package/dist/types/items.js +5 -0
  677. package/dist/types/meta.d.ts +4 -0
  678. package/dist/types/meta.js +5 -0
  679. package/dist/types/migration.d.ts +5 -0
  680. package/dist/types/migration.js +1 -0
  681. package/dist/types/revision.d.ts +7 -0
  682. package/dist/types/revision.js +1 -0
  683. package/dist/types/services.d.ts +21 -0
  684. package/dist/types/services.js +1 -0
  685. package/dist/types/snapshot.d.ts +55 -0
  686. package/dist/types/snapshot.js +13 -0
  687. package/dist/types/webhooks.d.ts +15 -0
  688. package/dist/types/webhooks.js +1 -0
  689. package/dist/utils/apply-diff.d.ts +9 -0
  690. package/dist/utils/apply-diff.js +257 -0
  691. package/dist/utils/apply-diff.test.d.ts +1 -0
  692. package/dist/utils/apply-function-to-column-name.d.ts +12 -0
  693. package/dist/utils/apply-function-to-column-name.js +22 -0
  694. package/dist/utils/apply-function-to-column-name.test.d.ts +1 -0
  695. package/dist/utils/apply-query.d.ts +34 -0
  696. package/dist/utils/apply-query.js +555 -0
  697. package/dist/utils/apply-snapshot.d.ts +9 -0
  698. package/dist/utils/apply-snapshot.js +15 -0
  699. package/dist/utils/apply-snapshot.test.d.ts +1 -0
  700. package/dist/utils/async-handler.d.ts +3 -0
  701. package/dist/utils/async-handler.js +2 -0
  702. package/dist/utils/async-handler.test.d.ts +1 -0
  703. package/dist/utils/calculate-field-depth.d.ts +33 -0
  704. package/dist/utils/calculate-field-depth.js +71 -0
  705. package/dist/utils/calculate-field-depth.test.d.ts +1 -0
  706. package/dist/utils/compress.d.ts +3 -0
  707. package/dist/utils/compress.js +12 -0
  708. package/dist/utils/construct-flow-tree.d.ts +2 -0
  709. package/dist/utils/construct-flow-tree.js +27 -0
  710. package/dist/utils/filter-items.d.ts +2 -0
  711. package/dist/utils/filter-items.js +33 -0
  712. package/dist/utils/filter-items.test.d.ts +1 -0
  713. package/dist/utils/generate-hash.d.ts +1 -0
  714. package/dist/utils/generate-hash.js +9 -0
  715. package/dist/utils/get-accountability-for-role.d.ts +7 -0
  716. package/dist/utils/get-accountability-for-role.js +41 -0
  717. package/dist/utils/get-ast-from-query.d.ts +13 -0
  718. package/dist/utils/get-ast-from-query.js +297 -0
  719. package/dist/utils/get-auth-providers.d.ts +8 -0
  720. package/dist/utils/get-auth-providers.js +12 -0
  721. package/dist/utils/get-auth-providers.test.d.ts +1 -0
  722. package/dist/utils/get-cache-headers.d.ts +10 -0
  723. package/dist/utils/get-cache-headers.js +36 -0
  724. package/dist/utils/get-cache-headers.test.d.ts +1 -0
  725. package/dist/utils/get-cache-key.d.ts +2 -0
  726. package/dist/utils/get-cache-key.js +14 -0
  727. package/dist/utils/get-cache-key.test.d.ts +1 -0
  728. package/dist/utils/get-collection-from-alias.d.ts +6 -0
  729. package/dist/utils/get-collection-from-alias.js +12 -0
  730. package/dist/utils/get-collection-from-alias.test.d.ts +1 -0
  731. package/dist/utils/get-column-path.d.ts +26 -0
  732. package/dist/utils/get-column-path.js +61 -0
  733. package/dist/utils/get-column-path.test.d.ts +1 -0
  734. package/dist/utils/get-column.d.ts +20 -0
  735. package/dist/utils/get-column.js +48 -0
  736. package/dist/utils/get-config-from-env.d.ts +1 -0
  737. package/dist/utils/get-config-from-env.js +41 -0
  738. package/dist/utils/get-config-from-env.test.d.ts +1 -0
  739. package/dist/utils/get-date-formatted.d.ts +1 -0
  740. package/dist/utils/get-date-formatted.js +10 -0
  741. package/dist/utils/get-date-formatted.test.d.ts +1 -0
  742. package/dist/utils/get-default-index-name.d.ts +10 -0
  743. package/dist/utils/get-default-index-name.js +21 -0
  744. package/dist/utils/get-default-value.d.ts +3 -0
  745. package/dist/utils/get-default-value.js +56 -0
  746. package/dist/utils/get-graphql-query-and-variables.d.ts +2 -0
  747. package/dist/utils/get-graphql-query-and-variables.js +5 -0
  748. package/dist/utils/get-graphql-query-and-variables.test.d.ts +1 -0
  749. package/dist/utils/get-graphql-type.d.ts +3 -0
  750. package/dist/utils/get-graphql-type.js +36 -0
  751. package/dist/utils/get-ip-from-req.d.ts +2 -0
  752. package/dist/utils/get-ip-from-req.js +17 -0
  753. package/dist/utils/get-local-type.d.ts +9 -0
  754. package/dist/utils/get-local-type.js +128 -0
  755. package/dist/utils/get-milliseconds.d.ts +4 -0
  756. package/dist/utils/get-milliseconds.js +7 -0
  757. package/dist/utils/get-milliseconds.test.d.ts +1 -0
  758. package/dist/utils/get-module-default.d.ts +3 -0
  759. package/dist/utils/get-module-default.js +6 -0
  760. package/dist/utils/get-os-info.d.ts +9 -0
  761. package/dist/utils/get-os-info.js +40 -0
  762. package/dist/utils/get-permissions.d.ts +2 -0
  763. package/dist/utils/get-permissions.js +151 -0
  764. package/dist/utils/get-relation-info.d.ts +7 -0
  765. package/dist/utils/get-relation-info.js +45 -0
  766. package/dist/utils/get-relation-info.test.d.ts +1 -0
  767. package/dist/utils/get-relation-type.d.ts +6 -0
  768. package/dist/utils/get-relation-type.js +18 -0
  769. package/dist/utils/get-relation-type.test.d.ts +1 -0
  770. package/dist/utils/get-schema.d.ts +10 -0
  771. package/dist/utils/get-schema.js +131 -0
  772. package/dist/utils/get-snapshot-diff.d.ts +2 -0
  773. package/dist/utils/get-snapshot-diff.js +78 -0
  774. package/dist/utils/get-snapshot.d.ts +7 -0
  775. package/dist/utils/get-snapshot.js +55 -0
  776. package/dist/utils/get-string-byte-size.d.ts +4 -0
  777. package/dist/utils/get-string-byte-size.js +6 -0
  778. package/dist/utils/get-string-byte-size.test.d.ts +1 -0
  779. package/dist/utils/get-versioned-hash.d.ts +1 -0
  780. package/dist/utils/get-versioned-hash.js +5 -0
  781. package/dist/utils/get-versioned-hash.test.d.ts +1 -0
  782. package/dist/utils/is-directus-jwt.d.ts +5 -0
  783. package/dist/utils/is-directus-jwt.js +16 -0
  784. package/dist/utils/is-directus-jwt.test.d.ts +1 -0
  785. package/dist/utils/is-url-allowed.d.ts +4 -0
  786. package/dist/utils/is-url-allowed.js +30 -0
  787. package/dist/utils/job-queue.d.ts +9 -0
  788. package/dist/utils/job-queue.js +22 -0
  789. package/dist/utils/jwt.d.ts +3 -0
  790. package/dist/utils/jwt.js +29 -0
  791. package/dist/utils/jwt.test.d.ts +1 -0
  792. package/dist/utils/map-values-deep.d.ts +1 -0
  793. package/dist/utils/map-values-deep.js +25 -0
  794. package/dist/utils/map-values-deep.test.d.ts +1 -0
  795. package/dist/utils/md.d.ts +4 -0
  796. package/dist/utils/md.js +8 -0
  797. package/dist/utils/md.test.d.ts +1 -0
  798. package/dist/utils/merge-permissions-for-share.d.ts +4 -0
  799. package/dist/utils/merge-permissions-for-share.js +109 -0
  800. package/dist/utils/merge-permissions.d.ts +3 -0
  801. package/dist/utils/merge-permissions.js +95 -0
  802. package/dist/utils/merge-permissions.test.d.ts +1 -0
  803. package/dist/utils/package.d.ts +2 -0
  804. package/dist/utils/package.js +6 -0
  805. package/dist/utils/parse-image-metadata.d.ts +3 -0
  806. package/dist/utils/parse-image-metadata.js +68 -0
  807. package/dist/utils/reduce-schema.d.ts +9 -0
  808. package/dist/utils/reduce-schema.js +78 -0
  809. package/dist/utils/require-yaml.d.ts +1 -0
  810. package/dist/utils/require-yaml.js +6 -0
  811. package/dist/utils/sanitize-query.d.ts +2 -0
  812. package/dist/utils/sanitize-query.js +172 -0
  813. package/dist/utils/sanitize-query.test.d.ts +1 -0
  814. package/dist/utils/sanitize-schema.d.ts +26 -0
  815. package/dist/utils/sanitize-schema.js +87 -0
  816. package/dist/utils/sanitize-schema.test.d.ts +1 -0
  817. package/dist/utils/should-skip-cache.d.ts +7 -0
  818. package/dist/utils/should-skip-cache.js +26 -0
  819. package/dist/utils/should-skip-cache.test.d.ts +1 -0
  820. package/dist/utils/stall.d.ts +26 -0
  821. package/dist/utils/stall.js +34 -0
  822. package/dist/utils/stall.test.d.ts +1 -0
  823. package/dist/utils/strip-function.d.ts +4 -0
  824. package/dist/utils/strip-function.js +12 -0
  825. package/dist/utils/strip-function.test.d.ts +1 -0
  826. package/dist/utils/telemetry.d.ts +1 -0
  827. package/dist/utils/telemetry.js +23 -0
  828. package/dist/utils/transformations.d.ts +6 -0
  829. package/dist/utils/transformations.js +30 -0
  830. package/dist/utils/url.d.ts +17 -0
  831. package/dist/utils/url.js +59 -0
  832. package/dist/utils/url.test.d.ts +1 -0
  833. package/dist/utils/user-name.d.ts +2 -0
  834. package/dist/utils/user-name.js +15 -0
  835. package/dist/utils/user-name.test.d.ts +1 -0
  836. package/dist/utils/validate-diff.d.ts +7 -0
  837. package/dist/utils/validate-diff.js +110 -0
  838. package/dist/utils/validate-diff.test.d.ts +1 -0
  839. package/dist/utils/validate-env.d.ts +1 -0
  840. package/dist/utils/validate-env.js +11 -0
  841. package/dist/utils/validate-env.test.d.ts +1 -0
  842. package/dist/utils/validate-keys.d.ts +6 -0
  843. package/dist/utils/validate-keys.js +21 -0
  844. package/dist/utils/validate-keys.test.d.ts +1 -0
  845. package/dist/utils/validate-query.d.ts +2 -0
  846. package/dist/utils/validate-query.js +198 -0
  847. package/dist/utils/validate-query.test.d.ts +1 -0
  848. package/dist/utils/validate-snapshot.d.ts +5 -0
  849. package/dist/utils/validate-snapshot.js +64 -0
  850. package/dist/utils/validate-snapshot.test.d.ts +1 -0
  851. package/dist/utils/validate-storage.d.ts +1 -0
  852. package/dist/utils/validate-storage.js +31 -0
  853. package/dist/webhooks.d.ts +4 -0
  854. package/dist/webhooks.js +79 -0
  855. package/package.json +231 -0
@@ -0,0 +1,293 @@
1
+ import { BaseException } from '@directus/exceptions';
2
+ import { parseJSON } from '@directus/utils';
3
+ import express, { Router } from 'express';
4
+ import flatten from 'flat';
5
+ import jwt from 'jsonwebtoken';
6
+ import { errors, generators, Issuer } from 'openid-client';
7
+ import { getAuthProvider } from '../../auth.js';
8
+ import getDatabase from '../../database/index.js';
9
+ import emitter from '../../emitter.js';
10
+ import env from '../../env.js';
11
+ import { RecordNotUniqueException } from '../../exceptions/database/record-not-unique.js';
12
+ import { InvalidConfigException, InvalidCredentialsException, InvalidProviderException, InvalidTokenException, ServiceUnavailableException, } from '../../exceptions/index.js';
13
+ import logger from '../../logger.js';
14
+ import { respond } from '../../middleware/respond.js';
15
+ import { AuthenticationService } from '../../services/authentication.js';
16
+ import { UsersService } from '../../services/users.js';
17
+ import asyncHandler from '../../utils/async-handler.js';
18
+ import { getConfigFromEnv } from '../../utils/get-config-from-env.js';
19
+ import { getIPFromReq } from '../../utils/get-ip-from-req.js';
20
+ import { getMilliseconds } from '../../utils/get-milliseconds.js';
21
+ import { Url } from '../../utils/url.js';
22
+ import { LocalAuthDriver } from './local.js';
23
+ export class OAuth2AuthDriver extends LocalAuthDriver {
24
+ client;
25
+ redirectUrl;
26
+ usersService;
27
+ config;
28
+ constructor(options, config) {
29
+ super(options, config);
30
+ const { authorizeUrl, accessUrl, profileUrl, clientId, clientSecret, ...additionalConfig } = config;
31
+ if (!authorizeUrl || !accessUrl || !profileUrl || !clientId || !clientSecret || !additionalConfig['provider']) {
32
+ throw new InvalidConfigException('Invalid provider config', { provider: additionalConfig['provider'] });
33
+ }
34
+ const redirectUrl = new Url(env['PUBLIC_URL']).addPath('auth', 'login', additionalConfig['provider'], 'callback');
35
+ this.redirectUrl = redirectUrl.toString();
36
+ this.usersService = new UsersService({ knex: this.knex, schema: this.schema });
37
+ this.config = additionalConfig;
38
+ const issuer = new Issuer({
39
+ authorization_endpoint: authorizeUrl,
40
+ token_endpoint: accessUrl,
41
+ userinfo_endpoint: profileUrl,
42
+ issuer: additionalConfig['provider'],
43
+ });
44
+ const clientOptionsOverrides = getConfigFromEnv(`AUTH_${config['provider'].toUpperCase()}_CLIENT_`, [`AUTH_${config['provider'].toUpperCase()}_CLIENT_ID`, `AUTH_${config['provider'].toUpperCase()}_CLIENT_SECRET`], 'underscore');
45
+ this.client = new issuer.Client({
46
+ client_id: clientId,
47
+ client_secret: clientSecret,
48
+ redirect_uris: [this.redirectUrl],
49
+ response_types: ['code'],
50
+ ...clientOptionsOverrides,
51
+ });
52
+ }
53
+ generateCodeVerifier() {
54
+ return generators.codeVerifier();
55
+ }
56
+ generateAuthUrl(codeVerifier, prompt = false) {
57
+ try {
58
+ const codeChallenge = generators.codeChallenge(codeVerifier);
59
+ const paramsConfig = typeof this.config['params'] === 'object' ? this.config['params'] : {};
60
+ return this.client.authorizationUrl({
61
+ scope: this.config['scope'] ?? 'email',
62
+ access_type: 'offline',
63
+ prompt: prompt ? 'consent' : undefined,
64
+ ...paramsConfig,
65
+ code_challenge: codeChallenge,
66
+ code_challenge_method: 'S256',
67
+ // Some providers require state even with PKCE
68
+ state: codeChallenge,
69
+ });
70
+ }
71
+ catch (e) {
72
+ throw handleError(e);
73
+ }
74
+ }
75
+ async fetchUserId(identifier) {
76
+ const user = await this.knex
77
+ .select('id')
78
+ .from('directus_users')
79
+ .whereRaw('LOWER(??) = ?', ['external_identifier', identifier.toLowerCase()])
80
+ .first();
81
+ return user?.id;
82
+ }
83
+ async getUserID(payload) {
84
+ if (!payload['code'] || !payload['codeVerifier'] || !payload['state']) {
85
+ logger.warn('[OAuth2] No code, codeVerifier or state in payload');
86
+ throw new InvalidCredentialsException();
87
+ }
88
+ let tokenSet;
89
+ let userInfo;
90
+ try {
91
+ tokenSet = await this.client.oauthCallback(this.redirectUrl, { code: payload['code'], state: payload['state'] }, { code_verifier: payload['codeVerifier'], state: generators.codeChallenge(payload['codeVerifier']) });
92
+ userInfo = await this.client.userinfo(tokenSet.access_token);
93
+ }
94
+ catch (e) {
95
+ throw handleError(e);
96
+ }
97
+ // Flatten response to support dot indexes
98
+ userInfo = flatten(userInfo);
99
+ const { provider, emailKey, identifierKey, allowPublicRegistration } = this.config;
100
+ const email = userInfo[emailKey ?? 'email'] ? String(userInfo[emailKey ?? 'email']) : undefined;
101
+ // Fallback to email if explicit identifier not found
102
+ const identifier = userInfo[identifierKey] ? String(userInfo[identifierKey]) : email;
103
+ if (!identifier) {
104
+ logger.warn(`[OAuth2] Failed to find user identifier for provider "${provider}"`);
105
+ throw new InvalidCredentialsException();
106
+ }
107
+ const userPayload = {
108
+ provider,
109
+ first_name: userInfo[this.config['firstNameKey']],
110
+ last_name: userInfo[this.config['lastNameKey']],
111
+ email: email,
112
+ external_identifier: identifier,
113
+ role: this.config['defaultRoleId'],
114
+ auth_data: tokenSet.refresh_token && JSON.stringify({ refreshToken: tokenSet.refresh_token }),
115
+ };
116
+ const userId = await this.fetchUserId(identifier);
117
+ if (userId) {
118
+ // Run hook so the end user has the chance to augment the
119
+ // user that is about to be updated
120
+ const updatedUserPayload = await emitter.emitFilter(`auth.update`, {}, {
121
+ identifier,
122
+ provider: this.config['provider'],
123
+ providerPayload: { accessToken: tokenSet.access_token, userInfo },
124
+ }, { database: getDatabase(), schema: this.schema, accountability: null });
125
+ // Update user to update refresh_token and other properties that might have changed
126
+ await this.usersService.updateOne(userId, updatedUserPayload);
127
+ return userId;
128
+ }
129
+ // Is public registration allowed?
130
+ if (!allowPublicRegistration) {
131
+ logger.warn(`[OAuth2] User doesn't exist, and public registration not allowed for provider "${provider}"`);
132
+ throw new InvalidCredentialsException();
133
+ }
134
+ // Run hook so the end user has the chance to augment the
135
+ // user that is about to be created
136
+ const updatedUserPayload = await emitter.emitFilter(`auth.create`, userPayload, {
137
+ identifier,
138
+ provider: this.config['provider'],
139
+ providerPayload: { accessToken: tokenSet.access_token, userInfo },
140
+ }, { database: getDatabase(), schema: this.schema, accountability: null });
141
+ try {
142
+ await this.usersService.createOne(updatedUserPayload);
143
+ }
144
+ catch (e) {
145
+ if (e instanceof RecordNotUniqueException) {
146
+ logger.warn(e, '[OAuth2] Failed to register user. User not unique');
147
+ throw new InvalidProviderException();
148
+ }
149
+ throw e;
150
+ }
151
+ return (await this.fetchUserId(identifier));
152
+ }
153
+ async login(user) {
154
+ return this.refresh(user);
155
+ }
156
+ async refresh(user) {
157
+ let authData = user.auth_data;
158
+ if (typeof authData === 'string') {
159
+ try {
160
+ authData = parseJSON(authData);
161
+ }
162
+ catch {
163
+ logger.warn(`[OAuth2] Session data isn't valid JSON: ${authData}`);
164
+ }
165
+ }
166
+ if (authData?.['refreshToken']) {
167
+ try {
168
+ const tokenSet = await this.client.refresh(authData['refreshToken']);
169
+ // Update user refreshToken if provided
170
+ if (tokenSet.refresh_token) {
171
+ await this.usersService.updateOne(user.id, {
172
+ auth_data: JSON.stringify({ refreshToken: tokenSet.refresh_token }),
173
+ });
174
+ }
175
+ }
176
+ catch (e) {
177
+ throw handleError(e);
178
+ }
179
+ }
180
+ }
181
+ }
182
+ const handleError = (e) => {
183
+ if (e instanceof errors.OPError) {
184
+ if (e.error === 'invalid_grant') {
185
+ // Invalid token
186
+ logger.trace(e, `[OAuth2] Invalid grant`);
187
+ return new InvalidTokenException();
188
+ }
189
+ // Server response error
190
+ logger.trace(e, `[OAuth2] Unknown OP error`);
191
+ return new ServiceUnavailableException('Service returned unexpected response', {
192
+ service: 'oauth2',
193
+ message: e.error_description,
194
+ });
195
+ }
196
+ else if (e instanceof errors.RPError) {
197
+ // Internal client error
198
+ logger.trace(e, `[OAuth2] Unknown RP error`);
199
+ return new InvalidCredentialsException();
200
+ }
201
+ logger.trace(e, `[OAuth2] Unknown error`);
202
+ return e;
203
+ };
204
+ export function createOAuth2AuthRouter(providerName) {
205
+ const router = Router();
206
+ router.get('/', (req, res) => {
207
+ const provider = getAuthProvider(providerName);
208
+ const codeVerifier = provider.generateCodeVerifier();
209
+ const prompt = !!req.query['prompt'];
210
+ const token = jwt.sign({ verifier: codeVerifier, redirect: req.query['redirect'], prompt }, env['SECRET'], {
211
+ expiresIn: '5m',
212
+ issuer: 'directus',
213
+ });
214
+ res.cookie(`oauth2.${providerName}`, token, {
215
+ httpOnly: true,
216
+ sameSite: 'lax',
217
+ });
218
+ return res.redirect(provider.generateAuthUrl(codeVerifier, prompt));
219
+ }, respond);
220
+ router.post('/callback', express.urlencoded({ extended: false }), (req, res) => {
221
+ res.redirect(303, `./callback?${new URLSearchParams(req.body)}`);
222
+ }, respond);
223
+ router.get('/callback', asyncHandler(async (req, res, next) => {
224
+ let tokenData;
225
+ try {
226
+ tokenData = jwt.verify(req.cookies[`oauth2.${providerName}`], env['SECRET'], {
227
+ issuer: 'directus',
228
+ });
229
+ }
230
+ catch (e) {
231
+ logger.warn(e, `[OAuth2] Couldn't verify OAuth2 cookie`);
232
+ throw new InvalidCredentialsException();
233
+ }
234
+ const { verifier, redirect, prompt } = tokenData;
235
+ const accountability = {
236
+ ip: getIPFromReq(req),
237
+ role: null,
238
+ };
239
+ const userAgent = req.get('user-agent');
240
+ if (userAgent)
241
+ accountability.userAgent = userAgent;
242
+ const origin = req.get('origin');
243
+ if (origin)
244
+ accountability.origin = origin;
245
+ const authenticationService = new AuthenticationService({
246
+ accountability,
247
+ schema: req.schema,
248
+ });
249
+ let authResponse;
250
+ try {
251
+ res.clearCookie(`oauth2.${providerName}`);
252
+ authResponse = await authenticationService.login(providerName, {
253
+ code: req.query['code'],
254
+ codeVerifier: verifier,
255
+ state: req.query['state'],
256
+ });
257
+ }
258
+ catch (error) {
259
+ // Prompt user for a new refresh_token if invalidated
260
+ if (error instanceof InvalidTokenException && !prompt) {
261
+ return res.redirect(`./?${redirect ? `redirect=${redirect}&` : ''}prompt=true`);
262
+ }
263
+ if (redirect) {
264
+ let reason = 'UNKNOWN_EXCEPTION';
265
+ if (error instanceof BaseException) {
266
+ reason = error.code;
267
+ }
268
+ else {
269
+ logger.warn(error, `[OAuth2] Unexpected error during OAuth2 login`);
270
+ }
271
+ return res.redirect(`${redirect.split('?')[0]}?reason=${reason}`);
272
+ }
273
+ logger.warn(error, `[OAuth2] Unexpected error during OAuth2 login`);
274
+ throw error;
275
+ }
276
+ const { accessToken, refreshToken, expires } = authResponse;
277
+ if (redirect) {
278
+ res.cookie(env['REFRESH_TOKEN_COOKIE_NAME'], refreshToken, {
279
+ httpOnly: true,
280
+ domain: env['REFRESH_TOKEN_COOKIE_DOMAIN'],
281
+ maxAge: getMilliseconds(env['REFRESH_TOKEN_TTL']),
282
+ secure: env['REFRESH_TOKEN_COOKIE_SECURE'] ?? false,
283
+ sameSite: env['REFRESH_TOKEN_COOKIE_SAME_SITE'] || 'strict',
284
+ });
285
+ return res.redirect(redirect);
286
+ }
287
+ res.locals['payload'] = {
288
+ data: { access_token: accessToken, refresh_token: refreshToken, expires },
289
+ };
290
+ next();
291
+ }), respond);
292
+ return router;
293
+ }
@@ -0,0 +1,19 @@
1
+ import { Router } from 'express';
2
+ import { Client } from 'openid-client';
3
+ import { UsersService } from '../../services/users.js';
4
+ import type { AuthDriverOptions, User } from '../../types/index.js';
5
+ import { LocalAuthDriver } from './local.js';
6
+ export declare class OpenIDAuthDriver extends LocalAuthDriver {
7
+ client: Promise<Client>;
8
+ redirectUrl: string;
9
+ usersService: UsersService;
10
+ config: Record<string, any>;
11
+ constructor(options: AuthDriverOptions, config: Record<string, any>);
12
+ generateCodeVerifier(): string;
13
+ generateAuthUrl(codeVerifier: string, prompt?: boolean): Promise<string>;
14
+ private fetchUserId;
15
+ getUserID(payload: Record<string, any>): Promise<string>;
16
+ login(user: User): Promise<void>;
17
+ refresh(user: User): Promise<void>;
18
+ }
19
+ export declare function createOpenIDAuthRouter(providerName: string): Router;
@@ -0,0 +1,316 @@
1
+ import { BaseException } from '@directus/exceptions';
2
+ import { parseJSON } from '@directus/utils';
3
+ import express, { Router } from 'express';
4
+ import flatten from 'flat';
5
+ import jwt from 'jsonwebtoken';
6
+ import { errors, generators, Issuer } from 'openid-client';
7
+ import { getAuthProvider } from '../../auth.js';
8
+ import getDatabase from '../../database/index.js';
9
+ import emitter from '../../emitter.js';
10
+ import env from '../../env.js';
11
+ import { RecordNotUniqueException } from '../../exceptions/database/record-not-unique.js';
12
+ import { InvalidConfigException, InvalidCredentialsException, InvalidProviderException, InvalidTokenException, ServiceUnavailableException, } from '../../exceptions/index.js';
13
+ import logger from '../../logger.js';
14
+ import { respond } from '../../middleware/respond.js';
15
+ import { AuthenticationService } from '../../services/authentication.js';
16
+ import { UsersService } from '../../services/users.js';
17
+ import asyncHandler from '../../utils/async-handler.js';
18
+ import { getConfigFromEnv } from '../../utils/get-config-from-env.js';
19
+ import { getIPFromReq } from '../../utils/get-ip-from-req.js';
20
+ import { getMilliseconds } from '../../utils/get-milliseconds.js';
21
+ import { Url } from '../../utils/url.js';
22
+ import { LocalAuthDriver } from './local.js';
23
+ export class OpenIDAuthDriver extends LocalAuthDriver {
24
+ client;
25
+ redirectUrl;
26
+ usersService;
27
+ config;
28
+ constructor(options, config) {
29
+ super(options, config);
30
+ const { issuerUrl, clientId, clientSecret, ...additionalConfig } = config;
31
+ if (!issuerUrl || !clientId || !clientSecret || !additionalConfig['provider']) {
32
+ throw new InvalidConfigException('Invalid provider config', { provider: additionalConfig['provider'] });
33
+ }
34
+ const redirectUrl = new Url(env['PUBLIC_URL']).addPath('auth', 'login', additionalConfig['provider'], 'callback');
35
+ const clientOptionsOverrides = getConfigFromEnv(`AUTH_${config['provider'].toUpperCase()}_CLIENT_`, [`AUTH_${config['provider'].toUpperCase()}_CLIENT_ID`, `AUTH_${config['provider'].toUpperCase()}_CLIENT_SECRET`], 'underscore');
36
+ this.redirectUrl = redirectUrl.toString();
37
+ this.usersService = new UsersService({ knex: this.knex, schema: this.schema });
38
+ this.config = additionalConfig;
39
+ this.client = new Promise((resolve, reject) => {
40
+ Issuer.discover(issuerUrl)
41
+ .then((issuer) => {
42
+ const supportedTypes = issuer.metadata['response_types_supported'];
43
+ if (!supportedTypes?.includes('code')) {
44
+ reject(new InvalidConfigException('OpenID provider does not support required code flow', {
45
+ provider: additionalConfig['provider'],
46
+ }));
47
+ }
48
+ resolve(new issuer.Client({
49
+ client_id: clientId,
50
+ client_secret: clientSecret,
51
+ redirect_uris: [this.redirectUrl],
52
+ response_types: ['code'],
53
+ ...clientOptionsOverrides,
54
+ }));
55
+ })
56
+ .catch((e) => {
57
+ logger.error(e, '[OpenID] Failed to fetch provider config');
58
+ process.exit(1);
59
+ });
60
+ });
61
+ }
62
+ generateCodeVerifier() {
63
+ return generators.codeVerifier();
64
+ }
65
+ async generateAuthUrl(codeVerifier, prompt = false) {
66
+ try {
67
+ const client = await this.client;
68
+ const codeChallenge = generators.codeChallenge(codeVerifier);
69
+ const paramsConfig = typeof this.config['params'] === 'object' ? this.config['params'] : {};
70
+ return client.authorizationUrl({
71
+ scope: this.config['scope'] ?? 'openid profile email',
72
+ access_type: 'offline',
73
+ prompt: prompt ? 'consent' : undefined,
74
+ ...paramsConfig,
75
+ code_challenge: codeChallenge,
76
+ code_challenge_method: 'S256',
77
+ // Some providers require state even with PKCE
78
+ state: codeChallenge,
79
+ nonce: codeChallenge,
80
+ });
81
+ }
82
+ catch (e) {
83
+ throw handleError(e);
84
+ }
85
+ }
86
+ async fetchUserId(identifier) {
87
+ const user = await this.knex
88
+ .select('id')
89
+ .from('directus_users')
90
+ .whereRaw('LOWER(??) = ?', ['external_identifier', identifier.toLowerCase()])
91
+ .first();
92
+ return user?.id;
93
+ }
94
+ async getUserID(payload) {
95
+ if (!payload['code'] || !payload['codeVerifier'] || !payload['state']) {
96
+ logger.warn('[OpenID] No code, codeVerifier or state in payload');
97
+ throw new InvalidCredentialsException();
98
+ }
99
+ let tokenSet;
100
+ let userInfo;
101
+ try {
102
+ const client = await this.client;
103
+ const codeChallenge = generators.codeChallenge(payload['codeVerifier']);
104
+ tokenSet = await client.callback(this.redirectUrl, { code: payload['code'], state: payload['state'], iss: payload['iss'] }, { code_verifier: payload['codeVerifier'], state: codeChallenge, nonce: codeChallenge });
105
+ userInfo = tokenSet.claims();
106
+ if (client.issuer.metadata['userinfo_endpoint']) {
107
+ userInfo = {
108
+ ...userInfo,
109
+ ...(await client.userinfo(tokenSet.access_token)),
110
+ };
111
+ }
112
+ }
113
+ catch (e) {
114
+ throw handleError(e);
115
+ }
116
+ // Flatten response to support dot indexes
117
+ userInfo = flatten(userInfo);
118
+ const { provider, identifierKey, allowPublicRegistration, requireVerifiedEmail } = this.config;
119
+ const email = userInfo['email'] ? String(userInfo['email']) : undefined;
120
+ // Fallback to email if explicit identifier not found
121
+ const identifier = userInfo[identifierKey ?? 'sub'] ? String(userInfo[identifierKey ?? 'sub']) : email;
122
+ if (!identifier) {
123
+ logger.warn(`[OpenID] Failed to find user identifier for provider "${provider}"`);
124
+ throw new InvalidCredentialsException();
125
+ }
126
+ const userPayload = {
127
+ provider,
128
+ first_name: userInfo['given_name'],
129
+ last_name: userInfo['family_name'],
130
+ email: email,
131
+ external_identifier: identifier,
132
+ role: this.config['defaultRoleId'],
133
+ auth_data: tokenSet.refresh_token && JSON.stringify({ refreshToken: tokenSet.refresh_token }),
134
+ };
135
+ const userId = await this.fetchUserId(identifier);
136
+ if (userId) {
137
+ // Run hook so the end user has the chance to augment the
138
+ // user that is about to be updated
139
+ const updatedUserPayload = await emitter.emitFilter(`auth.update`, {}, {
140
+ identifier,
141
+ provider: this.config['provider'],
142
+ providerPayload: { accessToken: tokenSet.access_token, userInfo },
143
+ }, { database: getDatabase(), schema: this.schema, accountability: null });
144
+ // Update user to update refresh_token and other properties that might have changed
145
+ await this.usersService.updateOne(userId, updatedUserPayload);
146
+ return userId;
147
+ }
148
+ const isEmailVerified = !requireVerifiedEmail || userInfo['email_verified'];
149
+ // Is public registration allowed?
150
+ if (!allowPublicRegistration || !isEmailVerified) {
151
+ logger.warn(`[OpenID] User doesn't exist, and public registration not allowed for provider "${provider}"`);
152
+ throw new InvalidCredentialsException();
153
+ }
154
+ // Run hook so the end user has the chance to augment the
155
+ // user that is about to be created
156
+ const updatedUserPayload = await emitter.emitFilter(`auth.create`, userPayload, {
157
+ identifier,
158
+ provider: this.config['provider'],
159
+ providerPayload: { accessToken: tokenSet.access_token, userInfo },
160
+ }, { database: getDatabase(), schema: this.schema, accountability: null });
161
+ try {
162
+ await this.usersService.createOne(updatedUserPayload);
163
+ }
164
+ catch (e) {
165
+ if (e instanceof RecordNotUniqueException) {
166
+ logger.warn(e, '[OpenID] Failed to register user. User not unique');
167
+ throw new InvalidProviderException();
168
+ }
169
+ throw e;
170
+ }
171
+ return (await this.fetchUserId(identifier));
172
+ }
173
+ async login(user) {
174
+ return this.refresh(user);
175
+ }
176
+ async refresh(user) {
177
+ let authData = user.auth_data;
178
+ if (typeof authData === 'string') {
179
+ try {
180
+ authData = parseJSON(authData);
181
+ }
182
+ catch {
183
+ logger.warn(`[OpenID] Session data isn't valid JSON: ${authData}`);
184
+ }
185
+ }
186
+ if (authData?.['refreshToken']) {
187
+ try {
188
+ const client = await this.client;
189
+ const tokenSet = await client.refresh(authData['refreshToken']);
190
+ // Update user refreshToken if provided
191
+ if (tokenSet.refresh_token) {
192
+ await this.usersService.updateOne(user.id, {
193
+ auth_data: JSON.stringify({ refreshToken: tokenSet.refresh_token }),
194
+ });
195
+ }
196
+ }
197
+ catch (e) {
198
+ throw handleError(e);
199
+ }
200
+ }
201
+ }
202
+ }
203
+ const handleError = (e) => {
204
+ if (e instanceof errors.OPError) {
205
+ if (e.error === 'invalid_grant') {
206
+ // Invalid token
207
+ logger.trace(e, `[OpenID] Invalid grant`);
208
+ return new InvalidTokenException();
209
+ }
210
+ // Server response error
211
+ logger.trace(e, `[OpenID] Unknown OP error`);
212
+ return new ServiceUnavailableException('Service returned unexpected response', {
213
+ service: 'openid',
214
+ message: e.error_description,
215
+ });
216
+ }
217
+ else if (e instanceof errors.RPError) {
218
+ // Internal client error
219
+ logger.trace(e, `[OpenID] Unknown RP error`);
220
+ return new InvalidCredentialsException();
221
+ }
222
+ logger.trace(e, `[OpenID] Unknown error`);
223
+ return e;
224
+ };
225
+ export function createOpenIDAuthRouter(providerName) {
226
+ const router = Router();
227
+ router.get('/', asyncHandler(async (req, res) => {
228
+ const provider = getAuthProvider(providerName);
229
+ const codeVerifier = provider.generateCodeVerifier();
230
+ const prompt = !!req.query['prompt'];
231
+ const token = jwt.sign({ verifier: codeVerifier, redirect: req.query['redirect'], prompt }, env['SECRET'], {
232
+ expiresIn: '5m',
233
+ issuer: 'directus',
234
+ });
235
+ res.cookie(`openid.${providerName}`, token, {
236
+ httpOnly: true,
237
+ sameSite: 'lax',
238
+ });
239
+ return res.redirect(await provider.generateAuthUrl(codeVerifier, prompt));
240
+ }), respond);
241
+ router.post('/callback', express.urlencoded({ extended: false }), (req, res) => {
242
+ res.redirect(303, `./callback?${new URLSearchParams(req.body)}`);
243
+ }, respond);
244
+ router.get('/callback', asyncHandler(async (req, res, next) => {
245
+ let tokenData;
246
+ try {
247
+ tokenData = jwt.verify(req.cookies[`openid.${providerName}`], env['SECRET'], {
248
+ issuer: 'directus',
249
+ });
250
+ }
251
+ catch (e) {
252
+ logger.warn(e, `[OpenID] Couldn't verify OpenID cookie`);
253
+ throw new InvalidCredentialsException();
254
+ }
255
+ const { verifier, redirect, prompt } = tokenData;
256
+ const accountability = {
257
+ ip: getIPFromReq(req),
258
+ role: null,
259
+ };
260
+ const userAgent = req.get('user-agent');
261
+ if (userAgent)
262
+ accountability.userAgent = userAgent;
263
+ const origin = req.get('origin');
264
+ if (origin)
265
+ accountability.origin = origin;
266
+ const authenticationService = new AuthenticationService({
267
+ accountability,
268
+ schema: req.schema,
269
+ });
270
+ let authResponse;
271
+ try {
272
+ res.clearCookie(`openid.${providerName}`);
273
+ authResponse = await authenticationService.login(providerName, {
274
+ code: req.query['code'],
275
+ codeVerifier: verifier,
276
+ state: req.query['state'],
277
+ iss: req.query['iss'],
278
+ });
279
+ }
280
+ catch (error) {
281
+ // Prompt user for a new refresh_token if invalidated
282
+ if (error instanceof InvalidTokenException && !prompt) {
283
+ return res.redirect(`./?${redirect ? `redirect=${redirect}&` : ''}prompt=true`);
284
+ }
285
+ logger.warn(error);
286
+ if (redirect) {
287
+ let reason = 'UNKNOWN_EXCEPTION';
288
+ if (error instanceof BaseException) {
289
+ reason = error.code;
290
+ }
291
+ else {
292
+ logger.warn(error, `[OpenID] Unexpected error during OpenID login`);
293
+ }
294
+ return res.redirect(`${redirect.split('?')[0]}?reason=${reason}`);
295
+ }
296
+ logger.warn(error, `[OpenID] Unexpected error during OpenID login`);
297
+ throw error;
298
+ }
299
+ const { accessToken, refreshToken, expires } = authResponse;
300
+ if (redirect) {
301
+ res.cookie(env['REFRESH_TOKEN_COOKIE_NAME'], refreshToken, {
302
+ httpOnly: true,
303
+ domain: env['REFRESH_TOKEN_COOKIE_DOMAIN'],
304
+ maxAge: getMilliseconds(env['REFRESH_TOKEN_TTL']),
305
+ secure: env['REFRESH_TOKEN_COOKIE_SECURE'] ?? false,
306
+ sameSite: env['REFRESH_TOKEN_COOKIE_SAME_SITE'] || 'strict',
307
+ });
308
+ return res.redirect(redirect);
309
+ }
310
+ res.locals['payload'] = {
311
+ data: { access_token: accessToken, refresh_token: refreshToken, expires },
312
+ };
313
+ next();
314
+ }), respond);
315
+ return router;
316
+ }
@@ -0,0 +1,15 @@
1
+ import * as samlify from 'samlify';
2
+ import { UsersService } from '../../services/users.js';
3
+ import type { AuthDriverOptions, User } from '../../types/index.js';
4
+ import { LocalAuthDriver } from './local.js';
5
+ export declare class SAMLAuthDriver extends LocalAuthDriver {
6
+ sp: samlify.ServiceProviderInstance;
7
+ idp: samlify.IdentityProviderInstance;
8
+ usersService: UsersService;
9
+ config: Record<string, any>;
10
+ constructor(options: AuthDriverOptions, config: Record<string, any>);
11
+ fetchUserID(identifier: string): Promise<any>;
12
+ getUserID(payload: Record<string, any>): Promise<any>;
13
+ login(_user: User): Promise<void>;
14
+ }
15
+ export declare function createSAMLAuthRouter(providerName: string): import("express-serve-static-core").Router;