payload 4.0.0-internal.e16cf59 → 4.0.0-internal.e55ccef

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 (678) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +11 -0
  3. package/dist/__testing__/predefinedMigration.d.ts +4 -3
  4. package/dist/__testing__/predefinedMigration.d.ts.map +1 -1
  5. package/dist/admin/RichText.d.ts +4 -17
  6. package/dist/admin/RichText.d.ts.map +1 -1
  7. package/dist/admin/RichText.js.map +1 -1
  8. package/dist/admin/adapters/cookies.d.ts +21 -0
  9. package/dist/admin/adapters/cookies.d.ts.map +1 -0
  10. package/dist/admin/adapters/cookies.js +3 -0
  11. package/dist/admin/adapters/cookies.js.map +1 -0
  12. package/dist/admin/adapters/devReload.d.ts +9 -0
  13. package/dist/admin/adapters/devReload.d.ts.map +1 -0
  14. package/dist/admin/adapters/devReload.js +6 -0
  15. package/dist/admin/adapters/devReload.js.map +1 -0
  16. package/dist/admin/adapters/index.d.ts +7 -0
  17. package/dist/admin/adapters/index.d.ts.map +1 -0
  18. package/dist/admin/adapters/index.js +3 -0
  19. package/dist/admin/adapters/index.js.map +1 -0
  20. package/dist/admin/adapters/render.d.ts +16 -0
  21. package/dist/admin/adapters/render.d.ts.map +1 -0
  22. package/dist/admin/adapters/render.js +7 -0
  23. package/dist/admin/adapters/render.js.map +1 -0
  24. package/dist/admin/adapters/router.d.ts +64 -0
  25. package/dist/admin/adapters/router.d.ts.map +1 -0
  26. package/dist/admin/adapters/router.js +3 -0
  27. package/dist/admin/adapters/router.js.map +1 -0
  28. package/dist/admin/adapters/server.d.ts +23 -0
  29. package/dist/admin/adapters/server.d.ts.map +1 -0
  30. package/dist/admin/adapters/server.js +6 -0
  31. package/dist/admin/adapters/server.js.map +1 -0
  32. package/dist/admin/adapters/views.d.ts +36 -0
  33. package/dist/admin/adapters/views.d.ts.map +1 -0
  34. package/dist/admin/adapters/views.js +7 -0
  35. package/dist/admin/adapters/views.js.map +1 -0
  36. package/dist/admin/elements/Table.d.ts +1 -0
  37. package/dist/admin/elements/Table.d.ts.map +1 -1
  38. package/dist/admin/elements/Table.js.map +1 -1
  39. package/dist/admin/fields/Row.d.ts +2 -2
  40. package/dist/admin/fields/Row.d.ts.map +1 -1
  41. package/dist/admin/fields/Row.js.map +1 -1
  42. package/dist/admin/forms/Description.d.ts +2 -2
  43. package/dist/admin/forms/Description.d.ts.map +1 -1
  44. package/dist/admin/forms/Description.js.map +1 -1
  45. package/dist/admin/forms/Field.d.ts +10 -5
  46. package/dist/admin/forms/Field.d.ts.map +1 -1
  47. package/dist/admin/forms/Field.js.map +1 -1
  48. package/dist/admin/functions/index.d.ts +10 -1
  49. package/dist/admin/functions/index.d.ts.map +1 -1
  50. package/dist/admin/functions/index.js.map +1 -1
  51. package/dist/admin/types.d.ts +3 -2
  52. package/dist/admin/types.d.ts.map +1 -1
  53. package/dist/admin/types.js.map +1 -1
  54. package/dist/admin/views/dashboard.d.ts +7 -0
  55. package/dist/admin/views/dashboard.d.ts.map +1 -1
  56. package/dist/admin/views/dashboard.js.map +1 -1
  57. package/dist/admin/views/document.d.ts +5 -3
  58. package/dist/admin/views/document.d.ts.map +1 -1
  59. package/dist/admin/views/document.js.map +1 -1
  60. package/dist/admin/views/hierarchyList.d.ts +1 -0
  61. package/dist/admin/views/hierarchyList.d.ts.map +1 -1
  62. package/dist/admin/views/hierarchyList.js.map +1 -1
  63. package/dist/admin/views/list.d.ts +10 -1
  64. package/dist/admin/views/list.d.ts.map +1 -1
  65. package/dist/admin/views/list.js.map +1 -1
  66. package/dist/auth/baseFields/apiKey.d.ts +10 -2
  67. package/dist/auth/baseFields/apiKey.d.ts.map +1 -1
  68. package/dist/auth/baseFields/apiKey.js +35 -24
  69. package/dist/auth/baseFields/apiKey.js.map +1 -1
  70. package/dist/auth/cookies.d.ts +2 -2
  71. package/dist/auth/cookies.d.ts.map +1 -1
  72. package/dist/auth/defaultAccess.d.ts +1 -1
  73. package/dist/auth/defaultAccess.d.ts.map +1 -1
  74. package/dist/auth/defaultAccess.js +1 -1
  75. package/dist/auth/defaultAccess.js.map +1 -1
  76. package/dist/auth/defaultUser.d.ts.map +1 -1
  77. package/dist/auth/defaultUser.js +2 -1
  78. package/dist/auth/defaultUser.js.map +1 -1
  79. package/dist/auth/extractJWT.d.ts +1 -1
  80. package/dist/auth/getAuthFields.js +2 -2
  81. package/dist/auth/getAuthFields.js.map +1 -1
  82. package/dist/auth/getFieldsToSign.d.ts +1 -1
  83. package/dist/auth/getLoginOptions.d.ts +1 -1
  84. package/dist/auth/operations/auth.d.ts +2 -2
  85. package/dist/auth/operations/auth.d.ts.map +1 -1
  86. package/dist/auth/operations/auth.js.map +1 -1
  87. package/dist/auth/operations/login.d.ts +2 -1
  88. package/dist/auth/operations/login.d.ts.map +1 -1
  89. package/dist/auth/operations/login.js.map +1 -1
  90. package/dist/auth/operations/me.d.ts +2 -2
  91. package/dist/auth/operations/me.d.ts.map +1 -1
  92. package/dist/auth/operations/me.js.map +1 -1
  93. package/dist/auth/operations/refresh.d.ts.map +1 -1
  94. package/dist/auth/operations/refresh.js +9 -3
  95. package/dist/auth/operations/refresh.js.map +1 -1
  96. package/dist/auth/operations/resetPassword.d.ts.map +1 -1
  97. package/dist/auth/operations/resetPassword.js.map +1 -1
  98. package/dist/auth/sendVerificationEmail.d.ts +2 -2
  99. package/dist/auth/sendVerificationEmail.d.ts.map +1 -1
  100. package/dist/auth/sendVerificationEmail.js +1 -1
  101. package/dist/auth/sendVerificationEmail.js.map +1 -1
  102. package/dist/auth/sessions.d.ts +4 -5
  103. package/dist/auth/sessions.d.ts.map +1 -1
  104. package/dist/auth/sessions.js +5 -3
  105. package/dist/auth/sessions.js.map +1 -1
  106. package/dist/auth/strategies/apiKey.d.ts.map +1 -1
  107. package/dist/auth/strategies/apiKey.js +6 -17
  108. package/dist/auth/strategies/apiKey.js.map +1 -1
  109. package/dist/auth/strategies/local/incrementLoginAttempts.d.ts +2 -2
  110. package/dist/auth/strategies/local/incrementLoginAttempts.d.ts.map +1 -1
  111. package/dist/auth/strategies/local/incrementLoginAttempts.js +1 -1
  112. package/dist/auth/strategies/local/incrementLoginAttempts.js.map +1 -1
  113. package/dist/auth/types.d.ts +25 -21
  114. package/dist/auth/types.d.ts.map +1 -1
  115. package/dist/auth/types.js.map +1 -1
  116. package/dist/bin/build.d.ts +49 -0
  117. package/dist/bin/build.d.ts.map +1 -0
  118. package/dist/bin/build.js +226 -0
  119. package/dist/bin/build.js.map +1 -0
  120. package/dist/bin/build.spec.js +594 -0
  121. package/dist/bin/build.spec.js.map +1 -0
  122. package/dist/bin/frameworkConventions.d.ts +8 -0
  123. package/dist/bin/frameworkConventions.d.ts.map +1 -0
  124. package/dist/bin/frameworkConventions.js +8 -0
  125. package/dist/bin/frameworkConventions.js.map +1 -0
  126. package/dist/bin/generateImportMap/index.d.ts.map +1 -1
  127. package/dist/bin/generateImportMap/index.js +8 -5
  128. package/dist/bin/generateImportMap/index.js.map +1 -1
  129. package/dist/bin/generateImportMap/iterateCollections.d.ts.map +1 -1
  130. package/dist/bin/generateImportMap/iterateCollections.js +11 -0
  131. package/dist/bin/generateImportMap/iterateCollections.js.map +1 -1
  132. package/dist/bin/generateImportMap/iterateConfig.d.ts.map +1 -1
  133. package/dist/bin/generateImportMap/iterateConfig.js +12 -0
  134. package/dist/bin/generateImportMap/iterateConfig.js.map +1 -1
  135. package/dist/bin/generateImportMap/iterateFields.d.ts.map +1 -1
  136. package/dist/bin/generateImportMap/iterateFields.js +4 -1
  137. package/dist/bin/generateImportMap/iterateFields.js.map +1 -1
  138. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts +5 -1
  139. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts.map +1 -1
  140. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js +33 -18
  141. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js.map +1 -1
  142. package/dist/bin/generateTypes.d.ts +3 -2
  143. package/dist/bin/generateTypes.d.ts.map +1 -1
  144. package/dist/bin/generateTypes.js +11 -1
  145. package/dist/bin/generateTypes.js.map +1 -1
  146. package/dist/bin/index.d.ts.map +1 -1
  147. package/dist/bin/index.js +9 -0
  148. package/dist/bin/index.js.map +1 -1
  149. package/dist/bin/loadEnv.d.ts +3 -1
  150. package/dist/bin/loadEnv.d.ts.map +1 -1
  151. package/dist/bin/loadEnv.js +40 -10
  152. package/dist/bin/loadEnv.js.map +1 -1
  153. package/dist/collections/config/client.d.ts +3 -3
  154. package/dist/collections/config/client.d.ts.map +1 -1
  155. package/dist/collections/config/client.js +1 -0
  156. package/dist/collections/config/client.js.map +1 -1
  157. package/dist/collections/config/defaults.d.ts +0 -4
  158. package/dist/collections/config/defaults.d.ts.map +1 -1
  159. package/dist/collections/config/defaults.js +2 -17
  160. package/dist/collections/config/defaults.js.map +1 -1
  161. package/dist/collections/config/defaults.spec.js +47 -0
  162. package/dist/collections/config/defaults.spec.js.map +1 -0
  163. package/dist/collections/config/sanitize.d.ts +10 -1
  164. package/dist/collections/config/sanitize.d.ts.map +1 -1
  165. package/dist/collections/config/sanitize.js +1 -11
  166. package/dist/collections/config/sanitize.js.map +1 -1
  167. package/dist/collections/config/types.d.ts +13 -9
  168. package/dist/collections/config/types.d.ts.map +1 -1
  169. package/dist/collections/config/types.js.map +1 -1
  170. package/dist/collections/dataloader.d.ts +1 -1
  171. package/dist/collections/endpoints/create.d.ts.map +1 -1
  172. package/dist/collections/endpoints/create.js +0 -2
  173. package/dist/collections/endpoints/create.js.map +1 -1
  174. package/dist/collections/endpoints/updateByID.d.ts.map +1 -1
  175. package/dist/collections/endpoints/updateByID.js +1 -2
  176. package/dist/collections/endpoints/updateByID.js.map +1 -1
  177. package/dist/collections/operations/count.d.ts.map +1 -1
  178. package/dist/collections/operations/count.js +1 -0
  179. package/dist/collections/operations/count.js.map +1 -1
  180. package/dist/collections/operations/create.d.ts +0 -1
  181. package/dist/collections/operations/create.d.ts.map +1 -1
  182. package/dist/collections/operations/create.js +15 -6
  183. package/dist/collections/operations/create.js.map +1 -1
  184. package/dist/collections/operations/delete.d.ts.map +1 -1
  185. package/dist/collections/operations/delete.js +3 -0
  186. package/dist/collections/operations/delete.js.map +1 -1
  187. package/dist/collections/operations/findDistinct.d.ts.map +1 -1
  188. package/dist/collections/operations/findDistinct.js +1 -0
  189. package/dist/collections/operations/findDistinct.js.map +1 -1
  190. package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
  191. package/dist/collections/operations/local/count.d.ts +3 -3
  192. package/dist/collections/operations/local/count.d.ts.map +1 -1
  193. package/dist/collections/operations/local/count.js.map +1 -1
  194. package/dist/collections/operations/local/countVersions.d.ts +3 -3
  195. package/dist/collections/operations/local/countVersions.d.ts.map +1 -1
  196. package/dist/collections/operations/local/countVersions.js.map +1 -1
  197. package/dist/collections/operations/local/create.d.ts +3 -3
  198. package/dist/collections/operations/local/create.d.ts.map +1 -1
  199. package/dist/collections/operations/local/create.js.map +1 -1
  200. package/dist/collections/operations/local/delete.d.ts +3 -3
  201. package/dist/collections/operations/local/delete.d.ts.map +1 -1
  202. package/dist/collections/operations/local/delete.js.map +1 -1
  203. package/dist/collections/operations/local/duplicate.d.ts +3 -3
  204. package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
  205. package/dist/collections/operations/local/duplicate.js.map +1 -1
  206. package/dist/collections/operations/local/find.d.ts +3 -3
  207. package/dist/collections/operations/local/find.d.ts.map +1 -1
  208. package/dist/collections/operations/local/find.js.map +1 -1
  209. package/dist/collections/operations/local/findByID.d.ts +3 -3
  210. package/dist/collections/operations/local/findByID.d.ts.map +1 -1
  211. package/dist/collections/operations/local/findByID.js.map +1 -1
  212. package/dist/collections/operations/local/findDistinct.d.ts +2 -2
  213. package/dist/collections/operations/local/findDistinct.d.ts.map +1 -1
  214. package/dist/collections/operations/local/findDistinct.js.map +1 -1
  215. package/dist/collections/operations/local/findVersionByID.d.ts +3 -3
  216. package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
  217. package/dist/collections/operations/local/findVersionByID.js.map +1 -1
  218. package/dist/collections/operations/local/findVersions.d.ts +3 -3
  219. package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
  220. package/dist/collections/operations/local/findVersions.js.map +1 -1
  221. package/dist/collections/operations/local/restoreVersion.d.ts +3 -3
  222. package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
  223. package/dist/collections/operations/local/restoreVersion.js.map +1 -1
  224. package/dist/collections/operations/local/update.d.ts +7 -11
  225. package/dist/collections/operations/local/update.d.ts.map +1 -1
  226. package/dist/collections/operations/local/update.js +1 -2
  227. package/dist/collections/operations/local/update.js.map +1 -1
  228. package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
  229. package/dist/collections/operations/update.d.ts +0 -1
  230. package/dist/collections/operations/update.d.ts.map +1 -1
  231. package/dist/collections/operations/update.js +8 -4
  232. package/dist/collections/operations/update.js.map +1 -1
  233. package/dist/collections/operations/updateByID.d.ts +0 -1
  234. package/dist/collections/operations/updateByID.d.ts.map +1 -1
  235. package/dist/collections/operations/updateByID.js +1 -5
  236. package/dist/collections/operations/updateByID.js.map +1 -1
  237. package/dist/collections/operations/utilities/buildAfterOperation.d.ts +1 -1
  238. package/dist/collections/operations/utilities/buildAfterOperation.d.ts.map +1 -1
  239. package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.d.ts +9 -0
  240. package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.d.ts.map +1 -0
  241. package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.js +170 -0
  242. package/dist/collections/operations/utilities/copyDataWithFreshRowIDs.js.map +1 -0
  243. package/dist/collections/operations/utilities/types.d.ts +20 -29
  244. package/dist/collections/operations/utilities/types.d.ts.map +1 -1
  245. package/dist/collections/operations/utilities/types.js.map +1 -1
  246. package/dist/collections/operations/utilities/update.d.ts +1 -2
  247. package/dist/collections/operations/utilities/update.d.ts.map +1 -1
  248. package/dist/collections/operations/utilities/update.js +64 -65
  249. package/dist/collections/operations/utilities/update.js.map +1 -1
  250. package/dist/config/build.d.ts.map +1 -1
  251. package/dist/config/build.js +8 -0
  252. package/dist/config/build.js.map +1 -1
  253. package/dist/config/client.d.ts +3 -3
  254. package/dist/config/client.d.ts.map +1 -1
  255. package/dist/config/client.js +2 -1
  256. package/dist/config/client.js.map +1 -1
  257. package/dist/config/defaults.d.ts +0 -4
  258. package/dist/config/defaults.d.ts.map +1 -1
  259. package/dist/config/defaults.js +0 -78
  260. package/dist/config/defaults.js.map +1 -1
  261. package/dist/config/definePlugin.d.ts +10 -10
  262. package/dist/config/definePlugin.d.ts.map +1 -1
  263. package/dist/config/definePlugin.js +7 -11
  264. package/dist/config/definePlugin.js.map +1 -1
  265. package/dist/config/orderable/fractional-indexing.d.ts +23 -23
  266. package/dist/config/orderable/fractional-indexing.d.ts.map +1 -1
  267. package/dist/config/orderable/index.d.ts.map +1 -1
  268. package/dist/config/orderable/index.js +23 -0
  269. package/dist/config/orderable/index.js.map +1 -1
  270. package/dist/config/sanitize.d.ts.map +1 -1
  271. package/dist/config/sanitize.js +139 -27
  272. package/dist/config/sanitize.js.map +1 -1
  273. package/dist/config/types.d.ts +126 -38
  274. package/dist/config/types.d.ts.map +1 -1
  275. package/dist/config/types.js +2 -0
  276. package/dist/config/types.js.map +1 -1
  277. package/dist/database/getLocalizedPaths.d.ts.map +1 -1
  278. package/dist/database/getLocalizedPaths.js +1 -1
  279. package/dist/database/getLocalizedPaths.js.map +1 -1
  280. package/dist/database/migrations/migrationsCollection.d.ts.map +1 -1
  281. package/dist/database/migrations/migrationsCollection.js +2 -1
  282. package/dist/database/migrations/migrationsCollection.js.map +1 -1
  283. package/dist/database/types.d.ts +1 -5
  284. package/dist/database/types.d.ts.map +1 -1
  285. package/dist/database/types.js.map +1 -1
  286. package/dist/errors/APIError.d.ts.map +1 -1
  287. package/dist/errors/AuthenticationError.d.ts.map +1 -1
  288. package/dist/errors/DuplicateCollection.d.ts.map +1 -1
  289. package/dist/errors/DuplicateFieldName.d.ts.map +1 -1
  290. package/dist/errors/DuplicateGlobal.d.ts.map +1 -1
  291. package/dist/errors/ErrorDeletingFile.d.ts.map +1 -1
  292. package/dist/errors/FileRetrievalError.d.ts.map +1 -1
  293. package/dist/errors/FileUploadError.d.ts.map +1 -1
  294. package/dist/errors/Forbidden.d.ts.map +1 -1
  295. package/dist/errors/InvalidConfiguration.d.ts.map +1 -1
  296. package/dist/errors/InvalidFieldJoin.d.ts.map +1 -1
  297. package/dist/errors/InvalidFieldName.d.ts.map +1 -1
  298. package/dist/errors/InvalidFieldRelationship.d.ts.map +1 -1
  299. package/dist/errors/InvalidSchema.d.ts.map +1 -1
  300. package/dist/errors/Locked.d.ts.map +1 -1
  301. package/dist/errors/LockedAuth.d.ts.map +1 -1
  302. package/dist/errors/MissingCollectionLabel.d.ts.map +1 -1
  303. package/dist/errors/MissingEditorProp.d.ts.map +1 -1
  304. package/dist/errors/MissingFieldInputOptions.d.ts.map +1 -1
  305. package/dist/errors/MissingFieldType.d.ts.map +1 -1
  306. package/dist/errors/MissingFile.d.ts.map +1 -1
  307. package/dist/errors/NotFound.d.ts.map +1 -1
  308. package/dist/errors/QueryError.d.ts.map +1 -1
  309. package/dist/errors/ReservedFieldName.d.ts.map +1 -1
  310. package/dist/errors/TimestampsRequired.d.ts.map +1 -1
  311. package/dist/errors/UnauthorizedError.d.ts.map +1 -1
  312. package/dist/errors/UnverifiedEmail.d.ts.map +1 -1
  313. package/dist/errors/ValidationError.d.ts +1 -0
  314. package/dist/errors/ValidationError.d.ts.map +1 -1
  315. package/dist/errors/ValidationError.js.map +1 -1
  316. package/dist/exports/internal.d.ts +2 -0
  317. package/dist/exports/internal.d.ts.map +1 -1
  318. package/dist/exports/internal.js +2 -0
  319. package/dist/exports/internal.js.map +1 -1
  320. package/dist/exports/migrations.d.ts +5 -13
  321. package/dist/exports/migrations.d.ts.map +1 -1
  322. package/dist/exports/migrations.js +5 -13
  323. package/dist/exports/migrations.js.map +1 -1
  324. package/dist/exports/shared.d.ts +24 -2
  325. package/dist/exports/shared.d.ts.map +1 -1
  326. package/dist/exports/shared.js +23 -1
  327. package/dist/exports/shared.js.map +1 -1
  328. package/dist/fields/baseFields/slug/countVersions.d.ts.map +1 -1
  329. package/dist/fields/baseFields/slug/countVersions.js +6 -8
  330. package/dist/fields/baseFields/slug/countVersions.js.map +1 -1
  331. package/dist/fields/baseFields/slug/generateSlug.d.ts +14 -7
  332. package/dist/fields/baseFields/slug/generateSlug.d.ts.map +1 -1
  333. package/dist/fields/baseFields/slug/generateSlug.js +53 -73
  334. package/dist/fields/baseFields/slug/generateSlug.js.map +1 -1
  335. package/dist/fields/baseFields/slug/types.d.ts +14 -0
  336. package/dist/fields/baseFields/slug/types.d.ts.map +1 -0
  337. package/dist/fields/baseFields/slug/types.js +6 -0
  338. package/dist/fields/baseFields/slug/types.js.map +1 -0
  339. package/dist/fields/config/client.d.ts +6 -6
  340. package/dist/fields/config/client.d.ts.map +1 -1
  341. package/dist/fields/config/client.js +14 -14
  342. package/dist/fields/config/client.js.map +1 -1
  343. package/dist/fields/config/sanitize.d.ts.map +1 -1
  344. package/dist/fields/config/sanitize.js +41 -14
  345. package/dist/fields/config/sanitize.js.map +1 -1
  346. package/dist/fields/config/types.d.ts +80 -76
  347. package/dist/fields/config/types.d.ts.map +1 -1
  348. package/dist/fields/config/types.js +1 -1
  349. package/dist/fields/config/types.js.map +1 -1
  350. package/dist/fields/hooks/afterChange/promise.js +1 -1
  351. package/dist/fields/hooks/afterChange/promise.js.map +1 -1
  352. package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
  353. package/dist/fields/hooks/afterRead/promise.js +13 -3
  354. package/dist/fields/hooks/afterRead/promise.js.map +1 -1
  355. package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
  356. package/dist/fields/hooks/beforeChange/promise.js +3 -3
  357. package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
  358. package/dist/fields/hooks/beforeDuplicate/promise.js +2 -2
  359. package/dist/fields/hooks/beforeDuplicate/promise.js.map +1 -1
  360. package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
  361. package/dist/fields/hooks/beforeValidate/promise.js +16 -5
  362. package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
  363. package/dist/fields/hooks/beforeValidate/stripNullRows.d.ts +10 -0
  364. package/dist/fields/hooks/beforeValidate/stripNullRows.d.ts.map +1 -0
  365. package/dist/fields/hooks/beforeValidate/stripNullRows.js +18 -0
  366. package/dist/fields/hooks/beforeValidate/stripNullRows.js.map +1 -0
  367. package/dist/fields/setDefaultBeforeDuplicate.js +1 -0
  368. package/dist/fields/setDefaultBeforeDuplicate.js.map +1 -1
  369. package/dist/fields/sortableFieldTypes.d.ts.map +1 -1
  370. package/dist/fields/sortableFieldTypes.js +1 -0
  371. package/dist/fields/sortableFieldTypes.js.map +1 -1
  372. package/dist/fields/validations.d.ts +4 -1
  373. package/dist/fields/validations.d.ts.map +1 -1
  374. package/dist/fields/validations.js +12 -4
  375. package/dist/fields/validations.js.map +1 -1
  376. package/dist/globals/config/client.d.ts +4 -4
  377. package/dist/globals/config/sanitize.d.ts +6 -1
  378. package/dist/globals/config/sanitize.d.ts.map +1 -1
  379. package/dist/globals/config/sanitize.js +2 -6
  380. package/dist/globals/config/sanitize.js.map +1 -1
  381. package/dist/globals/config/sanitize.spec.js +43 -0
  382. package/dist/globals/config/sanitize.spec.js.map +1 -0
  383. package/dist/globals/endpoints/update.d.ts.map +1 -1
  384. package/dist/globals/endpoints/update.js +0 -2
  385. package/dist/globals/endpoints/update.js.map +1 -1
  386. package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
  387. package/dist/globals/operations/local/countVersions.d.ts +3 -3
  388. package/dist/globals/operations/local/countVersions.d.ts.map +1 -1
  389. package/dist/globals/operations/local/countVersions.js.map +1 -1
  390. package/dist/globals/operations/local/findOne.d.ts +3 -3
  391. package/dist/globals/operations/local/findOne.d.ts.map +1 -1
  392. package/dist/globals/operations/local/findOne.js.map +1 -1
  393. package/dist/globals/operations/local/findVersionByID.d.ts +3 -3
  394. package/dist/globals/operations/local/findVersionByID.d.ts.map +1 -1
  395. package/dist/globals/operations/local/findVersionByID.js.map +1 -1
  396. package/dist/globals/operations/local/findVersions.d.ts +3 -3
  397. package/dist/globals/operations/local/findVersions.d.ts.map +1 -1
  398. package/dist/globals/operations/local/findVersions.js.map +1 -1
  399. package/dist/globals/operations/local/restoreVersion.d.ts +3 -3
  400. package/dist/globals/operations/local/restoreVersion.d.ts.map +1 -1
  401. package/dist/globals/operations/local/restoreVersion.js.map +1 -1
  402. package/dist/globals/operations/local/update.d.ts +7 -9
  403. package/dist/globals/operations/local/update.d.ts.map +1 -1
  404. package/dist/globals/operations/local/update.js +1 -2
  405. package/dist/globals/operations/local/update.js.map +1 -1
  406. package/dist/globals/operations/restoreVersion.d.ts.map +1 -1
  407. package/dist/globals/operations/update.d.ts +0 -1
  408. package/dist/globals/operations/update.d.ts.map +1 -1
  409. package/dist/globals/operations/update.js +52 -58
  410. package/dist/globals/operations/update.js.map +1 -1
  411. package/dist/hierarchy/resolveHierarchyCollections.js +1 -1
  412. package/dist/hierarchy/resolveHierarchyCollections.js.map +1 -1
  413. package/dist/hierarchy/sanitizeHierarchyCollection.d.ts.map +1 -1
  414. package/dist/hierarchy/sanitizeHierarchyCollection.js +3 -1
  415. package/dist/hierarchy/sanitizeHierarchyCollection.js.map +1 -1
  416. package/dist/hierarchy/types.d.ts +8 -1
  417. package/dist/hierarchy/types.d.ts.map +1 -1
  418. package/dist/hierarchy/types.js.map +1 -1
  419. package/dist/index.bundled.d.ts +864 -468
  420. package/dist/index.d.ts +82 -35
  421. package/dist/index.d.ts.map +1 -1
  422. package/dist/index.js +55 -37
  423. package/dist/index.js.map +1 -1
  424. package/dist/kv/adapters/DatabaseKVAdapter.d.ts.map +1 -1
  425. package/dist/kv/adapters/DatabaseKVAdapter.js +1 -0
  426. package/dist/kv/adapters/DatabaseKVAdapter.js.map +1 -1
  427. package/dist/kv/adapters/InMemoryKVAdapter.d.ts.map +1 -1
  428. package/dist/locked-documents/config.d.ts.map +1 -1
  429. package/dist/locked-documents/config.js +2 -1
  430. package/dist/locked-documents/config.js.map +1 -1
  431. package/dist/preferences/config.d.ts.map +1 -1
  432. package/dist/preferences/config.js +2 -1
  433. package/dist/preferences/config.js.map +1 -1
  434. package/dist/preferences/keys.d.ts +8 -4
  435. package/dist/preferences/keys.d.ts.map +1 -1
  436. package/dist/preferences/keys.js +4 -1
  437. package/dist/preferences/keys.js.map +1 -1
  438. package/dist/preferences/types.d.ts +15 -0
  439. package/dist/preferences/types.d.ts.map +1 -1
  440. package/dist/preferences/types.js +3 -1
  441. package/dist/preferences/types.js.map +1 -1
  442. package/dist/query-presets/config.d.ts.map +1 -1
  443. package/dist/query-presets/config.js +77 -37
  444. package/dist/query-presets/config.js.map +1 -1
  445. package/dist/query-presets/constraints.d.ts.map +1 -1
  446. package/dist/query-presets/constraints.js +3 -2
  447. package/dist/query-presets/constraints.js.map +1 -1
  448. package/dist/query-presets/types.d.ts +1 -1
  449. package/dist/query-presets/types.d.ts.map +1 -1
  450. package/dist/queues/config/collection.d.ts.map +1 -1
  451. package/dist/queues/config/collection.js +2 -1
  452. package/dist/queues/config/collection.js.map +1 -1
  453. package/dist/queues/config/generateJobsJSONSchemas.d.ts +1 -1
  454. package/dist/queues/config/generateJobsJSONSchemas.d.ts.map +1 -1
  455. package/dist/queues/config/generateJobsJSONSchemas.js +33 -12
  456. package/dist/queues/config/generateJobsJSONSchemas.js.map +1 -1
  457. package/dist/queues/config/global.d.ts.map +1 -1
  458. package/dist/queues/config/global.js +2 -1
  459. package/dist/queues/config/global.js.map +1 -1
  460. package/dist/queues/errors/index.d.ts.map +1 -1
  461. package/dist/queues/localAPI.d.ts +8 -8
  462. package/dist/queues/localAPI.d.ts.map +1 -1
  463. package/dist/queues/operations/runJobs/runJob/importHandlerPath.d.ts +1 -1
  464. package/dist/queues/operations/runJobs/runJob/importHandlerPath.d.ts.map +1 -1
  465. package/dist/queues/utilities/getCurrentDate.d.ts.map +1 -1
  466. package/dist/types/constants.d.ts +2 -2
  467. package/dist/types/constants.d.ts.map +1 -1
  468. package/dist/types/index.d.ts +18 -8
  469. package/dist/types/index.d.ts.map +1 -1
  470. package/dist/types/index.js.map +1 -1
  471. package/dist/uploads/cropImage.d.ts.map +1 -1
  472. package/dist/uploads/endpoints/getFileFromURL.d.ts.map +1 -1
  473. package/dist/uploads/endpoints/getFileFromURL.js +9 -5
  474. package/dist/uploads/endpoints/getFileFromURL.js.map +1 -1
  475. package/dist/uploads/fetchAPI-multipart/processMultipart.d.ts.map +1 -1
  476. package/dist/uploads/fetchAPI-multipart/processMultipart.js +4 -0
  477. package/dist/uploads/fetchAPI-multipart/processMultipart.js.map +1 -1
  478. package/dist/uploads/generateFileData.d.ts +2 -1
  479. package/dist/uploads/generateFileData.d.ts.map +1 -1
  480. package/dist/uploads/generateFileData.js +5 -2
  481. package/dist/uploads/generateFileData.js.map +1 -1
  482. package/dist/uploads/getBaseFields.d.ts.map +1 -1
  483. package/dist/uploads/getBaseFields.js +7 -19
  484. package/dist/uploads/getBaseFields.js.map +1 -1
  485. package/dist/uploads/getFileByPath.d.ts +1 -1
  486. package/dist/uploads/image-resizing/getImageResizeAction.d.ts +1 -1
  487. package/dist/uploads/matchMimeType.d.ts +8 -0
  488. package/dist/uploads/matchMimeType.d.ts.map +1 -0
  489. package/dist/uploads/matchMimeType.js +19 -0
  490. package/dist/uploads/matchMimeType.js.map +1 -0
  491. package/dist/uploads/matchMimeType.spec.js +66 -0
  492. package/dist/uploads/matchMimeType.spec.js.map +1 -0
  493. package/dist/uploads/safeFetch.d.ts +1 -1
  494. package/dist/uploads/safeFetch.d.ts.map +1 -1
  495. package/dist/uploads/safeFetch.js +11 -5
  496. package/dist/uploads/safeFetch.js.map +1 -1
  497. package/dist/uploads/types.d.ts +33 -29
  498. package/dist/uploads/types.d.ts.map +1 -1
  499. package/dist/uploads/types.js.map +1 -1
  500. package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
  501. package/dist/utilities/addDataAndFileToRequest.js +6 -0
  502. package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
  503. package/dist/utilities/appendDateTimezoneSelectFields.js +2 -2
  504. package/dist/utilities/appendDateTimezoneSelectFields.js.map +1 -1
  505. package/dist/utilities/configToJSONSchema.d.ts +68 -16
  506. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  507. package/dist/utilities/configToJSONSchema.js +312 -117
  508. package/dist/utilities/configToJSONSchema.js.map +1 -1
  509. package/dist/utilities/configToJSONSchema.spec.js +656 -85
  510. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  511. package/dist/utilities/createLocalReq.d.ts +2 -2
  512. package/dist/utilities/createLocalReq.d.ts.map +1 -1
  513. package/dist/utilities/createLocalReq.js.map +1 -1
  514. package/dist/utilities/createPayloadRequest.d.ts.map +1 -1
  515. package/dist/utilities/createPayloadRequest.js +1 -0
  516. package/dist/utilities/createPayloadRequest.js.map +1 -1
  517. package/dist/utilities/deepCopyObject.d.ts.map +1 -1
  518. package/dist/utilities/deepCopyObject.js +8 -0
  519. package/dist/utilities/deepCopyObject.js.map +1 -1
  520. package/dist/utilities/dependencies/dependencyChecker.js +1 -1
  521. package/dist/utilities/dependencies/dependencyChecker.js.map +1 -1
  522. package/dist/utilities/dependencies/getDependencies.d.ts.map +1 -1
  523. package/dist/utilities/dependencies/getDependencies.js +5 -5
  524. package/dist/utilities/dependencies/getDependencies.js.map +1 -1
  525. package/dist/utilities/dynamicImport.js +1 -1
  526. package/dist/utilities/dynamicImport.js.map +1 -1
  527. package/dist/utilities/filterDataToSelectedLocales.d.ts.map +1 -1
  528. package/dist/utilities/filterDataToSelectedLocales.js +5 -12
  529. package/dist/utilities/filterDataToSelectedLocales.js.map +1 -1
  530. package/dist/utilities/filterDataToSelectedLocales.spec.js +1 -2
  531. package/dist/utilities/filterDataToSelectedLocales.spec.js.map +1 -1
  532. package/dist/utilities/flattenAllFields.d.ts.map +1 -1
  533. package/dist/utilities/flattenAllFields.js +7 -22
  534. package/dist/utilities/flattenAllFields.js.map +1 -1
  535. package/dist/utilities/formatErrors.d.ts.map +1 -1
  536. package/dist/utilities/formatErrors.js +3 -1
  537. package/dist/utilities/formatErrors.js.map +1 -1
  538. package/dist/utilities/getDataByPath.d.ts.map +1 -1
  539. package/dist/utilities/getEntityPermissions/getEntityPermissions.d.ts.map +1 -1
  540. package/dist/utilities/getEntityPermissions/getEntityPermissions.js +2 -0
  541. package/dist/utilities/getEntityPermissions/getEntityPermissions.js.map +1 -1
  542. package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts +7 -1
  543. package/dist/utilities/getEntityPermissions/populateFieldPermissions.d.ts.map +1 -1
  544. package/dist/utilities/getEntityPermissions/populateFieldPermissions.js +24 -7
  545. package/dist/utilities/getEntityPermissions/populateFieldPermissions.js.map +1 -1
  546. package/dist/utilities/getFieldByPath.d.ts.map +1 -1
  547. package/dist/utilities/getFieldByPath.js +1 -1
  548. package/dist/utilities/getFieldByPath.js.map +1 -1
  549. package/dist/utilities/getRequestLanguage.d.ts +2 -2
  550. package/dist/utilities/getRequestLanguage.d.ts.map +1 -1
  551. package/dist/utilities/getRequestLanguage.js.map +1 -1
  552. package/dist/utilities/getRequestOrigin.d.ts +2 -2
  553. package/dist/utilities/getVersionsConfig.d.ts +1 -1
  554. package/dist/utilities/getVersionsConfig.js.map +1 -1
  555. package/dist/utilities/handleEndpoints.d.ts.map +1 -1
  556. package/dist/utilities/handleEndpoints.js +7 -4
  557. package/dist/utilities/handleEndpoints.js.map +1 -1
  558. package/dist/utilities/isEntityHidden.d.ts +2 -2
  559. package/dist/utilities/isURLAllowed.d.ts.map +1 -1
  560. package/dist/utilities/isURLAllowed.js +9 -3
  561. package/dist/utilities/isURLAllowed.js.map +1 -1
  562. package/dist/utilities/isURLAllowed.spec.js +78 -0
  563. package/dist/utilities/isURLAllowed.spec.js.map +1 -0
  564. package/dist/utilities/isValidID.d.ts +1 -1
  565. package/dist/utilities/logger.d.ts +1 -1
  566. package/dist/utilities/mergeLocalizedData.d.ts +14 -4
  567. package/dist/utilities/mergeLocalizedData.d.ts.map +1 -1
  568. package/dist/utilities/mergeLocalizedData.js +54 -46
  569. package/dist/utilities/mergeLocalizedData.js.map +1 -1
  570. package/dist/utilities/mergeLocalizedData.spec.js +23 -23
  571. package/dist/utilities/mergeLocalizedData.spec.js.map +1 -1
  572. package/dist/utilities/miniChalk.d.ts.map +1 -1
  573. package/dist/utilities/parseCookies.d.ts +1 -1
  574. package/dist/utilities/parseParams/index.d.ts +2 -5
  575. package/dist/utilities/parseParams/index.d.ts.map +1 -1
  576. package/dist/utilities/parseParams/index.js.map +1 -1
  577. package/dist/utilities/parseParams/index.spec.js +0 -9
  578. package/dist/utilities/parseParams/index.spec.js.map +1 -1
  579. package/dist/utilities/resolveSelect.d.ts.map +1 -1
  580. package/dist/utilities/telemetry/conf/index.d.ts.map +1 -1
  581. package/dist/utilities/telemetry/events/adminInit.d.ts.map +1 -1
  582. package/dist/utilities/telemetry/events/adminInit.js +2 -3
  583. package/dist/utilities/telemetry/events/adminInit.js.map +1 -1
  584. package/dist/utilities/telemetry/events/serverInit.d.ts.map +1 -1
  585. package/dist/utilities/telemetry/events/serverInit.js +2 -3
  586. package/dist/utilities/telemetry/events/serverInit.js.map +1 -1
  587. package/dist/utilities/telemetry/index.d.ts +15 -4
  588. package/dist/utilities/telemetry/index.d.ts.map +1 -1
  589. package/dist/utilities/telemetry/index.js +6 -1
  590. package/dist/utilities/telemetry/index.js.map +1 -1
  591. package/dist/utilities/telemetry/index.spec.js +43 -0
  592. package/dist/utilities/telemetry/index.spec.js.map +1 -0
  593. package/dist/utilities/transformColumnPreferences.js +4 -2
  594. package/dist/utilities/transformColumnPreferences.js.map +1 -1
  595. package/dist/utilities/traverseFields.d.ts.map +1 -1
  596. package/dist/utilities/traverseFields.js +2 -4
  597. package/dist/utilities/traverseFields.js.map +1 -1
  598. package/dist/utilities/traverseForLocalizedFields.d.ts.map +1 -1
  599. package/dist/utilities/traverseForLocalizedFields.js +3 -0
  600. package/dist/utilities/traverseForLocalizedFields.js.map +1 -1
  601. package/dist/versions/baseFields.d.ts +1 -2
  602. package/dist/versions/baseFields.d.ts.map +1 -1
  603. package/dist/versions/baseFields.js +0 -13
  604. package/dist/versions/baseFields.js.map +1 -1
  605. package/dist/versions/buildCollectionFields.d.ts.map +1 -1
  606. package/dist/versions/buildCollectionFields.js +0 -2
  607. package/dist/versions/buildCollectionFields.js.map +1 -1
  608. package/dist/versions/buildGlobalFields.d.ts.map +1 -1
  609. package/dist/versions/buildGlobalFields.js +0 -2
  610. package/dist/versions/buildGlobalFields.js.map +1 -1
  611. package/dist/versions/buildSingleLocalePublishData.d.ts +32 -0
  612. package/dist/versions/buildSingleLocalePublishData.d.ts.map +1 -0
  613. package/dist/versions/buildSingleLocalePublishData.js +37 -0
  614. package/dist/versions/buildSingleLocalePublishData.js.map +1 -0
  615. package/dist/versions/defaults.d.ts.map +1 -1
  616. package/dist/versions/getLatestCollectionVersion.d.ts.map +1 -1
  617. package/dist/versions/payloadPackageList.d.ts.map +1 -1
  618. package/dist/versions/payloadPackageList.js +0 -1
  619. package/dist/versions/payloadPackageList.js.map +1 -1
  620. package/dist/versions/saveVersion.d.ts +0 -2
  621. package/dist/versions/saveVersion.d.ts.map +1 -1
  622. package/dist/versions/saveVersion.js +12 -17
  623. package/dist/versions/saveVersion.js.map +1 -1
  624. package/dist/versions/schedule/job.d.ts.map +1 -1
  625. package/dist/versions/schedule/job.js +6 -10
  626. package/dist/versions/schedule/job.js.map +1 -1
  627. package/dist/versions/types.d.ts +2 -15
  628. package/dist/versions/types.d.ts.map +1 -1
  629. package/dist/versions/types.js.map +1 -1
  630. package/package.json +23 -20
  631. package/dist/database/migrations/templates/localizeStatus.d.ts +0 -10
  632. package/dist/database/migrations/templates/localizeStatus.d.ts.map +0 -1
  633. package/dist/database/migrations/templates/localizeStatus.js +0 -54
  634. package/dist/database/migrations/templates/localizeStatus.js.map +0 -1
  635. package/dist/fields/baseFields/slug/index.d.ts +0 -89
  636. package/dist/fields/baseFields/slug/index.d.ts.map +0 -1
  637. package/dist/fields/baseFields/slug/index.js +0 -81
  638. package/dist/fields/baseFields/slug/index.js.map +0 -1
  639. package/dist/versions/migrations/localizeStatus/index.d.ts +0 -12
  640. package/dist/versions/migrations/localizeStatus/index.d.ts.map +0 -1
  641. package/dist/versions/migrations/localizeStatus/index.js +0 -33
  642. package/dist/versions/migrations/localizeStatus/index.js.map +0 -1
  643. package/dist/versions/migrations/localizeStatus/mongo/down.d.ts +0 -9
  644. package/dist/versions/migrations/localizeStatus/mongo/down.d.ts.map +0 -1
  645. package/dist/versions/migrations/localizeStatus/mongo/down.js +0 -112
  646. package/dist/versions/migrations/localizeStatus/mongo/down.js.map +0 -1
  647. package/dist/versions/migrations/localizeStatus/mongo/index.d.ts +0 -8
  648. package/dist/versions/migrations/localizeStatus/mongo/index.d.ts.map +0 -1
  649. package/dist/versions/migrations/localizeStatus/mongo/index.js +0 -8
  650. package/dist/versions/migrations/localizeStatus/mongo/index.js.map +0 -1
  651. package/dist/versions/migrations/localizeStatus/mongo/up.d.ts +0 -9
  652. package/dist/versions/migrations/localizeStatus/mongo/up.d.ts.map +0 -1
  653. package/dist/versions/migrations/localizeStatus/mongo/up.js +0 -220
  654. package/dist/versions/migrations/localizeStatus/mongo/up.js.map +0 -1
  655. package/dist/versions/migrations/localizeStatus/sql/down.d.ts +0 -11
  656. package/dist/versions/migrations/localizeStatus/sql/down.d.ts.map +0 -1
  657. package/dist/versions/migrations/localizeStatus/sql/down.js +0 -213
  658. package/dist/versions/migrations/localizeStatus/sql/down.js.map +0 -1
  659. package/dist/versions/migrations/localizeStatus/sql/index.d.ts +0 -8
  660. package/dist/versions/migrations/localizeStatus/sql/index.d.ts.map +0 -1
  661. package/dist/versions/migrations/localizeStatus/sql/index.js +0 -8
  662. package/dist/versions/migrations/localizeStatus/sql/index.js.map +0 -1
  663. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts +0 -13
  664. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts.map +0 -1
  665. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js +0 -51
  666. package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js.map +0 -1
  667. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts +0 -13
  668. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts.map +0 -1
  669. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js +0 -54
  670. package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js.map +0 -1
  671. package/dist/versions/migrations/localizeStatus/sql/up.d.ts +0 -11
  672. package/dist/versions/migrations/localizeStatus/sql/up.d.ts.map +0 -1
  673. package/dist/versions/migrations/localizeStatus/sql/up.js +0 -277
  674. package/dist/versions/migrations/localizeStatus/sql/up.js.map +0 -1
  675. package/dist/versions/saveSnapshot.d.ts +0 -18
  676. package/dist/versions/saveSnapshot.d.ts.map +0 -1
  677. package/dist/versions/saveSnapshot.js +0 -38
  678. package/dist/versions/saveSnapshot.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/operations/refresh.ts"],"sourcesContent":["import type { Collection } from '../../collections/config/types.js'\nimport type { Document, PayloadRequest } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from '../../collections/operations/utilities/buildBeforeOperation.js'\nimport { Forbidden } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.js'\nimport { removeExpiredSessions } from '../sessions.js'\n\nexport type Result = {\n exp: number\n refreshedToken: string\n setCookie?: boolean\n /** @deprecated\n * use:\n * ```ts\n * user._strategy\n * ```\n */\n strategy?: string\n user: Document\n}\n\nexport type Arguments = {\n collection: Collection\n req: PayloadRequest\n}\n\nexport const refreshOperation = async (incomingArgs: Arguments): Promise<Result> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'refresh',\n overrideAccess: false,\n })\n\n // /////////////////////////////////////\n // Refresh\n // /////////////////////////////////////\n\n const {\n collection: { config: collectionConfig },\n req,\n req: {\n payload: { config, secret },\n },\n } = args\n\n if (!args.req.user) {\n throw new Forbidden(args.req.t)\n }\n\n const pathname = new URL(args.req.url!).pathname\n\n const isGraphQL = pathname === config.routes.graphQL\n\n let user = await req.payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where: { id: { equals: args.req.user.id } },\n })\n\n const sid = args.req.user._sid\n\n if (collectionConfig.auth.useSessions && !collectionConfig.auth.disableLocalStrategy) {\n if (!Array.isArray(user.sessions) || !sid) {\n throw new Forbidden(args.req.t)\n }\n\n const existingSession = user.sessions.find(({ id }: { id: number }) => id === sid)\n\n const now = new Date()\n const tokenExpInMs = collectionConfig.auth.tokenExpiration * 1000\n existingSession.expiresAt = new Date(now.getTime() + tokenExpInMs)\n\n // Prevent updatedAt from being updated when only refreshing a session\n user.updatedAt = null\n\n await req.payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: {\n ...user,\n sessions: removeExpiredSessions(user.sessions),\n },\n req,\n returning: false,\n })\n }\n\n user = await req.payload.findByID({\n id: user.id,\n collection: collectionConfig.slug,\n depth: isGraphQL ? 0 : args.collection.config.auth.depth,\n req: args.req,\n })\n\n if (user) {\n user.collection = args.req.user.collection\n user._strategy = args.req.user._strategy\n }\n\n let result!: Result\n\n // /////////////////////////////////////\n // refresh hook - Collection\n // /////////////////////////////////////\n\n for (const refreshHook of args.collection.config.hooks.refresh) {\n const hookResult = await refreshHook({ args, user })\n\n if (hookResult) {\n result = hookResult\n break\n }\n }\n\n if (!result) {\n const fieldsToSign = getFieldsToSign({\n collectionConfig,\n email: user?.email as string,\n sid,\n user: args?.req?.user,\n })\n\n const { exp, token: refreshedToken } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n result = {\n exp,\n refreshedToken,\n setCookie: true,\n /** @deprecated\n * use:\n * ```ts\n * user._strategy\n * ```\n */\n strategy: args.req.user._strategy,\n user,\n }\n }\n\n // /////////////////////////////////////\n // After Refresh - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRefresh?.length) {\n for (const hook of collectionConfig.hooks.afterRefresh) {\n result =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n exp: result.exp,\n req: args.req,\n token: result.refreshedToken,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'refresh',\n overrideAccess: false,\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["buildAfterOperation","buildBeforeOperation","Forbidden","commitTransaction","initTransaction","killTransaction","getFieldsToSign","jwtSign","removeExpiredSessions","refreshOperation","incomingArgs","args","shouldCommit","req","collection","config","operation","overrideAccess","collectionConfig","payload","secret","user","t","pathname","URL","url","isGraphQL","routes","graphQL","db","findOne","slug","where","id","equals","sid","_sid","auth","useSessions","disableLocalStrategy","Array","isArray","sessions","existingSession","find","now","Date","tokenExpInMs","tokenExpiration","expiresAt","getTime","updatedAt","updateOne","data","returning","findByID","depth","_strategy","result","refreshHook","hooks","refresh","hookResult","fieldsToSign","email","exp","token","refreshedToken","setCookie","str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;QACjB,wCAAwC;QAExC,IAAI9C,cAAc;YAChB,MAAMT,kBAAkBU;QAC1B;QAEA,OAAO6C;IACT,EAAE,OAAOgB,OAAgB;QACvB,MAAMrE,gBAAgBM,KAAKE,GAAG;QAC9B,MAAM6D;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/operations/refresh.ts"],"sourcesContent":["import type { Collection } from '../../collections/config/types.js'\nimport type { AuthenticatedUser } from '../../index.js'\nimport type { Document, PayloadRequest } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from '../../collections/operations/utilities/buildBeforeOperation.js'\nimport { Forbidden } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.js'\nimport { removeExpiredSessions } from '../sessions.js'\n\nexport type Result = {\n exp: number\n refreshedToken: string\n setCookie?: boolean\n /** @deprecated\n * use:\n * ```ts\n * user._strategy\n * ```\n */\n strategy?: string\n user: Document\n}\n\nexport type Arguments = {\n collection: Collection\n req: PayloadRequest\n}\n\nexport const refreshOperation = async (incomingArgs: Arguments): Promise<Result> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'refresh',\n overrideAccess: false,\n })\n\n // /////////////////////////////////////\n // Refresh\n // /////////////////////////////////////\n\n const {\n collection: { config: collectionConfig },\n req,\n req: {\n payload: { config, secret },\n },\n } = args\n\n if (!args.req.user) {\n throw new Forbidden(args.req.t)\n }\n\n const pathname = new URL(args.req.url!).pathname\n\n const isGraphQL = pathname === config.routes.graphQL\n\n let user = await req.payload.db.findOne<AuthenticatedUser>({\n collection: collectionConfig.slug,\n req,\n where: { id: { equals: args.req.user.id } },\n })\n\n if (!user) {\n throw new Forbidden(args.req.t)\n }\n\n const sid = args.req.user._sid\n\n if (collectionConfig.auth.useSessions && !collectionConfig.auth.disableLocalStrategy) {\n if (!Array.isArray(user.sessions) || !sid) {\n throw new Forbidden(args.req.t)\n }\n\n const existingSession = user.sessions.find(({ id }) => id === sid)\n\n if (!existingSession) {\n throw new Forbidden(args.req.t)\n }\n\n const now = new Date()\n const tokenExpInMs = collectionConfig.auth.tokenExpiration * 1000\n existingSession.expiresAt = new Date(now.getTime() + tokenExpInMs)\n\n await req.payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: {\n ...user,\n // Prevent updatedAt from being updated when only refreshing a session\n sessions: removeExpiredSessions(user.sessions),\n updatedAt: null,\n },\n req,\n returning: false,\n })\n }\n\n user = (await req.payload.findByID({\n id: user.id,\n collection: collectionConfig.slug,\n depth: isGraphQL ? 0 : args.collection.config.auth.depth,\n req: args.req,\n })) as AuthenticatedUser\n\n if (user) {\n user.collection = args.req.user.collection\n user._strategy = args.req.user._strategy\n }\n\n let result!: Result\n\n // /////////////////////////////////////\n // refresh hook - Collection\n // /////////////////////////////////////\n\n for (const refreshHook of args.collection.config.hooks.refresh) {\n const hookResult = await refreshHook({ args, user })\n\n if (hookResult) {\n result = hookResult\n break\n }\n }\n\n if (!result) {\n const fieldsToSign = getFieldsToSign({\n collectionConfig,\n email: user?.email as string,\n sid,\n user: args?.req?.user,\n })\n\n const { exp, token: refreshedToken } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n result = {\n exp,\n refreshedToken,\n setCookie: true,\n /** @deprecated\n * use:\n * ```ts\n * user._strategy\n * ```\n */\n strategy: args.req.user._strategy,\n user,\n }\n }\n\n // /////////////////////////////////////\n // After Refresh - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRefresh?.length) {\n for (const hook of collectionConfig.hooks.afterRefresh) {\n result =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n exp: result.exp,\n req: args.req,\n token: result.refreshedToken,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'refresh',\n overrideAccess: false,\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["buildAfterOperation","buildBeforeOperation","Forbidden","commitTransaction","initTransaction","killTransaction","getFieldsToSign","jwtSign","removeExpiredSessions","refreshOperation","incomingArgs","args","shouldCommit","req","collection","config","operation","overrideAccess","collectionConfig","payload","secret","user","t","pathname","URL","url","isGraphQL","routes","graphQL","db","findOne","slug","where","id","equals","sid","_sid","auth","useSessions","disableLocalStrategy","Array","isArray","sessions","existingSession","find","now","Date","tokenExpInMs","tokenExpiration","expiresAt","getTime","updateOne","data","updatedAt","returning","findByID","depth","_strategy","result","refreshHook","hooks","refresh","hookResult","fieldsToSign","email","exp","token","refreshedToken","setCookie","strategy","afterRefresh","length","hook","context","error"],"mappings":"AAIA,SAASA,mBAAmB,QAAQ,gEAA+D;AACnG,SAASC,oBAAoB,QAAQ,iEAAgE;AACrG,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,OAAO,QAAQ,YAAW;AACnC,SAASC,qBAAqB,QAAQ,iBAAgB;AAqBtD,OAAO,MAAMC,mBAAmB,OAAOC;IACrC,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,MAAMR,gBAAgBO,KAAKE,GAAG;QAEnD,wCAAwC;QACxC,+BAA+B;Q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AM2C;gBACb7B;gBACAd,MAAMV,MAAME,KAAKQ;YACnB;YAEA,MAAM,EAAE4C,GAAG,EAAEC,OAAOC,cAAc,EAAE,GAAG,MAAM5D,QAAQ;gBACnDwD;gBACA3C;gBACA4B,iBAAiB9B,iBAAiBmB,IAAI,CAACW,eAAe;YACxD;YAEAU,SAAS;gBACPO;gBACAE;gBACAC,WAAW;gBACX;;;;;SAKC,GACDC,UAAU1D,KAAKE,GAAG,CAACQ,IAAI,CAACoC,SAAS;gBACjCpC;YACF;QACF;QAEA,wCAAwC;QACxC,6BAA6B;QAC7B,wCAAwC;QAExC,IAAIH,iBAAiB0C,KAAK,EAAEU,cAAcC,QAAQ;YAChD,KAAK,MAAMC,QAAQtD,iBAAiB0C,KAAK,CAACU,YAAY,CAAE;gBACtDZ,SACE,AAAC,MAAMc,KAAK;oBACV1D,YAAYH,KAAKG,UAAU,EAAEC;oBAC7B0D,SAAS9D,KAAKE,GAAG,CAAC4D,OAAO;oBACzBR,KAAKP,OAAOO,GAAG;oBACfpD,KAAKF,KAAKE,GAAG;oBACbqD,OAAOR,OAAOS,cAAc;gBAC9B,MAAOT;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCA,SAAS,MAAM1D,oBAAoB;YACjCW;YACAG,YAAYH,KAAKG,UAAU,EAAEC;YAC7BC,WAAW;YACXC,gBAAgB;YAChByC;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAI9C,cAAc;YAChB,MAAMT,kBAAkBU;QAC1B;QAEA,OAAO6C;IACT,EAAE,OAAOgB,OAAgB;QACvB,MAAMrE,gBAAgBM,KAAKE,GAAG;QAC9B,MAAM6D;IACR;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/resetPassword.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,mCAAmC,CAAA;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O,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAU,KAAK,SAAS,kBAAkB,QACrE,SAAS,KACd,OAAO,CAAC,MAAM,CA4NhB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/operations/resetPassword.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { Collection, DataFromCollectionSlug } from '../../collections/config/types.js'\nimport type { AuthCollectionSlug, TypedUser } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from '../../collections/operations/utilities/buildBeforeOperation.js'\nimport { APIError, Forbidden } from '../../errors/index.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.js'\nimport { addSessionToUser, revokeSession } from '../sessions.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { generatePasswordSaltHash } from '../strategies/local/generatePasswordSaltHash.js'\n\nexport type Result = {\n token?: string\n user: Record<string, unknown>\n}\n\nexport type Arguments = {\n collection: Collection\n data: {\n password: string\n token: string\n }\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const resetPasswordOperation = async <TSlug extends AuthCollectionSlug>(\n args: Arguments,\n): Promise<Result> => {\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req: {\n payload: { secret },\n payload,\n },\n req,\n } = args\n\n if (\n !Object.prototype.hasOwnProperty.call(data, 'token') ||\n !Object.prototype.hasOwnProperty.call(data, 'password')\n ) {\n throw new APIError('Missing required data.', httpStatus.BAD_REQUEST)\n }\n\n if (collectionConfig.auth.disableLocalStrategy) {\n throw new Forbidden(req.t)\n }\n\n let sid: string | undefined\n let user: null | TypedUser = null\n\n try {\n const shouldCommit = await initTransaction(req)\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'resetPassword',\n overrideAccess,\n })\n\n // /////////////////////////////////////\n // Reset Password\n // /////////////////////////////////////\n\n const where = appendNonTrashedFilter({\n enableTrash: Boolean(collectionConfig.trash),\n trash: false,\n where: {\n resetPasswordExpiration: { greater_than: new Date().toISOString() },\n resetPasswordToken: { equals: data.token },\n },\n })\n\n user = await payload.db.findOne<TypedUser>({\n collection: collectionConfig.slug,\n req,\n where,\n })\n\n if (!user) {\n throw new APIError('Token is either invalid or has expired.', httpStatus.FORBIDDEN)\n }\n\n // TODO: replace this method\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password: data.password,\n req,\n })\n\n user.salt = salt\n user.hash = hash\n\n user.resetPasswordExpiration = new Date().toISOString()\n\n if (collectionConfig.auth.verify) {\n user._verified = Boolean(user._verified)\n }\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n await hook({\n collection: args.collection?.config,\n context: req.context,\n data: user,\n operation: 'update',\n req,\n })\n }\n }\n\n // /////////////////////////////////////\n // Update new password\n // /////////////////////////////////////\n\n // Ensure updatedAt date is always updated\n user.updatedAt = new Date().toISOString()\n\n const doc = await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n await authenticateLocalStrategy({ doc, password: data.password })\n\n const fieldsToSignArgs: Parameters<typeof getFieldsToSign>[0] = {\n collectionConfig,\n email: user.email!,\n user,\n }\n\n const session = await addSessionToUser({\n collectionConfig,\n payload,\n req,\n user,\n })\n sid = session.sid\n\n if (sid) {\n fieldsToSignArgs.sid = sid\n }\n\n const fieldsToSign = getFieldsToSign(fieldsToSignArgs)\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n let userBeforeLogin = user\n\n if (collectionConfig.hooks?.beforeLogin?.length) {\n for (const hook of collectionConfig.hooks.beforeLogin) {\n userBeforeLogin =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user: userBeforeLogin,\n })) || userBeforeLogin\n }\n }\n\n const { token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = userBeforeLogin\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterLogin?.length) {\n for (const hook of collectionConfig.hooks.afterLogin) {\n userBeforeLogin =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n token,\n user: userBeforeLogin,\n })) || userBeforeLogin\n }\n }\n\n const fullUser = await payload.findByID({\n id: user.id,\n collection: collectionConfig.slug,\n depth,\n overrideAccess,\n req,\n trash: false,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n if (fullUser) {\n fullUser.collection = collectionConfig.slug\n fullUser._strategy = 'local-jwt'\n }\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n token,\n user: fullUser,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'resetPassword',\n overrideAccess,\n result,\n })\n\n return result\n } catch (error: unknown) {\n if (sid) {\n await revokeSession({\n collectionConfig,\n payload,\n req,\n sid,\n user,\n })\n }\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["status","httpStatus","buildAfterOperation","buildBeforeOperation","APIError","Forbidden","appendNonTrashedFilter","commitTransaction","initTransaction","killTransaction","getFieldsToSign","jwtSign","addSessionToUser","revokeSession","authenticateLocalStrategy","generatePasswordSaltHash","resetPasswordOperation","args","collection","config","collectionConfig","data","depth","overrideAccess","req","payload","secret","Object","prototype","hasOwnProperty","call","BAD_REQUEST","auth","disableLocalStrategy","t","sid","user","shouldCommit","operation","where","enableTrash","Boolean","trash","resetPasswordExpiration","greater_than","Date","toISOString","resetPasswordToken","equals","token","db","findOne","slug","FORBIDDEN","hash","salt","password","verify","_verified","hooks","beforeValidate","length","hook","context","updatedAt","doc","updateOne","id","fieldsToSignArgs","email","session","fieldsToSign","userBeforeLogin","beforeLogin","tokenExpiration","afterLogin","fullUser","findByID","_strategy","result","error"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAMlD,SAASC,mBAAmB,QAAQ,gEAA+D;AACnG,SAASC,oBAAoB,QAAQ,iEAAgE;AACrG,SAASC,QAAQ,EAAEC,SAAS,QAAQ,wBAAuB;AAC3D,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,OAAO,QAAQ,YAAW;AACnC,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,iBAAgB;AAChE,SAASC,yBAAyB,QAAQ,sCAAqC;AAC/E,SAASC,wBAAwB,QAAQ,kDAAiD;AAkB1F,OAAO,MAAMC,yBAAyB,OACpCC;IAEA,MAAM,EACJC,YAAY,EAAEC,QAAQC,gBAAgB,EAAE,EACxCC,IAAI,EACJC,KAAK,EACLC,cAAc,EACdC,KAAK,EACHC,SAAS,EAAEC,MAAM,EAAE,EACnBD,OAAO,EACR,EACDD,GAAG,EACJ,GAAGP;IAEJ,IACE,CAACU,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACT,MAAM,YAC5C,CAACM,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACT,MAAM,aAC5C;QACA,MAAM,IAAIjB,SAAS,0BAA0BH,WAAW8B,WAAW;IACrE;IAEA,IAAIX,iBAAiBY,IAAI,CAACC,oBAAoB,EAAE;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GoC;QAEX,wCAAwC;QACxC,0BAA0B;QAC1B,wCAAwC;QAExC,IAAIpD,iBAAiBuC,KAAK,EAAEgB,YAAYd,QAAQ;YAC9C,KAAK,MAAMC,QAAQ1C,iBAAiBuC,KAAK,CAACgB,UAAU,CAAE;gBACpDH,kBACE,AAAC,MAAMV,KAAK;oBACV5C,YAAYD,KAAKC,UAAU,EAAEC;oBAC7B4C,SAAS9C,KAAKO,GAAG,CAACuC,OAAO;oBACzBvC,KAAKP,KAAKO,GAAG;oBACbyB;oBACAb,MAAMoC;gBACR,MAAOA;YACX;QACF;QAEA,MAAMI,WAAW,MAAMnD,QAAQoD,QAAQ,CAAC;YACtCV,IAAI/B,KAAK+B,EAAE;YACXjD,YAAYE,iBAAiBgC,IAAI;YACjC9B;YACAC;YACAC;YACAkB,OAAO;QACT;QAEA,IAAIL,cAAc;YAChB,MAAM9B,kBAAkBiB;QAC1B;QAEA,IAAIoD,UAAU;YACZA,SAAS1D,UAAU,GAAGE,iBAAiBgC,IAAI;YAC3CwB,SAASE,SAAS,GAAG;QACvB;QAEA,IAAIC,SAA2D;YAC7D9B;YACAb,MAAMwC;QACR;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCG,SAAS,MAAM7E,oBAAoB;YACjCe;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BmB,WAAW;YACXf;YACAwD;QACF;QAEA,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,IAAI7C,KAAK;YACP,MAAMtB,cAAc;gBAClBO;gBACAK;gBACAD;gBACAW;gBACAC;YACF;QACF;QACA,MAAM3B,gBAAgBe;QACtB,MAAMwD;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/operations/resetPassword.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { Collection, DataFromCollectionSlug } from '../../collections/config/types.js'\nimport type { AuthCollectionSlug, User } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utilities/buildAfterOperation.js'\nimport { buildBeforeOperation } from '../../collections/operations/utilities/buildBeforeOperation.js'\nimport { APIError, Forbidden } from '../../errors/index.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.js'\nimport { addSessionToUser, revokeSession } from '../sessions.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { generatePasswordSaltHash } from '../strategies/local/generatePasswordSaltHash.js'\n\nexport type Result = {\n token?: string\n user: Record<string, unknown>\n}\n\nexport type Arguments = {\n collection: Collection\n data: {\n password: string\n token: string\n }\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const resetPasswordOperation = async <TSlug extends AuthCollectionSlug>(\n args: Arguments,\n): Promise<Result> => {\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req: {\n payload: { secret },\n payload,\n },\n req,\n } = args\n\n if (\n !Object.prototype.hasOwnProperty.call(data, 'token') ||\n !Object.prototype.hasOwnProperty.call(data, 'password')\n ) {\n throw new APIError('Missing required data.', httpStatus.BAD_REQUEST)\n }\n\n if (collectionConfig.auth.disableLocalStrategy) {\n throw new Forbidden(req.t)\n }\n\n let sid: string | undefined\n let user: null | User = null\n\n try {\n const shouldCommit = await initTransaction(req)\n\n args = await buildBeforeOperation({\n args,\n collection: args.collection.config,\n operation: 'resetPassword',\n overrideAccess,\n })\n\n // /////////////////////////////////////\n // Reset Password\n // /////////////////////////////////////\n\n const where = appendNonTrashedFilter({\n enableTrash: Boolean(collectionConfig.trash),\n trash: false,\n where: {\n resetPasswordExpiration: { greater_than: new Date().toISOString() },\n resetPasswordToken: { equals: data.token },\n },\n })\n\n user = await payload.db.findOne<User>({\n collection: collectionConfig.slug,\n req,\n where,\n })\n\n if (!user) {\n throw new APIError('Token is either invalid or has expired.', httpStatus.FORBIDDEN)\n }\n\n // TODO: replace this method\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password: data.password,\n req,\n })\n\n user.salt = salt\n user.hash = hash\n\n user.resetPasswordExpiration = new Date().toISOString()\n\n if (collectionConfig.auth.verify) {\n user._verified = Boolean(user._verified)\n }\n\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n await hook({\n collection: args.collection?.config,\n context: req.context,\n data: user,\n operation: 'update',\n req,\n })\n }\n }\n\n // /////////////////////////////////////\n // Update new password\n // /////////////////////////////////////\n\n // Ensure updatedAt date is always updated\n user.updatedAt = new Date().toISOString()\n\n const doc = await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n await authenticateLocalStrategy({ doc, password: data.password })\n\n const fieldsToSignArgs: Parameters<typeof getFieldsToSign>[0] = {\n collectionConfig,\n email: user.email!,\n user,\n }\n\n const session = await addSessionToUser({\n collectionConfig,\n payload,\n req,\n user,\n })\n sid = session.sid\n\n if (sid) {\n fieldsToSignArgs.sid = sid\n }\n\n const fieldsToSign = getFieldsToSign(fieldsToSignArgs)\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n let userBeforeLogin = user\n\n if (collectionConfig.hooks?.beforeLogin?.length) {\n for (const hook of collectionConfig.hooks.beforeLogin) {\n userBeforeLogin =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user: userBeforeLogin,\n })) || userBeforeLogin\n }\n }\n\n const { token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = userBeforeLogin\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterLogin?.length) {\n for (const hook of collectionConfig.hooks.afterLogin) {\n userBeforeLogin =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n token,\n user: userBeforeLogin,\n })) || userBeforeLogin\n }\n }\n\n const fullUser = await payload.findByID({\n id: user.id,\n collection: collectionConfig.slug,\n depth,\n overrideAccess,\n req,\n trash: false,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n if (fullUser) {\n fullUser.collection = collectionConfig.slug\n fullUser._strategy = 'local-jwt'\n }\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n token,\n user: fullUser,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'resetPassword',\n overrideAccess,\n result,\n })\n\n return result\n } catch (error: unknown) {\n if (sid) {\n await revokeSession({\n collectionConfig,\n payload,\n req,\n sid,\n user,\n })\n }\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["status","httpStatus","buildAfterOperation","buildBeforeOperation","APIError","Forbidden","appendNonTrashedFilter","commitTransaction","initTransaction","killTransaction","getFieldsToSign","jwtSign","addSessionToUser","revokeSession","authenticateLocalStrategy","generatePasswordSaltHash","resetPasswordOperation","args","collection","config","collectionConfig","data","depth","overrideAccess","req","payload","secret","Object","prototype","hasOwnProperty","call","BAD_REQUEST","auth","disableLocalStrategy","t","sid","user","shouldCommit","operation","where","enableTrash","Boolean","trash","resetPasswordExpiration","greater_than","Date","toISOString","resetPasswordToken","equals","token","db","findOne","slug","FORBIDDEN","hash","salt","password","verify","_verified","hooks","beforeValidate","length","hook","context","updatedAt","doc","updateOne","id","fieldsToSignArgs","email","session","fieldsToSign","userBeforeLogin","beforeLogin","tokenExpiration","afterLogin","fullUser","findByID","_strategy","result","error"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAMlD,SAASC,mBAAmB,QAAQ,gEAA+D;AACnG,SAAS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,WAAW,MAAMnD,QAAQoD,QAAQ,CAAC;YACtCV,IAAI/B,KAAK+B,EAAE;YACXjD,YAAYE,iBAAiBgC,IAAI;YACjC9B;YACAC;YACAC;YACAkB,OAAO;QACT;QAEA,IAAIL,cAAc;YAChB,MAAM9B,kBAAkBiB;QAC1B;QAEA,IAAIoD,UAAU;YACZA,SAAS1D,UAAU,GAAGE,iBAAiBgC,IAAI;YAC3CwB,SAASE,SAAS,GAAG;QACvB;QAEA,IAAIC,SAA2D;YAC7D9B;YACAb,MAAMwC;QACR;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCG,SAAS,MAAM7E,oBAAoB;YACjCe;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BmB,WAAW;YACXf;YACAwD;QACF;QAEA,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,IAAI7C,KAAK;YACP,MAAMtB,cAAc;gBAClBO;gBACAK;gBACAD;gBACAW;gBACAC;YACF;QACF;QACA,MAAM3B,gBAAgBe;QACtB,MAAMwD;IACR;AACF,EAAC"}
@@ -1,7 +1,7 @@
1
1
  import type { Collection } from '../collections/config/types.js';
2
2
  import type { SanitizedConfig } from '../config/types.js';
3
3
  import type { InitializedEmailAdapter } from '../email/types.js';
4
- import type { TypedUser } from '../index.js';
4
+ import type { User } from '../index.js';
5
5
  import type { PayloadRequest } from '../types/index.js';
6
6
  type Args = {
7
7
  collection: Collection;
@@ -10,7 +10,7 @@ type Args = {
10
10
  email: InitializedEmailAdapter;
11
11
  req: PayloadRequest;
12
12
  token: string;
13
- user: TypedUser;
13
+ user: User;
14
14
  };
15
15
  export declare function sendVerificationEmail(args: Args): Promise<void>;
16
16
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"sendVerificationEmail.d.ts","sourceRoot":"","sources":["../../src/auth/sendVerificationEmail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,KAAK,E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,CAAC,CAuDrE"}
@@ -3,7 +3,7 @@ import { getRequestOrigin } from '../utilities/getRequestOrigin.js';
3
3
  export async function sendVerificationEmail(args) {
4
4
  // Verify token from e-mail
5
5
  const { collection: { config: collectionConfig }, config, disableEmail, email, req, token, user } = args;
6
- if (!disableEmail) {
6
+ if (!disableEmail && user.email) {
7
7
  const serverURL = getRequestOrigin({
8
8
  config,
9
9
  req
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/auth/sendVerificationEmail.ts"],"sourcesContent":["import type { Collection } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { InitializedEmailAdapter } from '../email/types.js'\nimport type { TypedUser } from '../index.js'\nimport type { PayloadRequest } from '../types/index.js'\nimport type { VerifyConfig } from './types.js'\n\nimport { formatAdminURL } from '../utilities/formatAdminURL.js'\nimport { getRequestOrigin } from '../utilities/getRequestOrigin.js'\n\ntype Args = {\n collection: Collection\n config: SanitizedConfig\n disableEmail: boolean\n email: InitializedEmailAdapter\n req: PayloadRequest\n token: string\n user: TypedUser\n}\n\nexport async function sendVerificationEmail(args: Args): Promise<void> {\n // Verify token from e-mail\n const {\n collection: { config: collectionConfig },\n config,\n disableEmail,\n email,\n req,\n token,\n user,\n } = args\n\n if (!disableEmail) {\n const serverURL = getRequestOrigin({ config, req })\n\n const verificationURL = formatAdminURL({\n adminRoute: config.routes.admin,\n path: `/${collectionConfig.slug}/verify/${token}`,\n serverURL,\n })\n\n let html = `${req.t('authentication:newAccountCreated', {\n serverURL: config.serverURL,\n verificationURL,\n })}`\n\n const verify = collectionConfig.auth.verify as VerifyConfig\n\n // Allow config to override email content\n if (typeof verify.generateEmailHTML === 'function') {\n html = await verify.generateEmailHTML({\n req,\n token,\n user,\n })\n }\n\n let subject = req.t('authentication:verifyYourEmail')\n\n // Allow config to override email subject\n if (typeof verify.generateEmailSubject === 'function') {\n subject = await verify.generateEmailSubject({\n req,\n token,\n user,\n })\n }\n\n await email.sendEmail({\n from: `\"${email.defaultFromName}\" <${email.defaultFromAddress}>`,\n html,\n subject,\n to: user.email,\n })\n }\n}\n"],"names":["formatAdminURL","getRequestOrigin","sendVerificationEmail","args","collection","config","collectionConfig","disableEmail","email","req","token","user","serverURL","verificationURL","adminRoute","routes","admin","path","slug","html","t","verify","auth","generateEmailHTML","subject","generateEmailSubject","sendEmail","from","defaultFromName","defaultFromAddress","to"],"mappings":"AAOA,SAASA,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,gBAAgB,QAAQ,mCAAkC;AAYnE,OAAO,eAAeC,sBAAsBC,IAAU;IACpD,2BAA2B;IAC3B,MAAM,EACJC,YAAY,EAAEC,QAAQC,gBAAgB,EAAE,EACxCD,MAAM,EACNE,YAAY,EACZC,KAAK,EACLC,GAAG,EACHC,KAAK,EACLC,IAAI,EACL,GAAGR;IAEJ,IAAI,CAACI,cAAc;QACjB,MAAMK,YAAYX,iBAAiB;YAAEI;YAAQI;QAAI;QAEjD,MAAMI,kBAAkBb,eAAe;YACrCc,YAAYT,OAAOU,MAAM,CAACC,KAAK;YAC/BC,MAAM,CAAC,CAAC,EAAEX,iBAAiBY,IAAI,CAAC,QAAQ,EAAER,OAAO;YACjDE;QACF;QAEA,IAAIO,OAAO,GAAGV,IAAIW,CAAC,CAAC,oCAAoC;YACtDR,WAAWP,OAAOO,SAAS;YAC3BC;QACF,IAAI;QAEJ,MAAMQ,SAASf,iBAAiBgB,IAAI,CAACD,MAAM;QAE3C,yCAAyC;QACzC,IAAI,OAAOA,OAAOE,iBAAiB,KAAK,YAAY;YAClDJ,OAAO,MAAME,OAAOE,iBAAiB,CAAC;gBACpCd;gBACAC;gBACAC;YACF;QACF;QAEA,IAAIa,UAAUf,IAAIW,CAAC,CAAC;QAEpB,yCAAyC;QACzC,IAAI,OAAOC,OAAOI,oBAAoB,KAAK,YAAY;YACrDD,UAAU,MAAMH,OAAOI,oBAAoB,CAAC;gBAC1ChB;gBACAC;gBACAC;YACF;QACF;QAEA,MAAMH,MAAMkB,SAAS,CAAC;YACpBC,MAAM,CAAC,CAAC,EAAEnB,MAAMoB,eAAe,CAAC,GAAG,EAAEpB,MAAMqB,kBAAkB,CAAC,CAAC,CAAC;YAChEV;YACAK;YACAM,IAAInB,KAAKH,KAAK;QAChB;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/auth/sendVerificationEmail.ts"],"sourcesContent":["import type { Collection } from '../collections/config/types.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type { InitializedEmailAdapter } from '../email/types.js'\nimport type { User } from '../index.js'\nimport type { PayloadRequest } from '../types/index.js'\nimport type { VerifyConfig } from './types.js'\n\nimport { formatAdminURL } from '../utilities/formatAdminURL.js'\nimport { getRequestOrigin } from '../utilities/getRequestOrigin.js'\n\ntype Args = {\n collection: Collection\n config: SanitizedConfig\n disableEmail: boolean\n email: InitializedEmailAdapter\n req: PayloadRequest\n token: string\n user: User\n}\n\nexport async function sendVerificationEmail(args: Args): Promise<void> {\n // Verify token from e-mail\n const {\n collection: { config: collectionConfig },\n config,\n disableEmail,\n email,\n req,\n token,\n user,\n } = args\n\n if (!disableEmail && user.email) {\n const serverURL = getRequestOrigin({ config, req })\n\n const verificationURL = formatAdminURL({\n adminRoute: config.routes.admin,\n path: `/${collectionConfig.slug}/verify/${token}`,\n serverURL,\n })\n\n let html = `${req.t('authentication:newAccountCreated', {\n serverURL: config.serverURL,\n verificationURL,\n })}`\n\n const verify = collectionConfig.auth.verify as VerifyConfig\n\n // Allow config to override email content\n if (typeof verify.generateEmailHTML === 'function') {\n html = await verify.generateEmailHTML({\n req,\n token,\n user,\n })\n }\n\n let subject = req.t('authentication:verifyYourEmail')\n\n // Allow config to override email subject\n if (typeof verify.generateEmailSubject === 'function') {\n subject = await verify.generateEmailSubject({\n req,\n token,\n user,\n })\n }\n\n await email.sendEmail({\n from: `\"${email.defaultFromName}\" <${email.defaultFromAddress}>`,\n html,\n subject,\n to: user.email,\n })\n }\n}\n"],"names":["formatAdminURL","getRequestOrigin","sendVerificationEmail","args","collection","config","collectionConfig","disableEmail","email","req","token","user","serverURL","verificationURL","adminRoute","routes","admin","path","slug","html","t","verify","auth","generateEmailHTML","subject","generateEmailSubject","sendEmail","from","defaultFromName","defaultFromAddress","to"],"mappings":"AAOA,SAASA,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,gBAAgB,QAAQ,mCAAkC;AAYnE,OAAO,eAAeC,sBAAsBC,IAAU;IACpD,2BAA2B;IAC3B,MAAM,EACJC,YAAY,EAAEC,QAAQC,gBAAgB,EAAE,EACxCD,MAAM,EACNE,YAAY,EACZC,KAAK,EACLC,GAAG,EACHC,KAAK,EACLC,IAAI,EACL,GAAGR;IAEJ,IAAI,CAACI,gBAAgBI,KAAKH,KAAK,EAAE;QAC/B,MAAMI,YAAYX,iBAAiB;YAAEI;YAAQI;QAAI;QAEjD,MAAMI,kBAAkBb,eAAe;YACrCc,YAAYT,OAAOU,MAAM,CAACC,KAAK;YAC/BC,MAAM,CAAC,CAAC,EAAEX,iBAAiBY,IAAI,CAAC,QAAQ,EAAER,OAAO;YACjDE;QACF;QAEA,IAAIO,OAAO,GAAGV,IAAIW,CAAC,CAAC,oCAAoC;YACtDR,WAAWP,OAAOO,SAAS;YAC3BC;QACF,IAAI;QAEJ,MAAMQ,SAASf,iBAAiBgB,IAAI,CAACD,MAAM;QAE3C,yCAAyC;QACzC,IAAI,OAAOA,OAAOE,iBAAiB,KAAK,YAAY;YAClDJ,OAAO,MAAME,OAAOE,iBAAiB,CAAC;gBACpCd;gBACAC;gBACAC;YACF;QACF;QAEA,IAAIa,UAAUf,IAAIW,CAAC,CAAC;QAEpB,yCAAyC;QACzC,IAAI,OAAOC,OAAOI,oBAAoB,KAAK,YAAY;YACrDD,UAAU,MAAMH,OAAOI,oBAAoB,CAAC;gBAC1ChB;gBACAC;gBACAC;YACF;QACF;QAEA,MAAMH,MAAMkB,SAAS,CAAC;YACpBC,MAAM,CAAC,CAAC,EAAEnB,MAAMoB,eAAe,CAAC,GAAG,EAAEpB,MAAMqB,kBAAkB,CAAC,CAAC,CAAC;YAChEV;YACAK;YACAM,IAAInB,KAAKH,KAAK;QAChB;IACF;AACF"}
@@ -1,7 +1,6 @@
1
- import type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js';
2
- import type { TypedUser } from '../index.js';
1
+ import type { SanitizedCollectionConfig } from '../collections/config/types.js';
2
+ import type { AuthenticatedUser, User, UserSession } from '../index.js';
3
3
  import type { Payload, PayloadRequest } from '../types/index.js';
4
- import type { UntypedUser, UserSession } from './types.js';
5
4
  /**
6
5
  * Removes expired sessions from an array of sessions
7
6
  */
@@ -14,7 +13,7 @@ export declare const addSessionToUser: ({ collectionConfig, payload, req, user,
14
13
  collectionConfig: SanitizedCollectionConfig;
15
14
  payload: Payload;
16
15
  req: PayloadRequest;
17
- user: TypedUser;
16
+ user: AuthenticatedUser;
18
17
  }) => Promise<{
19
18
  sid?: string;
20
19
  }>;
@@ -23,6 +22,6 @@ export declare const revokeSession: ({ collectionConfig, payload, req, sid, user
23
22
  payload: Payload;
24
23
  req: PayloadRequest;
25
24
  sid: string;
26
- user: null | (TypeWithID & UntypedUser);
25
+ user: null | User;
27
26
  }) => Promise<void>;
28
27
  //# sourceMappingURL=sessions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../src/auth/sessions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAC3F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE1D;;GAEG;AACH,eAAO,MAAM,qBAAqB,aAAc,WAAW,EAAE,kBAO5D,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,8CAK1B;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EAAE,MAAM,CAAA;IACX,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;CAClB,KAAG,OAAO,CAAC,IAAI,CAWf,CAAA"}
@@ -32,12 +32,14 @@ import { v4 as uuid } from 'uuid';
32
32
  user.sessions = removeExpiredSessions(user.sessions);
33
33
  user.sessions.push(session);
34
34
  }
35
- // Prevent updatedAt from being updated when only adding a session
36
- user.updatedAt = null;
37
35
  await payload.db.updateOne({
38
36
  id: user.id,
39
37
  collection: collectionConfig.slug,
40
- data: user,
38
+ data: {
39
+ ...user,
40
+ // Prevent updatedAt from being updated when only adding a session
41
+ updatedAt: null
42
+ },
41
43
  req,
42
44
  returning: false
43
45
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/auth/sessions.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid'\n\nimport type { SanitizedCollectionConfig, TypeWithID } from '../collections/config/types.js'\nimport type { TypedUser } from '../index.js'\nimport type { Payload, PayloadRequest } from '../types/index.js'\nimport type { UntypedUser, UserSession } from './types.js'\n\n/**\n * Removes expired sessions from an array of sessions\n */\nexport const removeExpiredSessions = (sessions: UserSession[]) => {\n const now = new Date()\n\n return sessions.filter(({ expiresAt }) => {\n const expiry = expiresAt instanceof Date ? expiresAt : new Date(expiresAt)\n return expiry > now\n })\n}\n\n/**\n * Adds a session to the user and removes expired sessions\n * @returns The session ID (sid) if sessions are used\n */\nexport const addSessionToUser = async ({\n collectionConfig,\n payload,\n req,\n user,\n}: {\n collectionConfig: SanitizedCollectionConfig\n payload: Payload\n req: PayloadRequest\n user: TypedUser\n}): Promise<{ sid?: string }> => {\n let sid: string | undefined\n if (collectionConfig.auth.useSessions) {\n // Add session to user\n sid = uuid()\n const now = new Date()\n const tokenExpInMs = collectionConfig.auth.tokenExpiration * 1000\n const expiresAt = new Date(now.getTime() + tokenExpInMs)\n\n const session = { id: sid, createdAt: now, expiresAt }\n\n if (!user.sessions?.length) {\n user.sessions = [session]\n } else {\n user.sessions = removeExpiredSessions(user.sessions)\n user.sessions.push(session)\n }\n\n // Prevent updatedAt from being updated when only adding a session\n user.updatedAt = null\n\n await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n returning: false,\n })\n\n user.collection = collectionConfig.slug\n user._strategy = 'local-jwt'\n }\n\n return {\n sid,\n }\n}\n\nexport const revokeSession = async ({\n collectionConfig,\n payload,\n req,\n sid,\n user,\n}: {\n collectionConfig: SanitizedCollectionConfig\n payload: Payload\n req: PayloadRequest\n sid: string\n user: null | (TypeWithID & UntypedUser)\n}): Promise<void> => {\n if (collectionConfig.auth.useSessions && user && user.sessions?.length) {\n user.sessions = user.sessions.filter((session) => session.id !== sid)\n await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n returning: false,\n })\n }\n}\n"],"names":["v4","uuid","removeExpiredSessions","sessions","now","Date","filter","expiresAt","expiry","addSessionToUser","collectionConfig","payload","req","user","sid","auth","useSessions","tokenExpInMs","tokenExpiration","getTime","session","id","createdAt","length","push","updatedAt","db","updateOne","collection","slug","data","returning","_strategy","revokeSession"],"mappings":"AAAA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAOjC;;CAEC,GACD,OAAO,MAAMC,wBAAwB,CAACC;IACpC,MAAMC,MAAM,IAAIC;IAEhB,OAAOF,SAASG,MAAM,CAAC,CAAC,EAAEC,SAAS,EAAE;QACnC,MAAMC,SAASD,qBAAqBF,OAAOE,YAAY,IAAIF,KAAKE;QAChE,OAAOC,SAASJ;IAClB;AACF,EAAC;AAED;;;CAGC,GACD,OAAO,MAAMK,mBAAmB,OAAO,EACrCC,gBAAgB,EAChBC,OAAO,EACPC,GAAG,EACHC,IAAI,EAML;IACC,IAAIC;IACJ,IAAIJ,iBAAiBK,IAAI,CAACC,WAAW,EAAE;QACrC,sBAAsB;QACtBF,MAAMb;QACN,MAAMG,MAAM,IAAIC;QAChB,MAAMY,eAAeP,iBAAiBK,IAAI,CAACG,eAAe,GAAG;QAC7D,MAAMX,YAAY,IAAIF,KAAKD,IAAIe,OAAO,KAAKF;QAE3C,MAAMG,UAAU;YAAEC,IAAIP;YAAKQ,WAAWlB;YAAKG;QAAU;QAErD,IAAI,CAACM,KAAKV,QAAQ,EAAEoB,QAAQ;YAC1BV,KAAKV,QAAQ,GAAG;gBAACiB;aAAQ;QAC3B,OAAO;YACLP,KAAKV,QAAQ,GAAGD,sBAAsBW,KAAKV,QAAQ;YACnDU,KAAKV,QAAQ,CAACqB,IAAI,CAACJ;QACrB;QAEA,kEAAkE;QAClEP,KAAKY,SAAS,GAAG;QAEjB,MAAMd,QAAQe,EAAE,CAACC,SAAS,CAAC;YACzBN,IAAIR,KAAKQ,EAAE;YACXO,YAAYlB,iBAAiBmB,IAAI;YACjCC,MAAMjB;YACND;YACAmB,WAAW;QACb;QAEAlB,KAAKe,UAAU,GAAGlB,iBAAiBmB,IAAI;QACvChB,KAAKmB,SAAS,GAAG;IACnB;IAEA,OAAO;QACLlB;IACF;AACF,EAAC;AAED,OAAO,MAAMmB,gBAAgB,OAAO,EAClCvB,gBAAgB,EAChBC,OAAO,EACPC,GAAG,EACHE,GAAG,EACHD,IAAI,EAOL;IACC,IAAIH,iBAAiBK,IAAI,CAACC,WAAW,IAAIH,QAAQA,KAAKV,QAAQ,EAAEoB,QAAQ;QACtEV,KAAKV,QAAQ,GAAGU,KAAKV,QAAQ,CAACG,MAAM,CAAC,CAACc,UAAYA,QAAQC,EAAE,KAAKP;QACjE,MAAMH,QAAQe,EAAE,CAACC,SAAS,CAAC;YACzBN,IAAIR,KAAKQ,EAAE;YACXO,YAAYlB,iBAAiBmB,IAAI;YACjCC,MAAMjB;YACND;YACAmB,WAAW;QACb;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/auth/sessions.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid'\n\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { AuthenticatedUser, User, UserSession } from '../index.js'\nimport type { Payload, PayloadRequest } from '../types/index.js'\n\n/**\n * Removes expired sessions from an array of sessions\n */\nexport const removeExpiredSessions = (sessions: UserSession[]): UserSession[] => {\n const now = new Date()\n\n return sessions.filter(({ expiresAt }) => {\n const expiry = expiresAt instanceof Date ? expiresAt : new Date(expiresAt)\n return expiry > now\n })\n}\n\n/**\n * Adds a session to the user and removes expired sessions\n * @returns The session ID (sid) if sessions are used\n */\nexport const addSessionToUser = async ({\n collectionConfig,\n payload,\n req,\n user,\n}: {\n collectionConfig: SanitizedCollectionConfig\n payload: Payload\n req: PayloadRequest\n user: AuthenticatedUser\n}): Promise<{ sid?: string }> => {\n let sid: string | undefined\n if (collectionConfig.auth.useSessions) {\n // Add session to user\n sid = uuid()\n const now = new Date()\n const tokenExpInMs = collectionConfig.auth.tokenExpiration * 1000\n const expiresAt = new Date(now.getTime() + tokenExpInMs)\n\n const session = { id: sid, createdAt: now, expiresAt }\n\n if (!user.sessions?.length) {\n user.sessions = [session]\n } else {\n user.sessions = removeExpiredSessions(user.sessions)\n user.sessions.push(session)\n }\n\n await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: {\n ...user,\n // Prevent updatedAt from being updated when only adding a session\n updatedAt: null,\n },\n req,\n returning: false,\n })\n\n user.collection = collectionConfig.slug\n user._strategy = 'local-jwt'\n }\n\n return {\n sid,\n }\n}\n\nexport const revokeSession = async ({\n collectionConfig,\n payload,\n req,\n sid,\n user,\n}: {\n collectionConfig: SanitizedCollectionConfig\n payload: Payload\n req: PayloadRequest\n sid: string\n user: null | User\n}): Promise<void> => {\n if (collectionConfig.auth.useSessions && user && user.sessions?.length) {\n user.sessions = user.sessions.filter((session) => session.id !== sid)\n await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n returning: false,\n })\n }\n}\n"],"names":["v4","uuid","removeExpiredSessions","sessions","now","Date","filter","expiresAt","expiry","addSessionToUser","collectionConfig","payload","req","user","sid","auth","useSessions","tokenExpInMs","tokenExpiration","getTime","session","id","createdAt","length","push","db","updateOne","collection","slug","data","updatedAt","returning","_strategy","revokeSession"],"mappings":"AAAA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAMjC;;CAEC,GACD,OAAO,MAAMC,wBAAwB,CAACC;IACpC,MAAMC,MAAM,IAAIC;IAEhB,OAAOF,SAASG,MAAM,CAAC,CAAC,EAAEC,SAAS,EAAE;QACnC,MAAMC,SAASD,qBAAqBF,OAAOE,YAAY,IAAIF,KAAKE;QAChE,OAAOC,SAASJ;IAClB;AACF,EAAC;AAED;;;CAGC,GACD,OAAO,MAAMK,mBAAmB,OAAO,EACrCC,gBAAgB,EAChBC,OAAO,EACPC,GAAG,EACHC,IAAI,EAML;IACC,IAAIC;IACJ,IAAIJ,iBAAiBK,IAAI,CAACC,WAAW,EAAE;QACrC,sBAAsB;QACtBF,MAAMb;QACN,MAAMG,MAAM,IAAIC;QAChB,MAAMY,eAAeP,iBAAiBK,IAAI,CAACG,eAAe,GAAG;QAC7D,MAAMX,YAAY,IAAIF,KAAKD,IAAIe,OAAO,KAAKF;QAE3C,MAAMG,UAAU;YAAEC,IAAIP;YAAKQ,WAAWlB;YAAKG;QAAU;QAErD,IAAI,CAACM,KAAKV,QAAQ,EAAEoB,QAAQ;YAC1BV,KAAKV,QAAQ,GAAG;gBAACiB;aAAQ;QAC3B,OAAO;YACLP,KAAKV,QAAQ,GAAGD,sBAAsBW,KAAKV,QAAQ;YACnDU,KAAKV,QAAQ,CAACqB,IAAI,CAACJ;QACrB;QAEA,MAAMT,QAAQc,EAAE,CAACC,SAAS,CAAC;YACzBL,IAAIR,KAAKQ,EAAE;YACXM,YAAYjB,iBAAiBkB,IAAI;YACjCC,MAAM;gBACJ,GAAGhB,IAAI;gBACP,kEAAkE;gBAClEiB,WAAW;YACb;YACAlB;YACAmB,WAAW;QACb;QAEAlB,KAAKc,UAAU,GAAGjB,iBAAiBkB,IAAI;QACvCf,KAAKmB,SAAS,GAAG;IACnB;IAEA,OAAO;QACLlB;IACF;AACF,EAAC;AAED,OAAO,MAAMmB,gBAAgB,OAAO,EAClCvB,gBAAgB,EAChBC,OAAO,EACPC,GAAG,EACHE,GAAG,EACHD,IAAI,EAOL;IACC,IAAIH,iBAAiBK,IAAI,CAACC,WAAW,IAAIH,QAAQA,KAAKV,QAAQ,EAAEoB,QAAQ;QACtEV,KAAKV,QAAQ,GAAGU,KAAKV,QAAQ,CAACG,MAAM,CAAC,CAACc,UAAYA,QAAQC,EAAE,KAAKP;QACjE,MAAMH,QAAQc,EAAE,CAACC,SAAS,CAAC;YACzBL,IAAIR,KAAKQ,EAAE;YACXM,YAAYjB,iBAAiBkB,IAAI;YACjCC,MAAMhB;YACND;YACAmB,WAAW;QACb;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"apiKey.d.ts","sourceRoot":"","sources":["../../../src/auth/strategies/apiKey.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAGlF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEvD,eAAO,MAAM,oBAAoB,qBACZ,yBAAyB,KAAG,oBAqE9C,CAAA"}
1
+ {"version":3,"file":"apiKey.d.ts","sourceRoot":"","sources":["../../../src/auth/strategies/apiKey.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAGlF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEvD,eAAO,MAAM,oBAAoB,qBACZ,yBAAyB,KAAG,oBAuD9C,CAAA"}
@@ -3,28 +3,15 @@ export const APIKeyAuthentication = (collectionConfig)=>async ({ headers, isGrap
3
3
  const authHeader = headers.get('Authorization');
4
4
  if (authHeader?.startsWith(`${collectionConfig.slug} API-Key `)) {
5
5
  const apiKey = authHeader.replace(`${collectionConfig.slug} API-Key `, '');
6
- // TODO: V4 remove extra algorithm check
7
- // api keys saved prior to v3.46.0 will have sha1
8
- const sha1APIKeyIndex = crypto.createHmac('sha1', payload.secret).update(apiKey).digest('hex');
9
6
  const sha256APIKeyIndex = crypto.createHmac('sha256', payload.secret).update(apiKey).digest('hex');
10
- const apiKeyConstraints = [
11
- {
12
- apiKeyIndex: {
13
- equals: sha1APIKeyIndex
14
- }
15
- },
16
- {
17
- apiKeyIndex: {
18
- equals: sha256APIKeyIndex
19
- }
20
- }
21
- ];
22
7
  try {
23
8
  const where = {};
24
9
  if (collectionConfig.auth?.verify) {
25
10
  where.and = [
26
11
  {
27
- or: apiKeyConstraints
12
+ apiKeyIndex: {
13
+ equals: sha256APIKeyIndex
14
+ }
28
15
  },
29
16
  {
30
17
  _verified: {
@@ -33,7 +20,9 @@ export const APIKeyAuthentication = (collectionConfig)=>async ({ headers, isGrap
33
20
  }
34
21
  ];
35
22
  } else {
36
- where.or = apiKeyConstraints;
23
+ where.apiKeyIndex = {
24
+ equals: sha256APIKeyIndex
25
+ };
37
26
  }
38
27
  const userQuery = await payload.find({
39
28
  collection: collectionConfig.slug,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/strategies/apiKey.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { TypedUser } from '../../index.js'\nimport type { Where } from '../../types/index.js'\nimport type { AuthStrategyFunction } from '../index.js'\n\nexport const APIKeyAuthentication =\n (collectionConfig: SanitizedCollectionConfig): AuthStrategyFunction =>\n async ({ headers, isGraphQL = false, payload }) => {\n const authHeader = headers.get('Authorization')\n\n if (authHeader?.startsWith(`${collectionConfig.slug} API-Key `)) {\n const apiKey = authHeader.replace(`${collectionConfig.slug} API-Key `, '')\n\n // TODO: V4 remove extra algorithm check\n // api keys saved prior to v3.46.0 will have sha1\n const sha1APIKeyIndex = crypto.createHmac('sha1', payload.secret).update(apiKey).digest('hex')\n const sha256APIKeyIndex = crypto\n .createHmac('sha256', payload.secret)\n .update(apiKey)\n .digest('hex')\n\n const apiKeyConstraints = [\n {\n apiKeyIndex: {\n equals: sha1APIKeyIndex,\n },\n },\n {\n apiKeyIndex: {\n equals: sha256APIKeyIndex,\n },\n },\n ]\n\n try {\n const where: Where = {}\n if (collectionConfig.auth?.verify) {\n where.and = [\n {\n or: apiKeyConstraints,\n },\n {\n _verified: {\n not_equals: false,\n },\n },\n ]\n } else {\n where.or = apiKeyConstraints\n }\n\n const userQuery = await payload.find({\n collection: collectionConfig.slug,\n depth: isGraphQL ? 0 : collectionConfig.auth.depth,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n where,\n })\n\n if (userQuery.docs && userQuery.docs.length > 0) {\n const user = userQuery.docs[0]\n user!.collection = collectionConfig.slug\n user!._strategy = 'api-key'\n\n return {\n user: user as TypedUser,\n }\n }\n } catch (ignore) {\n return { user: null }\n }\n }\n\n return { user: null }\n }\n"],"names":["crypto","APIKeyAuthentication","collectionConfig","headers","isGraphQL","payload","authHeader","get","startsWith","slug","apiKey","replace","sha1APIKeyIndex","createHmac","secret","update","digest","sha256APIKeyIndex","apiKeyConstraints","apiKeyIndex","equals","where","auth","verify","and","or","_verified","not_equals","userQuery","find","collection","depth","limit","overrideAccess","pagination","docs","length","user","_strategy","ignore"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAO3B,OAAO,MAAMC,uBACX,CAACC,mBACD,OAAO,EAAEC,OAAO,EAAEC,YAAY,KAAK,EAAEC,OAAO,EAAE;QAC5C,MAAMC,aAAaH,QAAQI,GAAG,CAAC;QAE/B,IAAID,YAAYE,WAAW,GAAGN,iBAAiBO,IAAI,CAAC,SAAS,CAAC,GAAG;YAC/D,MAAMC,SAASJ,WAAWK,OAAO,CAAC,GAAGT,iBAAiBO,IAAI,CAAC,SAAS,CAAC,EAAE;YAEvE,wCAAwC;YACxC,iDAAiD;YACjD,MAAMG,kBAAkBZ,OAAOa,UAAU,CAAC,QAAQR,QAAQS,MAAM,EAAEC,MAAM,CAACL,QAAQM,MAAM,CAAC;YACxF,MAAMC,oBAAoBjB,OACvBa,UAAU,CAAC,UAAUR,QAAQS,MAAM,EACnCC,MAAM,CAACL,QACPM,MAAM,CAAC;YAEV,MAAME,oBAAoB;gBACxB;oBACEC,aAAa;wBACXC,QAAQR;oBACV;gBACF;gBACA;oBACEO,aAAa;wBACXC,QAAQH;oBACV;gBACF;aACD;YAED,IAAI;gBACF,MAAMI,QAAe,CAAC;gBACtB,IAAInB,iBAAiBoB,IAAI,EAAEC,QAAQ;oBACjCF,MAAMG,GAAG,GAAG;wBACV;4BACEC,IAAIP;wBACN;wBACA;4BACEQ,WAAW;gCACTC,YAAY;4BACd;wBACF;qBACD;gBACH,OAAO;oBACLN,MAAMI,EAAE,GAAGP;gBACb;gBAEA,MAAMU,YAAY,MAAMvB,QAAQwB,IAAI,CAAC;oBACnCC,YAAY5B,iBAAiBO,IAAI;oBACjCsB,OAAO3B,YAAY,IAAIF,iBAAiBoB,IAAI,CAACS,KAAK;oBAClDC,OAAO;oBACPC,gBAAgB;oBAChBC,YAAY;oBACZb;gBACF;gBAEA,IAAIO,UAAUO,IAAI,IAAIP,UAAUO,IAAI,CAACC,MAAM,GAAG,GAAG;oBAC/C,MAAMC,OAAOT,UAAUO,IAAI,CAAC,EAAE;oBAC9BE,KAAMP,UAAU,GAAG5B,iBAAiBO,IAAI;oBACxC4B,KAAMC,SAAS,GAAG;oBAElB,OAAO;wBACLD,MAAMA;oBACR;gBACF;YACF,EAAE,OAAOE,QAAQ;gBACf,OAAO;oBAAEF,MAAM;gBAAK;YACtB;QACF;QAEA,OAAO;YAAEA,MAAM;QAAK;IACtB,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/strategies/apiKey.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { User } from '../../index.js'\nimport type { Where } from '../../types/index.js'\nimport type { AuthStrategyFunction } from '../index.js'\n\nexport const APIKeyAuthentication =\n (collectionConfig: SanitizedCollectionConfig): AuthStrategyFunction =>\n async ({ headers, isGraphQL = false, payload }) => {\n const authHeader = headers.get('Authorization')\n\n if (authHeader?.startsWith(`${collectionConfig.slug} API-Key `)) {\n const apiKey = authHeader.replace(`${collectionConfig.slug} API-Key `, '')\n\n const sha256APIKeyIndex = crypto\n .createHmac('sha256', payload.secret)\n .update(apiKey)\n .digest('hex')\n\n try {\n const where: Where = {}\n if (collectionConfig.auth?.verify) {\n where.and = [\n {\n apiKeyIndex: {\n equals: sha256APIKeyIndex,\n },\n },\n {\n _verified: {\n not_equals: false,\n },\n },\n ]\n } else {\n where.apiKeyIndex = { equals: sha256APIKeyIndex }\n }\n\n const userQuery = await payload.find({\n collection: collectionConfig.slug,\n depth: isGraphQL ? 0 : collectionConfig.auth.depth,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n where,\n })\n\n if (userQuery.docs && userQuery.docs.length > 0) {\n const user = userQuery.docs[0]\n user!.collection = collectionConfig.slug\n user!._strategy = 'api-key'\n\n return {\n user: user as User,\n }\n }\n } catch (ignore) {\n return { user: null }\n }\n }\n\n return { user: null }\n }\n"],"names":["crypto","APIKeyAuthentication","collectionConfig","headers","isGraphQL","payload","authHeader","get","startsWith","slug","apiKey","replace","sha256APIKeyIndex","createHmac","secret","update","digest","where","auth","verify","and","apiKeyIndex","equals","_verified","not_equals","userQuery","find","collection","depth","limit","overrideAccess","pagination","docs","length","user","_strategy","ignore"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAO3B,OAAO,MAAMC,uBACX,CAACC,mBACD,OAAO,EAAEC,OAAO,EAAEC,YAAY,KAAK,EAAEC,OAAO,EAAE;QAC5C,MAAMC,aAAaH,QAAQI,GAAG,CAAC;QAE/B,IAAID,YAAYE,WAAW,GAAGN,iBAAiBO,IAAI,CAAC,SAAS,CAAC,GAAG;YAC/D,MAAMC,SAASJ,WAAWK,OAAO,CAAC,GAAGT,iBAAiBO,IAAI,CAAC,SAAS,CAAC,EAAE;YAEvE,MAAMG,oBAAoBZ,OACvBa,UAAU,CAAC,UAAUR,QAAQS,MAAM,EACnCC,MAAM,CAACL,QACPM,MAAM,CAAC;YAEV,IAAI;gBACF,MAAMC,QAAe,CAAC;gBACtB,IAAIf,iBAAiBgB,IAAI,EAAEC,QAAQ;oBACjCF,MAAMG,GAAG,GAAG;wBACV;4BACEC,aAAa;gCACXC,QAAQV;4BACV;wBACF;wBACA;4BACEW,WAAW;gCACTC,YAAY;4BACd;wBACF;qBACD;gBACH,OAAO;oBACLP,MAAMI,WAAW,GAAG;wBAAEC,QAAQV;oBAAkB;gBAClD;gBAEA,MAAMa,YAAY,MAAMpB,QAAQqB,IAAI,CAAC;oBACnCC,YAAYzB,iBAAiBO,IAAI;oBACjCmB,OAAOxB,YAAY,IAAIF,iBAAiBgB,IAAI,CAACU,KAAK;oBAClDC,OAAO;oBACPC,gBAAgB;oBAChBC,YAAY;oBACZd;gBACF;gBAEA,IAAIQ,UAAUO,IAAI,IAAIP,UAAUO,IAAI,CAACC,MAAM,GAAG,GAAG;oBAC/C,MAAMC,OAAOT,UAAUO,IAAI,CAAC,EAAE;oBAC9BE,KAAMP,UAAU,GAAGzB,iBAAiBO,IAAI;oBACxCyB,KAAMC,SAAS,GAAG;oBAElB,OAAO;wBACLD,MAAMA;oBACR;gBACF;YACF,EAAE,OAAOE,QAAQ;gBACf,OAAO;oBAAEF,MAAM;gBAAK;YACtB;QACF;QAEA,OAAO;YAAEA,MAAM;QAAK;IACtB,EAAC"}
@@ -1,9 +1,9 @@
1
1
  import type { SanitizedCollectionConfig } from '../../../collections/config/types.js';
2
- import { type Payload, type TypedUser } from '../../../index.js';
2
+ import { type Payload, type User } from '../../../index.js';
3
3
  type Args = {
4
4
  collection: SanitizedCollectionConfig;
5
5
  payload: Payload;
6
- user: TypedUser;
6
+ user: User;
7
7
  };
8
8
  export declare const incrementLoginAttempts: ({ collection, payload, user, }: Args) => Promise<void>;
9
9
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"incrementLoginAttempts.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/incrementLoginAttempts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AAErF,OAAO,EAAmB,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAGjF,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,CAAA;IACrC,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AAID,eAAO,MAAM,sBAAsB,mCAIhC,IAAI,KAAG,OAAO,CAAC,IAAI,CAuIrB,CAAA"}
1
+ {"version":3,"file":"incrementLoginAttempts.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/incrementLoginAttempts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AAErF,OAAO,EAAmB,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAG5E,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,CAAA;IACrC,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAID,eAAO,MAAM,sBAAsB,mCAIhC,IAAI,KAAG,OAAO,CAAC,IAAI,CAuIrB,CAAA"}
@@ -92,7 +92,7 @@ export const incrementLoginAttempts = async ({ collection, payload, user })=>{
92
92
  if (currentUser?.sessions?.length) {
93
93
  // Does not hurt also removing expired sessions
94
94
  currentUser.sessions = currentUser.sessions.filter((session)=>{
95
- const sessionCreatedAt = new Date(session.createdAt);
95
+ const sessionCreatedAt = new Date(session.createdAt ?? 0);
96
96
  const twentySecondsAgo = new Date(currentTime - 20000);
97
97
  // Remove sessions created within the last 20 seconds
98
98
  return sessionCreatedAt <= twentySecondsAgo;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/auth/strategies/local/incrementLoginAttempts.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\n\nimport { type JsonObject, type Payload, type TypedUser } from '../../../index.js'\nimport { isUserLocked } from '../../isUserLocked.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig\n payload: Payload\n user: TypedUser\n}\n\n// Note: this function does not use req in its updates, as we want those to be visible in parallel requests that are on a different\n// transaction. At the same time, we want updates from parallel requests to be visible here.\nexport const incrementLoginAttempts = async ({\n collection,\n payload,\n user,\n}: Args): Promise<void> => {\n const {\n auth: { lockTime, maxLoginAttempts },\n } = collection\n\n const currentTime = Date.now()\n\n let updatedLockUntil: null | string = null\n let updatedLoginAttempts: null | number = null\n\n if (user.lockUntil && !isUserLocked(new Date(user.lockUntil))) {\n // Expired lock, restart count at 1\n const updatedUser = await payload.db.updateOne({\n id: user.id,\n collection: collection.slug,\n data: {\n lockUntil: null,\n loginAttempts: 1,\n },\n select: {\n lockUntil: true,\n loginAttempts: true,\n },\n })\n updatedLockUntil = updatedUser.lockUntil\n updatedLoginAttempts = updatedUser.loginAttempts\n user.lockUntil = updatedLockUntil\n } else {\n const data: JsonObject = {\n loginAttempts: {\n $inc: 1,\n },\n }\n\n const willReachMaxAttempts =\n typeof user.loginAttempts === 'number' && user.loginAttempts + 1 >= maxLoginAttempts\n // Lock the account if at max attempts and not already locked\n if (willReachMaxAttempts) {\n const lockUntil = new Date(currentTime + lockTime).toISOString()\n data.lockUntil = lockUntil\n }\n\n const updatedUser = await payload.db.updateOne({\n id: user.id,\n collection: collection.slug,\n data,\n select: {\n lockUntil: true,\n loginAttempts: true,\n },\n })\n\n updatedLockUntil = updatedUser.lockUntil\n updatedLoginAttempts = updatedUser.loginAttempts\n }\n\n if (updatedLoginAttempts === null) {\n throw new Error('Failed to update login attempts or lockUntil for user')\n }\n\n // Check updated latest lockUntil and loginAttempts in case there were parallel updates\n const reachedMaxAttemptsForCurrentUser =\n typeof updatedLoginAttempts === 'number' && updatedLoginAttempts - 1 >= maxLoginAttempts\n\n const reachedMaxAttemptsForNextUser =\n typeof updatedLoginAttempts === 'number' && updatedLoginAttempts >= maxLoginAttempts\n\n if (reachedMaxAttemptsForCurrentUser) {\n user.lockUntil = updatedLockUntil\n }\n user.loginAttempts = updatedLoginAttempts - 1 // -1, as the updated increment is applied for the *next* login attempt, not the current one\n\n if (\n reachedMaxAttemptsForNextUser &&\n (!updatedLockUntil || !isUserLocked(new Date(updatedLockUntil)))\n ) {\n // If lockUntil reached max login attempts due to multiple parallel attempts but user was not locked yet,\n const newLockUntil = new Date(currentTime + lockTime).toISOString()\n\n await payload.db.updateOne({\n id: user.id,\n collection: collection.slug,\n data: {\n lockUntil: newLockUntil,\n },\n returning: false,\n })\n\n if (reachedMaxAttemptsForCurrentUser) {\n user.lockUntil = newLockUntil\n }\n\n if (collection.auth.useSessions) {\n // Remove all active sessions that have been created in a 20 second window. This protects\n // against brute force attacks - example: 99 incorrect, 1 correct parallel login attempts.\n // The correct login attempt will be finished first, as it's faster due to not having to perform\n // an additional db update here.\n // However, this request (the incorrect login attempt request) can kill the successful login attempt here.\n\n // Fetch user sessions separately (do not do this in the updateOne select in order to preserve the returning: true db call optimization)\n const currentUser = await payload.db.findOne<TypedUser>({\n collection: collection.slug,\n select: {\n sessions: true,\n },\n where: {\n id: {\n equals: user.id,\n },\n },\n })\n if (currentUser?.sessions?.length) {\n // Does not hurt also removing expired sessions\n currentUser.sessions = currentUser.sessions.filter((session) => {\n const sessionCreatedAt = new Date(session.createdAt)\n const twentySecondsAgo = new Date(currentTime - 20000)\n\n // Remove sessions created within the last 20 seconds\n return sessionCreatedAt <= twentySecondsAgo\n })\n\n user.sessions = currentUser.sessions\n\n // Ensure updatedAt date is always updated\n user.updatedAt = new Date().toISOString()\n\n await payload.db.updateOne({\n id: user.id,\n collection: collection.slug,\n data: user,\n returning: false,\n })\n }\n }\n }\n}\n"],"names":["isUserLocked","incrementLoginAttempts","collection","payload","user","auth","lockTime","maxLoginAttempts","currentTime","Date","now","updatedLockUntil","updatedLoginAttempts","lockUntil","updatedUser","db","updateOne","id","slug","data","loginAttempts","select","$inc","willReachMaxAttempts","toISOString","Error","reachedMaxAttemptsForCurrentUser","reachedMaxAttemptsForNextUser","newLockUntil","returning","useSessions","currentUser","findOne","sessions","where","equals","length","filter","session","sessionCreatedAt","createdAt","twentySecondsAgo","updatedAt"],"mappings":"AAGA,SAASA,YAAY,QAAQ,wBAAuB;AAQpD,mIAAmI;AACnI,4FAA4F;AAC5F,OAAO,MAAMC,yBAAyB,OAAO,EAC3CC,UAAU,EACVC,OAAO,EACPC,IAAI,EACC;IACL,MAAM,EACJC,MAAM,EAAEC,QAAQ,EAAEC,gBAAgB,EAAE,EACrC,GAAGL;IAEJ,MAAMM,cAAcC,KAAKC,GAAG;IAE5B,IAAIC,mBAAkC;IACtC,IAAIC,uBAAsC;IAE1C,IAAIR,KAAKS,SAAS,IAAI,CAACb,aAAa,IAAIS,KAAKL,KAAKS,SAAS,IAAI;QAC7D,mCAAmC;QACnC,MAAMC,cAAc,MAAMX,QAAQY,EAAE,CAACC,SAAS,CAAC;YAC7CC,IAAIb,KAAKa,EAAE;YACXf,YAAYA,WAAWgB,IAAI;YAC3BC,MAAM;gBACJN,WAAW;gBACXO,eAAe;YACjB;YACAC,QAAQ;gBACNR,WAAW;gBACXO,eAAe;YACjB;QACF;QACAT,mBAAmBG,YAAYD,SAAS;QACxCD,uBAAuBE,YAAYM,aAAa;QAChDhB,KAAKS,SAAS,GAAGF;IACnB,OAAO;QACL,MAAMQ,OAAmB;YACvBC,eAAe;gBACbE,MAAM;YACR;QACF;QAEA,MAAMC,uBACJ,OAAOnB,KAAKgB,aAAa,KAAK,YAAYhB,KAAKgB,aAAa,GAAG,KAAKb;QACtE,6DAA6D;QAC7D,IAAIgB,sBAAsB;YACxB,MAAMV,YAAY,IAAIJ,KAAKD,cAAcF,UAAUkB,WAAW;YAC9DL,KAAKN,SAAS,GAAGA;QACnB;QAEA,MAAMC,cAAc,MAAMX,QAAQY,EAAE,CAACC,SAAS,CAAC;YAC7CC,I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YAAYE,QAAQ,GAAGF,YAAYE,QAAQ,CAACI,MAAM,CAAC,CAACC;oBAClD,MAAMC,mBAAmB,IAAI9B,KAAK6B,QAAQE,SAAS;oBACnD,MAAMC,mBAAmB,IAAIhC,KAAKD,cAAc;oBAEhD,qDAAqD;oBACrD,OAAO+B,oBAAoBE;gBAC7B;gBAEArC,KAAK6B,QAAQ,GAAGF,YAAYE,QAAQ;gBAEpC,0CAA0C;gBAC1C7B,KAAKsC,SAAS,GAAG,IAAIjC,OAAOe,WAAW;gBAEvC,MAAMrB,QAAQY,EAAE,CAACC,SAAS,CAAC;oBACzBC,IAAIb,KAAKa,EAAE;oBACXf,YAAYA,WAAWgB,IAAI;oBAC3BC,MAAMf;oBACNyB,WAAW;gBACb;YACF;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/auth/strategies/local/incrementLoginAttempts.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\n\nimport { type JsonObject, type Payload, type User } from '../../../index.js'\nimport { isUserLocked } from '../../isUserLocked.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig\n payload: Payload\n user: User\n}\n\n// Note: this function does not use req in its updates, as we want those to be visible in parallel requests that are on a different\n// transaction. At the same time, we want updates from parallel requests to be visible here.\nexport const incrementLoginAttempts = async ({\n collection,\n payload,\n user,\n}: Args): Promise<void> => {\n const {\n auth: { lockTime, maxLoginAttempts },\n } = collection\n\n const currentTime = Date.now()\n\n let updatedLockUntil: null | string = null\n let updatedLoginAttempts: null | number = null\n\n if (user.lockUntil && !isUserLocked(new Date(user.lockUntil))) {\n // Expired lock, restart count at 1\n const updatedUser = await payload.db.updateOne({\n id: user.id,\n collection: collection.slug,\n data: {\n lockUntil: null,\n loginAttempts: 1,\n },\n select: {\n lockUntil: true,\n loginAttempts: true,\n },\n })\n updatedLockUntil = updatedUser.lockUntil\n updatedLoginAttempts = updatedUser.loginAttempts\n user.lockUntil = updatedLockUntil\n } else {\n const data: JsonObject = {\n loginAttempts: {\n $inc: 1,\n },\n }\n\n const willReachMaxAttempts =\n typeof user.loginAttempts === 'number' && user.loginAttempts + 1 >= maxLoginAttempts\n // Lock the account if at max attempts and not already locked\n if (willReachMaxAttempts) {\n const lockUntil = new Date(currentTime + lockTime).toISOString()\n data.lockUntil = lockUntil\n }\n\n const updatedUser = await payload.db.updateOne({\n id: user.id,\n collection: collection.slug,\n data,\n select: {\n lockUntil: true,\n loginAttempts: true,\n },\n })\n\n updatedLockUntil = updatedUser.lockUntil\n updatedLoginAttempts = updatedUser.loginAttempts\n }\n\n if (updatedLoginAttempts === null) {\n throw new Error('Failed to update login attempts or lockUntil for user')\n }\n\n // Check updated latest lockUntil and loginAttempts in case there were parallel updates\n const reachedMaxAttemptsForCurrentUser =\n typeof updatedLoginAttempts === 'number' && updatedLoginAttempts - 1 >= maxLoginAttempts\n\n const reachedMaxAttemptsForNextUser =\n typeof updatedLoginAttempts === 'number' && updatedLoginAttempts >= maxLoginAttempts\n\n if (reachedMaxAttemptsForCurrentUser) {\n user.lockUntil = updatedLockUntil\n }\n user.loginAttempts = updatedLoginAttempts - 1 // -1, as the updated increment is applied for the *next* login attempt, not the current one\n\n if (\n reachedMaxAttemptsForNextUser &&\n (!updatedLockUntil || !isUserLocked(new Date(updatedLockUntil)))\n ) {\n // If lockUntil reached max login attempts due to multiple parallel attempts but user was not locked yet,\n const newLockUntil = new Date(currentTime + lockTime).toISOString()\n\n await payload.db.updateOne({\n id: user.id,\n collection: collection.slug,\n data: {\n lockUntil: newLockUntil,\n },\n returning: false,\n })\n\n if (reachedMaxAttemptsForCurrentUser) {\n user.lockUntil = newLockUntil\n }\n\n if (collection.auth.useSessions) {\n // Remove all active sessions that have been created in a 20 second window. This protects\n // against brute force attacks - example: 99 incorrect, 1 correct parallel login attempts.\n // The correct login attempt will be finished first, as it's faster due to not having to perform\n // an additional db update here.\n // However, this request (the incorrect login attempt request) can kill the successful login attempt here.\n\n // Fetch user sessions separately (do not do this in the updateOne select in order to preserve the returning: true db call optimization)\n const currentUser = await payload.db.findOne<User>({\n collection: collection.slug,\n select: {\n sessions: true,\n },\n where: {\n id: {\n equals: user.id,\n },\n },\n })\n if (currentUser?.sessions?.length) {\n // Does not hurt also removing expired sessions\n currentUser.sessions = currentUser.sessions.filter((session) => {\n const sessionCreatedAt = new Date(session.createdAt ?? 0)\n const twentySecondsAgo = new Date(currentTime - 20000)\n\n // Remove sessions created within the last 20 seconds\n return sessionCreatedAt <= twentySecondsAgo\n })\n\n user.sessions = currentUser.sessions\n\n // Ensure updatedAt date is always updated\n user.updatedAt = new Date().toISOString()\n\n await payload.db.updateOne({\n id: user.id,\n collection: collection.slug,\n data: user,\n returning: false,\n })\n }\n }\n }\n}\n"],"names":["isUserLocked","incrementLoginAttempts","collection","payload","user","auth","lockTime","maxLoginAttempts","currentTime","Date","now","updatedLockUntil","updatedLoginAttempts","lockUntil","updatedUser","db","updateOne","id","slug","data","loginAttempts","select","$inc","willReachMaxAttempts","toISOString","Error","reachedMaxAttemptsForCurrentUser","reachedMaxAttemptsForNextUser","newLockUntil","returning","useSessions","currentUser","findOne","sessions","where","equals","length","filter","session","sessionCreatedAt","createdAt","twentySecondsAgo","updatedAt"],"mappings":"AAGA,SAASA,YAAY,QAAQ,wBAAuB;AAQpD,mIAAmI;AACnI,4FAA4F;AAC5F,OAAO,MAAMC,yBAAyB,OAAO,EAC3CC,UAAU,EACVC,OAAO,EACPC,IAAI,EACC;IACL,MAAM,EACJC,MAAM,EAAEC,QAAQ,EAAEC,gBAAgB,EAAE,EACrC,GAAGL;IAEJ,MAAMM,cAAcC,KAAKC,GAAG;IAE5B,IAAIC,mBAAkC;IACtC,IAAIC,uBAAsC;IAE1C,IAAIR,KAAKS,SAAS,IAAI,CAACb,aAAa,IAAIS,KAAKL,KAAKS,SAAS,IAAI;QAC7D,mCAAmC;QACnC,MAAMC,cAAc,MAAMX,QAAQY,EAAE,CAACC,SAAS,CAAC;YAC7CC,IAAIb,KAAKa,EAAE;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YACzBC,IAAIb,KAAKa,EAAE;YACXf,YAAYA,WAAWgB,IAAI;YAC3BC,MAAM;gBACJN,WAAWe;YACb;YACAC,WAAW;QACb;QAEA,IAAIH,kCAAkC;YACpCtB,KAAKS,SAAS,GAAGe;QACnB;QAEA,IAAI1B,WAAWG,IAAI,CAACyB,WAAW,EAAE;YAC/B,yFAAyF;YACzF,0FAA0F;YAC1F,gGAAgG;YAChG,gCAAgC;YAChC,0GAA0G;YAE1G,wIAAwI;YACxI,MAAMC,cAAc,MAAM5B,QAAQY,EAAE,CAACiB,OAAO,CAAO;gBACjD9B,YAAYA,WAAWgB,IAAI;gBAC3BG,QAAQ;oBACNY,UAAU;gBACZ;gBACAC,OAAO;oBACLjB,IAAI;wBACFkB,QAAQ/B,KAAKa,EAAE;oBACjB;gBACF;YACF;YACA,IAAIc,aAAaE,UAAUG,QAAQ;gBACjC,+CAA+C;gBAC/CL,YAAYE,QAAQ,GAAGF,YAAYE,QAAQ,CAACI,MAAM,CAAC,CAACC;oBAClD,MAAMC,mBAAmB,IAAI9B,KAAK6B,QAAQE,SAAS,IAAI;oBACvD,MAAMC,mBAAmB,IAAIhC,KAAKD,cAAc;oBAEhD,qDAAqD;oBACrD,OAAO+B,oBAAoBE;gBAC7B;gBAEArC,KAAK6B,QAAQ,GAAGF,YAAYE,QAAQ;gBAEpC,0CAA0C;gBAC1C7B,KAAKsC,SAAS,GAAG,IAAIjC,OAAOe,WAAW;gBAEvC,MAAMrB,QAAQY,EAAE,CAACC,SAAS,CAAC;oBACzBC,IAAIb,KAAKa,EAAE;oBACXf,YAAYA,WAAWgB,IAAI;oBAC3BC,MAAMf;oBACNyB,WAAW;gBACb;YACF;QACF;IACF;AACF,EAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { DeepRequired } from 'ts-essentials';
2
- import type { CollectionSlug, GlobalSlug, Payload, TypedUser } from '../index.js';
2
+ import type { CollectionSlug, GlobalSlug, Payload, User } from '../index.js';
3
3
  import type { PayloadRequest, Where } from '../types/index.js';
4
4
  /**
5
5
  * A permission object that can be used to determine if a user has access to a specific operation.
@@ -89,28 +89,35 @@ export type SanitizedPermissions = {
89
89
  [globalSlug: string]: SanitizedGlobalPermission;
90
90
  };
91
91
  };
92
- type BaseUser = {
93
- collection: string;
94
- email?: string;
95
- id: number | string;
96
- sessions?: Array<UserSession>;
97
- username?: string;
92
+ /**
93
+ * Fields injected onto a user at authentication time. They are never stored in the database and
94
+ * never present on a plain document read (e.g. `payload.findByID`) - only on the authenticated
95
+ * user (`req.user`, login/auth/me results, auth strategies).
96
+ */
97
+ export type AuthRuntimeFields = {
98
+ /**
99
+ * The session ID of the current request. May be present on request-authenticated users when
100
+ * sessions are enabled.
101
+ */
102
+ _sid?: string;
103
+ /**
104
+ * The name of the auth strategy that authenticated the request (e.g. `local-jwt`).
105
+ */
106
+ _strategy?: string;
98
107
  };
99
108
  /**
100
- * @deprecated Use `TypedUser` instead. This will be removed in 4.0.
109
+ * Note: AuthenticatedUser still carries the write-only `password` from `User` (always `undefined` at runtime).
110
+ * Stripping it cleanly isn't possible, because auth operations build the authenticated user
111
+ * from a read `User` doc, so a `never`-typed `password` would break those assignments
101
112
  */
102
- export type UntypedUser = {
103
- [key: string]: any;
104
- } & BaseUser;
105
113
  /**
106
- * `collection` is not available one the client. It's only available on the server (req.user)
107
- * On the client, you can access the collection via config.admin.user. Config can be accessed using the useConfig() hook
114
+ * The signed-in user: the read user plus the runtime auth markers (`_strategy`, `_sid`). This is
115
+ * what `req.user`, `payload.auth()`, the `me` operation, auth strategies, and `useAuth().user`
116
+ * return.
108
117
  */
109
- export type ClientUser = {
110
- [key: string]: any;
111
- } & BaseUser;
118
+ export type AuthenticatedUser = AuthRuntimeFields & User;
112
119
  export type UserSession = {
113
- createdAt: Date | string;
120
+ createdAt?: Date | null | string;
114
121
  expiresAt: Date | string;
115
122
  id: string;
116
123
  };
@@ -149,10 +156,7 @@ export type AuthStrategyFunctionArgs = {
149
156
  };
150
157
  export type AuthStrategyResult = {
151
158
  responseHeaders?: Headers;
152
- user: ({
153
- _strategy?: string;
154
- collection?: string;
155
- } & TypedUser) | null;
159
+ user: AuthenticatedUser | null;
156
160
  };
157
161
  export type AuthStrategyFunction = (args: AuthStrategyFunctionArgs) => AuthStrategyResult | Promise<AuthStrategyResult>;
158
162
  export type AuthStrategy = {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAE9D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,OAAO,CAAA;IACnB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAAA;CACtC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,UAAU,CAAA;IAClB,MAAM,EAAE,iBAAiB,CAAA;IACzB,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,UAAU,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,yBAAyB,GACjC;IACE,MAAM,EAAE,0BAA0B,CAAA;CACnC,GACD,IAAI,CAAA;AAER,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAAA;CACtC,CAAA;AAED,MAAM,MAAM,0BAA0B,GAClC;IACE,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,CAAA;CAC/C,GACD,IAAI,CAAA;AAER,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,EAAE,iBAA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,UAAU,CAAC,EAAE,YAAY,EAAE,CAAA;IAC3B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IAErB;;;OAGG;IACH,MAAM,CAAC,EACH;QACE,iBAAiB,CAAC,EAAE,uBAAuB,CAAA;QAC3C,oBAAoB,CAAC,EAAE,0BAA0B,CAAA;KAClD,GACD,OAAO,CAAA;CACZ;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,iBAAiB,CAAC,EAAE,uBAAuB,CAAA;IAC3C,oBAAoB,CAAC,EAAE,0BAA0B,CAAA;CAClD,CAAA;AAED,MAAM,WAAW,IACf,SAAQ,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,mBAAmB,GAAG,QAAQ,CAAC;IAC/F,cAAc,CAAC,EAAE;QACf,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,iBAAiB,CAAC,EAAE,+BAA+B,CAAA;QACnD,oBAAoB,CAAC,EAAE,kCAAkC,CAAA;KAC1D,CAAA;IACD,iBAAiB,EAAE,KAAK,GAAG,wBAAwB,CAAA;IACnD,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAA;CAChC;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,IAAI,KAAK,CAE7E"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/auth/types.ts"],"sourcesContent":["import type { DeepRequired } from 'ts-essentials'\n\nimport type { CollectionSlug, GlobalSlug, Payload, TypedUser } from '../index.js'\nimport type { PayloadRequest, Where } from '../types/index.js'\n\n/**\n * A permission object that can be used to determine if a user has access to a specific operation.\n */\nexport type Permission = {\n permission: boolean\n where?: Where\n}\n\nexport type FieldsPermissions = {\n [fieldName: string]: FieldPermissions\n}\n\nexport type BlockPermissions = {\n create: Permission\n fields: FieldsPermissions\n read: Permission\n update: Permission\n}\n\nexport type SanitizedBlockPermissions =\n | {\n fields: SanitizedFieldsPermissions\n }\n | true\n\nexport type BlocksPermissions = {\n [blockSlug: string]: BlockPermissions\n}\n\nexport type SanitizedBlocksPermissions =\n | {\n [blockSlug: string]: SanitizedBlockPermissions\n }\n | true\n\nexport type FieldPermissions = {\n blocks?: BlocksPermissions\n create?: Permission\n fields?: FieldsPermissions\n read?: Permission\n update?: Permission\n}\n\nexport type SanitizedFieldPermissions =\n | {\n blocks?: SanitizedBlocksPermissions\n create: true\n fields?: SanitizedFieldsPermissions\n read: true\n update: true\n }\n | true\n\nexport type SanitizedFieldsPermissions =\n | {\n [fieldName: string]: SanitizedFieldPermissions\n }\n | true\n\nexport type CollectionPermission = {\n create?: Permission\n delete?: Permission\n fields: FieldsPermissions\n read?: Permission\n readVersions?: Permission\n // Auth-enabled Collections only\n unlock?: Permission\n update?: Permission\n}\n\nexport type SanitizedCollectionPermission = {\n create?: true\n delete?: true\n fields: SanitizedFieldsPermissions\n read?: true\n readVersions?: true\n // Auth-enabled Collections only\n unlock?: true\n update?: true\n}\n\nexport type GlobalPermission = {\n fields: FieldsPermissions\n read?: Permission\n readVersions?: Permission\n update?: Permission\n}\n\nexport type SanitizedGlobalPermission = {\n fields: SanitizedFieldsPermissions\n read?: true\n readVersions?: true\n update?: true\n}\n\nexport type DocumentPermissions = CollectionPermission | GlobalPermission\n\nexport type SanitizedDocumentPermissions = SanitizedCollectionPermission | SanitizedGlobalPermission\n\nexport type Permissions = {\n canAccessAdmin: boolean\n collections?: Record<CollectionSlug, CollectionPermission>\n globals?: Record<GlobalSlug, GlobalPermission>\n}\n\nexport type SanitizedPermissions = {\n canAccessAdmin?: boolean\n collections?: {\n [collectionSlug: string]: SanitizedCollectionPermission\n }\n globals?: {\n [globalSlug: string]: SanitizedGlobalPermission\n }\n}\n\ntype BaseUser = {\n collection: string\n email?: string\n id: number | string\n sessions?: Array<UserSession>\n username?: string\n}\n\n/**\n * @deprecated Use `TypedUser` instead. This will be removed in 4.0.\n */\nexport type UntypedUser = {\n [key: string]: any\n} & BaseUser\n\n/**\n * `collection` is not available one the client. It's only available on the server (req.user)\n * On the client, you can access the collection via config.admin.user. Config can be accessed using the useConfig() hook\n */\nexport type ClientUser = {\n [key: string]: any\n} & BaseUser\n\nexport type UserSession = { createdAt: Date | string; expiresAt: Date | string; id: string }\ntype GenerateVerifyEmailHTML<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateVerifyEmailSubject<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailHTML<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailSubject<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\nexport type AuthStrategyFunctionArgs = {\n /**\n * Specifies whether or not response headers can be set from this strategy.\n */\n canSetHeaders?: boolean\n headers: Request['headers']\n isGraphQL?: boolean\n payload: Payload\n /**\n * The AuthStrategy name property from the payload config.\n */\n strategyName?: string\n}\n\nexport type AuthStrategyResult = {\n responseHeaders?: Headers\n user:\n | ({\n _strategy?: string\n collection?: string\n } & TypedUser)\n | null\n}\n\nexport type AuthStrategyFunction = (\n args: AuthStrategyFunctionArgs,\n) => AuthStrategyResult | Promise<AuthStrategyResult>\nexport type AuthStrategy = {\n authenticate: AuthStrategyFunction\n name: string\n}\n\nexport type LoginWithUsernameOptions =\n | {\n allowEmailLogin?: false\n requireEmail?: boolean\n // If `allowEmailLogin` is false, `requireUsername` must be true (default: true)\n requireUsername?: true\n }\n | {\n allowEmailLogin?: true\n requireEmail?: boolean\n requireUsername?: boolean\n }\n\nexport interface IncomingAuthType {\n /**\n * Set cookie options, including secure, sameSite, and domain. For advanced users.\n */\n cookies?: {\n domain?: string\n sameSite?: 'Lax' | 'None' | 'Strict' | boolean\n secure?: boolean\n }\n /**\n * How many levels deep a user document should be populated when creating the JWT and binding the user to the req. Defaults to 0 and should only be modified if absolutely necessary, as this will affect performance.\n * @default 0\n */\n depth?: number\n /**\n * Advanced - disable Payload's built-in local auth strategy. Only use this property if you have replaced Payload's auth mechanisms with your own.\n */\n disableLocalStrategy?:\n | {\n /**\n * Include auth fields on the collection even though the local strategy is disabled.\n * Useful when you do not want the database or types to vary depending on the auth configuration.\n */\n enableFields?: true\n optionalPassword?: true\n }\n | true\n /**\n * Customize the way that the forgotPassword operation functions.\n * @link https://payloadcms.com/docs/authentication/email#forgot-password\n */\n forgotPassword?: {\n /**\n * The number of milliseconds that the forgot password token should be valid for.\n * @default 3600000 // 1 hour\n */\n expiration?: number\n generateEmailHTML?: GenerateForgotPasswordEmailHTML\n generateEmailSubject?: GenerateForgotPasswordEmailSubject\n }\n /**\n * Set the time (in milliseconds) that a user should be locked out if they fail authentication more times than maxLoginAttempts allows for.\n */\n lockTime?: number\n /**\n * Ability to allow users to login with username/password.\n *\n * @link https://payloadcms.com/docs/authentication/overview#login-with-username\n */\n loginWithUsername?: boolean | LoginWithUsernameOptions\n /**\n * Only allow a user to attempt logging in X amount of times. Automatically locks out a user from authenticating if this limit is passed. Set to 0 to disable.\n */\n maxLoginAttempts?: number\n /***\n * Set to true if you want to remove the token from the returned authentication API responses such as login or refresh.\n */\n removeTokenFromResponses?: true\n /**\n * Advanced - an array of custom authentification strategies to extend this collection's authentication with.\n * @link https://payloadcms.com/docs/authentication/custom-strategies\n */\n strategies?: AuthStrategy[]\n /**\n * Controls how many seconds the token will be valid for. Default is 2 hours.\n * @default 7200\n * @link https://payloadcms.com/docs/authentication/overview#config-options\n */\n tokenExpiration?: number\n /**\n * Payload Authentication provides for API keys to be set on each user within an Authentication-enabled Collection.\n * @default false\n * @link https://payloadcms.com/docs/authentication/api-keys\n */\n useAPIKey?: boolean\n\n /**\n * Use sessions for authentication. Enabled by default.\n * @default true\n */\n useSessions?: boolean\n\n /**\n * Set to true or pass an object with verification options to require users to verify by email before they are allowed to log into your app.\n * @link https://payloadcms.com/docs/authentication/email#email-verification\n */\n verify?:\n | {\n generateEmailHTML?: GenerateVerifyEmailHTML\n generateEmailSubject?: GenerateVerifyEmailSubject\n }\n | boolean\n}\n\nexport type VerifyConfig = {\n generateEmailHTML?: GenerateVerifyEmailHTML\n generateEmailSubject?: GenerateVerifyEmailSubject\n}\n\nexport interface Auth\n extends Omit<DeepRequired<IncomingAuthType>, 'forgotPassword' | 'loginWithUsername' | 'verify'> {\n forgotPassword?: {\n expiration?: number\n generateEmailHTML?: GenerateForgotPasswordEmailHTML\n generateEmailSubject?: GenerateForgotPasswordEmailSubject\n }\n loginWithUsername: false | LoginWithUsernameOptions\n verify?: boolean | VerifyConfig\n}\n\nexport function hasWhereAccessResult(result: boolean | Where): result is Where {\n return result && typeof result === 'object'\n}\n"],"names":["hasWhereAccessResult","result"],"mappings":"AAmUA,OAAO,SAASA,qBAAqBC,MAAuB;IAC1D,OAAOA,UAAU,OAAOA,WAAW;AACrC"}
1
+ {"version":3,"sources":["../../src/auth/types.ts"],"sourcesContent":["import type { DeepRequired } from 'ts-essentials'\n\nimport type { CollectionSlug, GlobalSlug, Payload, User } from '../index.js'\nimport type { PayloadRequest, Where } from '../types/index.js'\n\n/**\n * A permission object that can be used to determine if a user has access to a specific operation.\n */\nexport type Permission = {\n permission: boolean\n where?: Where\n}\n\nexport type FieldsPermissions = {\n [fieldName: string]: FieldPermissions\n}\n\nexport type BlockPermissions = {\n create: Permission\n fields: FieldsPermissions\n read: Permission\n update: Permission\n}\n\nexport type SanitizedBlockPermissions =\n | {\n fields: SanitizedFieldsPermissions\n }\n | true\n\nexport type BlocksPermissions = {\n [blockSlug: string]: BlockPermissions\n}\n\nexport type SanitizedBlocksPermissions =\n | {\n [blockSlug: string]: SanitizedBlockPermissions\n }\n | true\n\nexport type FieldPermissions = {\n blocks?: BlocksPermissions\n create?: Permission\n fields?: FieldsPermissions\n read?: Permission\n update?: Permission\n}\n\nexport type SanitizedFieldPermissions =\n | {\n blocks?: SanitizedBlocksPermissions\n create: true\n fields?: SanitizedFieldsPermissions\n read: true\n update: true\n }\n | true\n\nexport type SanitizedFieldsPermissions =\n | {\n [fieldName: string]: SanitizedFieldPermissions\n }\n | true\n\nexport type CollectionPermission = {\n create?: Permission\n delete?: Permission\n fields: FieldsPermissions\n read?: Permission\n readVersions?: Permission\n // Auth-enabled Collections only\n unlock?: Permission\n update?: Permission\n}\n\nexport type SanitizedCollectionPermission = {\n create?: true\n delete?: true\n fields: SanitizedFieldsPermissions\n read?: true\n readVersions?: true\n // Auth-enabled Collections only\n unlock?: true\n update?: true\n}\n\nexport type GlobalPermission = {\n fields: FieldsPermissions\n read?: Permission\n readVersions?: Permission\n update?: Permission\n}\n\nexport type SanitizedGlobalPermission = {\n fields: SanitizedFieldsPermissions\n read?: true\n readVersions?: true\n update?: true\n}\n\nexport type DocumentPermissions = CollectionPermission | GlobalPermission\n\nexport type SanitizedDocumentPermissions = SanitizedCollectionPermission | SanitizedGlobalPermission\n\nexport type Permissions = {\n canAccessAdmin: boolean\n collections?: Record<CollectionSlug, CollectionPermission>\n globals?: Record<GlobalSlug, GlobalPermission>\n}\n\nexport type SanitizedPermissions = {\n canAccessAdmin?: boolean\n collections?: {\n [collectionSlug: string]: SanitizedCollectionPermission\n }\n globals?: {\n [globalSlug: string]: SanitizedGlobalPermission\n }\n}\n\n/**\n * Fields injected onto a user at authentication time. They are never stored in the database and\n * never present on a plain document read (e.g. `payload.findByID`) - only on the authenticated\n * user (`req.user`, login/auth/me results, auth strategies).\n */\nexport type AuthRuntimeFields = {\n /**\n * The session ID of the current request. May be present on request-authenticated users when\n * sessions are enabled.\n */\n _sid?: string\n /**\n * The name of the auth strategy that authenticated the request (e.g. `local-jwt`).\n */\n _strategy?: string\n}\n\n/**\n * Note: AuthenticatedUser still carries the write-only `password` from `User` (always `undefined` at runtime).\n * Stripping it cleanly isn't possible, because auth operations build the authenticated user\n * from a read `User` doc, so a `never`-typed `password` would break those assignments\n */\n/**\n * The signed-in user: the read user plus the runtime auth markers (`_strategy`, `_sid`). This is\n * what `req.user`, `payload.auth()`, the `me` operation, auth strategies, and `useAuth().user`\n * return.\n */\nexport type AuthenticatedUser = AuthRuntimeFields & User\n\nexport type UserSession = {\n createdAt?: Date | null | string\n expiresAt: Date | string\n id: string\n}\ntype GenerateVerifyEmailHTML<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateVerifyEmailSubject<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailHTML<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailSubject<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\nexport type AuthStrategyFunctionArgs = {\n /**\n * Specifies whether or not response headers can be set from this strategy.\n */\n canSetHeaders?: boolean\n headers: Request['headers']\n isGraphQL?: boolean\n payload: Payload\n /**\n * The AuthStrategy name property from the payload config.\n */\n strategyName?: string\n}\n\nexport type AuthStrategyResult = {\n responseHeaders?: Headers\n user: AuthenticatedUser | null\n}\n\nexport type AuthStrategyFunction = (\n args: AuthStrategyFunctionArgs,\n) => AuthStrategyResult | Promise<AuthStrategyResult>\nexport type AuthStrategy = {\n authenticate: AuthStrategyFunction\n name: string\n}\n\nexport type LoginWithUsernameOptions =\n | {\n allowEmailLogin?: false\n requireEmail?: boolean\n // If `allowEmailLogin` is false, `requireUsername` must be true (default: true)\n requireUsername?: true\n }\n | {\n allowEmailLogin?: true\n requireEmail?: boolean\n requireUsername?: boolean\n }\n\nexport interface IncomingAuthType {\n /**\n * Set cookie options, including secure, sameSite, and domain. For advanced users.\n */\n cookies?: {\n domain?: string\n sameSite?: 'Lax' | 'None' | 'Strict' | boolean\n secure?: boolean\n }\n /**\n * How many levels deep a user document should be populated when creating the JWT and binding the user to the req. Defaults to 0 and should only be modified if absolutely necessary, as this will affect performance.\n * @default 0\n */\n depth?: number\n /**\n * Advanced - disable Payload's built-in local auth strategy. Only use this property if you have replaced Payload's auth mechanisms with your own.\n */\n disableLocalStrategy?:\n | {\n /**\n * Include auth fields on the collection even though the local strategy is disabled.\n * Useful when you do not want the database or types to vary depending on the auth configuration.\n */\n enableFields?: true\n optionalPassword?: true\n }\n | true\n /**\n * Customize the way that the forgotPassword operation functions.\n * @link https://payloadcms.com/docs/authentication/email#forgot-password\n */\n forgotPassword?: {\n /**\n * The number of milliseconds that the forgot password token should be valid for.\n * @default 3600000 // 1 hour\n */\n expiration?: number\n generateEmailHTML?: GenerateForgotPasswordEmailHTML\n generateEmailSubject?: GenerateForgotPasswordEmailSubject\n }\n /**\n * Set the time (in milliseconds) that a user should be locked out if they fail authentication more times than maxLoginAttempts allows for.\n */\n lockTime?: number\n /**\n * Ability to allow users to login with username/password.\n *\n * @link https://payloadcms.com/docs/authentication/overview#login-with-username\n */\n loginWithUsername?: boolean | LoginWithUsernameOptions\n /**\n * Only allow a user to attempt logging in X amount of times. Automatically locks out a user from authenticating if this limit is passed. Set to 0 to disable.\n */\n maxLoginAttempts?: number\n /***\n * Set to true if you want to remove the token from the returned authentication API responses such as login or refresh.\n */\n removeTokenFromResponses?: true\n /**\n * Advanced - an array of custom authentification strategies to extend this collection's authentication with.\n * @link https://payloadcms.com/docs/authentication/custom-strategies\n */\n strategies?: AuthStrategy[]\n /**\n * Controls how many seconds the token will be valid for. Default is 2 hours.\n * @default 7200\n * @link https://payloadcms.com/docs/authentication/overview#config-options\n */\n tokenExpiration?: number\n /**\n * Payload Authentication provides for API keys to be set on each user within an Authentication-enabled Collection.\n * @default false\n * @link https://payloadcms.com/docs/authentication/api-keys\n */\n useAPIKey?: boolean\n\n /**\n * Use sessions for authentication. Enabled by default.\n * @default true\n */\n useSessions?: boolean\n\n /**\n * Set to true or pass an object with verification options to require users to verify by email before they are allowed to log into your app.\n * @link https://payloadcms.com/docs/authentication/email#email-verification\n */\n verify?:\n | {\n generateEmailHTML?: GenerateVerifyEmailHTML\n generateEmailSubject?: GenerateVerifyEmailSubject\n }\n | boolean\n}\n\nexport type VerifyConfig = {\n generateEmailHTML?: GenerateVerifyEmailHTML\n generateEmailSubject?: GenerateVerifyEmailSubject\n}\n\nexport interface Auth\n extends Omit<DeepRequired<IncomingAuthType>, 'forgotPassword' | 'loginWithUsername' | 'verify'> {\n forgotPassword?: {\n expiration?: number\n generateEmailHTML?: GenerateForgotPasswordEmailHTML\n generateEmailSubject?: GenerateForgotPasswordEmailSubject\n }\n loginWithUsername: false | LoginWithUsernameOptions\n verify?: boolean | VerifyConfig\n}\n\nexport function hasWhereAccessResult(result: boolean | Where): result is Where {\n return result && typeof result === 'object'\n}\n"],"names":["hasWhereAccessResult","result"],"mappings":"AAwUA,OAAO,SAASA,qBAAqBC,MAAuB;IAC1D,OAAOA,UAAU,OAAOA,WAAW;AACrC"}