@payloadcms/next 3.0.0-beta.11 → 3.0.0-beta.13

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 (180) hide show
  1. package/dist/cjs/withPayload.cjs +2 -1
  2. package/dist/cjs/withPayload.cjs.map +1 -1
  3. package/dist/exports/routes.d.ts +1 -1
  4. package/dist/exports/routes.d.ts.map +1 -1
  5. package/dist/exports/routes.js +1 -1
  6. package/dist/exports/routes.js.map +1 -1
  7. package/dist/exports/utilities.d.ts +3 -1
  8. package/dist/exports/utilities.d.ts.map +1 -1
  9. package/dist/exports/utilities.js +3 -1
  10. package/dist/exports/utilities.js.map +1 -1
  11. package/dist/next-fileupload/handlers.js.map +1 -1
  12. package/dist/next-fileupload/isEligibleRequest.js +1 -1
  13. package/dist/next-fileupload/isEligibleRequest.js.map +1 -1
  14. package/dist/next-fileupload/processMultipart.d.ts.map +1 -1
  15. package/dist/next-fileupload/processMultipart.js +29 -6
  16. package/dist/next-fileupload/processMultipart.js.map +1 -1
  17. package/dist/next-fileupload/utilities.d.ts.map +1 -1
  18. package/dist/next-fileupload/utilities.js +4 -4
  19. package/dist/next-fileupload/utilities.js.map +1 -1
  20. package/dist/routes/graphql/handler.d.ts.map +1 -1
  21. package/dist/routes/graphql/handler.js +9 -4
  22. package/dist/routes/graphql/handler.js.map +1 -1
  23. package/dist/routes/rest/auth/access.d.ts.map +1 -1
  24. package/dist/routes/rest/auth/access.js +5 -0
  25. package/dist/routes/rest/auth/access.js.map +1 -1
  26. package/dist/routes/rest/auth/forgotPassword.d.ts.map +1 -1
  27. package/dist/routes/rest/auth/forgotPassword.js +7 -2
  28. package/dist/routes/rest/auth/forgotPassword.js.map +1 -1
  29. package/dist/routes/rest/auth/init.d.ts.map +1 -1
  30. package/dist/routes/rest/auth/init.js +6 -0
  31. package/dist/routes/rest/auth/init.js.map +1 -1
  32. package/dist/routes/rest/auth/login.d.ts.map +1 -1
  33. package/dist/routes/rest/auth/login.js +8 -5
  34. package/dist/routes/rest/auth/login.js.map +1 -1
  35. package/dist/routes/rest/auth/logout.d.ts.map +1 -1
  36. package/dist/routes/rest/auth/logout.js +11 -6
  37. package/dist/routes/rest/auth/logout.js.map +1 -1
  38. package/dist/routes/rest/auth/me.d.ts.map +1 -1
  39. package/dist/routes/rest/auth/me.js +5 -0
  40. package/dist/routes/rest/auth/me.js.map +1 -1
  41. package/dist/routes/rest/auth/refresh.d.ts.map +1 -1
  42. package/dist/routes/rest/auth/refresh.js +11 -7
  43. package/dist/routes/rest/auth/refresh.js.map +1 -1
  44. package/dist/routes/rest/auth/registerFirstUser.d.ts.map +1 -1
  45. package/dist/routes/rest/auth/registerFirstUser.js +17 -5
  46. package/dist/routes/rest/auth/registerFirstUser.js.map +1 -1
  47. package/dist/routes/rest/auth/resetPassword.d.ts.map +1 -1
  48. package/dist/routes/rest/auth/resetPassword.js +8 -5
  49. package/dist/routes/rest/auth/resetPassword.js.map +1 -1
  50. package/dist/routes/rest/auth/unlock.d.ts.map +1 -1
  51. package/dist/routes/rest/auth/unlock.js +7 -2
  52. package/dist/routes/rest/auth/unlock.js.map +1 -1
  53. package/dist/routes/rest/auth/verifyEmail.d.ts.map +1 -1
  54. package/dist/routes/rest/auth/verifyEmail.js +7 -2
  55. package/dist/routes/rest/auth/verifyEmail.js.map +1 -1
  56. package/dist/routes/rest/buildFormState.d.ts.map +1 -1
  57. package/dist/routes/rest/buildFormState.js +11 -0
  58. package/dist/routes/rest/buildFormState.js.map +1 -1
  59. package/dist/routes/rest/collections/count.d.ts +3 -0
  60. package/dist/routes/rest/collections/count.d.ts.map +1 -0
  61. package/dist/routes/rest/collections/count.js +15 -0
  62. package/dist/routes/rest/collections/count.js.map +1 -0
  63. package/dist/routes/rest/collections/create.d.ts.map +1 -1
  64. package/dist/routes/rest/collections/create.js +5 -0
  65. package/dist/routes/rest/collections/create.js.map +1 -1
  66. package/dist/routes/rest/collections/delete.d.ts.map +1 -1
  67. package/dist/routes/rest/collections/delete.js +7 -0
  68. package/dist/routes/rest/collections/delete.js.map +1 -1
  69. package/dist/routes/rest/collections/deleteByID.d.ts.map +1 -1
  70. package/dist/routes/rest/collections/deleteByID.js +7 -0
  71. package/dist/routes/rest/collections/deleteByID.js.map +1 -1
  72. package/dist/routes/rest/collections/docAccess.d.ts.map +1 -1
  73. package/dist/routes/rest/collections/docAccess.js +5 -0
  74. package/dist/routes/rest/collections/docAccess.js.map +1 -1
  75. package/dist/routes/rest/collections/duplicate.d.ts.map +1 -1
  76. package/dist/routes/rest/collections/duplicate.js +5 -0
  77. package/dist/routes/rest/collections/duplicate.js.map +1 -1
  78. package/dist/routes/rest/collections/find.d.ts.map +1 -1
  79. package/dist/routes/rest/collections/find.js +5 -0
  80. package/dist/routes/rest/collections/find.js.map +1 -1
  81. package/dist/routes/rest/collections/findByID.d.ts.map +1 -1
  82. package/dist/routes/rest/collections/findByID.js +5 -0
  83. package/dist/routes/rest/collections/findByID.js.map +1 -1
  84. package/dist/routes/rest/collections/findVersionByID.d.ts.map +1 -1
  85. package/dist/routes/rest/collections/findVersionByID.js +5 -0
  86. package/dist/routes/rest/collections/findVersionByID.js.map +1 -1
  87. package/dist/routes/rest/collections/findVersions.d.ts.map +1 -1
  88. package/dist/routes/rest/collections/findVersions.js +5 -0
  89. package/dist/routes/rest/collections/findVersions.js.map +1 -1
  90. package/dist/routes/rest/collections/preview.d.ts.map +1 -1
  91. package/dist/routes/rest/collections/preview.js +7 -1
  92. package/dist/routes/rest/collections/preview.js.map +1 -1
  93. package/dist/routes/rest/collections/restoreVersion.d.ts.map +1 -1
  94. package/dist/routes/rest/collections/restoreVersion.js +5 -0
  95. package/dist/routes/rest/collections/restoreVersion.js.map +1 -1
  96. package/dist/routes/rest/collections/update.d.ts.map +1 -1
  97. package/dist/routes/rest/collections/update.js +7 -0
  98. package/dist/routes/rest/collections/update.js.map +1 -1
  99. package/dist/routes/rest/collections/updateByID.d.ts.map +1 -1
  100. package/dist/routes/rest/collections/updateByID.js +5 -0
  101. package/dist/routes/rest/collections/updateByID.js.map +1 -1
  102. package/dist/routes/rest/files/getFile.d.ts.map +1 -1
  103. package/dist/routes/rest/files/getFile.js +15 -8
  104. package/dist/routes/rest/files/getFile.js.map +1 -1
  105. package/dist/routes/rest/files/getFileTypeFallback.d.ts +7 -0
  106. package/dist/routes/rest/files/getFileTypeFallback.d.ts.map +1 -0
  107. package/dist/routes/rest/files/getFileTypeFallback.js +21 -0
  108. package/dist/routes/rest/files/getFileTypeFallback.js.map +1 -0
  109. package/dist/routes/rest/globals/docAccess.d.ts.map +1 -1
  110. package/dist/routes/rest/globals/docAccess.js +5 -0
  111. package/dist/routes/rest/globals/docAccess.js.map +1 -1
  112. package/dist/routes/rest/globals/findOne.d.ts.map +1 -1
  113. package/dist/routes/rest/globals/findOne.js +5 -0
  114. package/dist/routes/rest/globals/findOne.js.map +1 -1
  115. package/dist/routes/rest/globals/findVersionByID.d.ts.map +1 -1
  116. package/dist/routes/rest/globals/findVersionByID.js +5 -0
  117. package/dist/routes/rest/globals/findVersionByID.js.map +1 -1
  118. package/dist/routes/rest/globals/findVersions.d.ts.map +1 -1
  119. package/dist/routes/rest/globals/findVersions.js +5 -0
  120. package/dist/routes/rest/globals/findVersions.js.map +1 -1
  121. package/dist/routes/rest/globals/preview.d.ts.map +1 -1
  122. package/dist/routes/rest/globals/preview.js +7 -1
  123. package/dist/routes/rest/globals/preview.js.map +1 -1
  124. package/dist/routes/rest/globals/restoreVersion.d.ts.map +1 -1
  125. package/dist/routes/rest/globals/restoreVersion.js +5 -0
  126. package/dist/routes/rest/globals/restoreVersion.js.map +1 -1
  127. package/dist/routes/rest/globals/update.d.ts.map +1 -1
  128. package/dist/routes/rest/globals/update.js +5 -0
  129. package/dist/routes/rest/globals/update.js.map +1 -1
  130. package/dist/routes/rest/index.d.ts +1 -0
  131. package/dist/routes/rest/index.d.ts.map +1 -1
  132. package/dist/routes/rest/index.js +55 -9
  133. package/dist/routes/rest/index.js.map +1 -1
  134. package/dist/routes/rest/routeError.d.ts +5 -4
  135. package/dist/routes/rest/routeError.d.ts.map +1 -1
  136. package/dist/routes/rest/routeError.js +25 -11
  137. package/dist/routes/rest/routeError.js.map +1 -1
  138. package/dist/utilities/getDataAndFile.d.ts.map +1 -1
  139. package/dist/utilities/getDataAndFile.js +26 -46
  140. package/dist/utilities/getDataAndFile.js.map +1 -1
  141. package/dist/utilities/getPayloadHMR.d.ts +2 -1
  142. package/dist/utilities/getPayloadHMR.d.ts.map +1 -1
  143. package/dist/utilities/getPayloadHMR.js +22 -19
  144. package/dist/utilities/getPayloadHMR.js.map +1 -1
  145. package/dist/utilities/headersWithCors.d.ts +8 -0
  146. package/dist/utilities/headersWithCors.d.ts.map +1 -0
  147. package/dist/utilities/headersWithCors.js +17 -0
  148. package/dist/utilities/headersWithCors.js.map +1 -0
  149. package/dist/utilities/initPage.d.ts.map +1 -1
  150. package/dist/utilities/initPage.js +15 -2
  151. package/dist/utilities/initPage.js.map +1 -1
  152. package/dist/views/CreateFirstUser/index.client.js +2 -2
  153. package/dist/views/CreateFirstUser/index.client.js.map +1 -1
  154. package/dist/views/CreateFirstUser/index.d.ts.map +1 -1
  155. package/dist/views/CreateFirstUser/index.js +17 -0
  156. package/dist/views/CreateFirstUser/index.js.map +1 -1
  157. package/dist/views/Edit/Default/index.d.ts.map +1 -1
  158. package/dist/views/Edit/Default/index.js +3 -2
  159. package/dist/views/Edit/Default/index.js.map +1 -1
  160. package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts +3 -0
  161. package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts.map +1 -0
  162. package/dist/views/ForgotPassword/ForgotPasswordForm/index.js +55 -0
  163. package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -0
  164. package/dist/views/ForgotPassword/index.d.ts.map +1 -1
  165. package/dist/views/ForgotPassword/index.js +3 -39
  166. package/dist/views/ForgotPassword/index.js.map +1 -1
  167. package/dist/views/LivePreview/Toolbar/Controls/index.d.ts.map +1 -1
  168. package/dist/views/LivePreview/Toolbar/Controls/index.js +6 -4
  169. package/dist/views/LivePreview/Toolbar/Controls/index.js.map +1 -1
  170. package/dist/views/Login/LoginForm/index.d.ts.map +1 -1
  171. package/dist/views/Login/LoginForm/index.js +26 -2
  172. package/dist/views/Login/LoginForm/index.js.map +1 -1
  173. package/dist/views/Logout/LogoutClient.d.ts.map +1 -1
  174. package/dist/views/Logout/LogoutClient.js +1 -2
  175. package/dist/views/Logout/LogoutClient.js.map +1 -1
  176. package/dist/withPayload.d.ts.map +1 -1
  177. package/dist/withPayload.js +2 -1
  178. package/dist/withPayload.js.map +1 -1
  179. package/package.json +11 -9
  180. package/src/index.js +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/forgotPassword.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { forgotPasswordOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const forgotPassword: CollectionRouteHandler = async ({ collection, req }) => {\n await forgotPasswordOperation({\n collection,\n data: {\n email: req.data.email as string,\n },\n disableEmail: Boolean(req.data?.disableEmail),\n expiration: typeof req.data.expiration === 'number' ? req.data.expiration : undefined,\n req,\n })\n\n return Response.json(\n {\n // TODO(translate)\n message: 'Success',\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","forgotPasswordOperation","forgotPassword","collection","req","data","email","disableEmail","Boolean","expiration","undefined","Response","json","message","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,uBAAuB,QAAQ,qBAAoB;AAI5D,OAAO,MAAMC,iBAAyC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAC9E,MAAMH,wBAAwB;QAC5BE;QACAE,MAAM;YACJC,OAAOF,IAAIC,IAAI,CAACC,KAAK;QACvB;QACAC,cAAcC,QAAQJ,IAAIC,IAAI,EAAEE;QAChCE,YAAY,OAAOL,IAAIC,IAAI,CAACI,UAAU,KAAK,WAAWL,IAAIC,IAAI,CAACI,UAAU,GAAGC;QAC5EN;IACF;IAEA,OAAOO,SAASC,IAAI,CAClB;QACE,kBAAkB;QAClBC,SAAS;IACX,GACA;QACEC,QAAQd,WAAWe,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/forgotPassword.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { forgotPasswordOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const forgotPassword: CollectionRouteHandler = async ({ collection, req }) => {\n const { t } = req\n await forgotPasswordOperation({\n collection,\n data: {\n email: req.data.email as string,\n },\n disableEmail: Boolean(req.data?.disableEmail),\n expiration: typeof req.data.expiration === 'number' ? req.data.expiration : undefined,\n req,\n })\n\n return Response.json(\n {\n message: t('general:success'),\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","forgotPasswordOperation","headersWithCors","forgotPassword","collection","req","t","data","email","disableEmail","Boolean","expiration","undefined","Response","json","message","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,uBAAuB,QAAQ,qBAAoB;AAI5D,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,iBAAyC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAC9E,MAAM,EAAEC,CAAC,EAAE,GAAGD;IACd,MAAMJ,wBAAwB;QAC5BG;QACAG,MAAM;YACJC,OAAOH,IAAIE,IAAI,CAACC,KAAK;QACvB;QACAC,cAAcC,QAAQL,IAAIE,IAAI,EAAEE;QAChCE,YAAY,OAAON,IAAIE,IAAI,CAACI,UAAU,KAAK,WAAWN,IAAIE,IAAI,CAACI,UAAU,GAAGC;QAC5EP;IACF;IAEA,OAAOQ,SAASC,IAAI,CAClB;QACEC,SAAST,EAAE;IACb,GACA;QACEU,SAASd,gBAAgB;YACvBc,SAAS,IAAIC;YACbZ;QACF;QACAa,QAAQlB,WAAWmB,EAAE;IACvB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,IAAI,EAAE,sBAOlB,CAAA"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,IAAI,EAAE,sBAelB,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { initOperation } from 'payload/operations';
2
+ import { headersWithCors } from '../../../utilities/headersWithCors.js';
2
3
  export const init = async ({ collection, req })=>{
3
4
  const initialized = await initOperation({
4
5
  collection: collection.config.slug,
@@ -6,6 +7,11 @@ export const init = async ({ collection, req })=>{
6
7
  });
7
8
  return Response.json({
8
9
  initialized
10
+ }, {
11
+ headers: headersWithCors({
12
+ headers: new Headers(),
13
+ req
14
+ })
9
15
  });
10
16
  };
11
17
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/init.ts"],"sourcesContent":["import { initOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const init: CollectionRouteHandler = async ({ collection, req }) => {\n const initialized = await initOperation({\n collection: collection.config.slug,\n req,\n })\n\n return Response.json({ initialized })\n}\n"],"names":["initOperation","init","collection","req","initialized","config","slug","Response","json"],"rangeMappings":";;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAoB;AAIlD,OAAO,MAAMC,OAA+B,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACpE,MAAMC,cAAc,MAAMJ,cAAc;QACtCE,YAAYA,WAAWG,MAAM,CAACC,IAAI;QAClCH;IACF;IAEA,OAAOI,SAASC,IAAI,CAAC;QAAEJ;IAAY;AACrC,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/init.ts"],"sourcesContent":["import { initOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const init: CollectionRouteHandler = async ({ collection, req }) => {\n const initialized = await initOperation({\n collection: collection.config.slug,\n req,\n })\n\n return Response.json(\n { initialized },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n },\n )\n}\n"],"names":["initOperation","headersWithCors","init","collection","req","initialized","config","slug","Response","json","headers","Headers"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAoB;AAIlD,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,OAA+B,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACpE,MAAMC,cAAc,MAAML,cAAc;QACtCG,YAAYA,WAAWG,MAAM,CAACC,IAAI;QAClCH;IACF;IAEA,OAAOI,SAASC,IAAI,CAClB;QAAEJ;IAAY,GACd;QACEK,SAAST,gBAAgB;YACvBS,SAAS,IAAIC;YACbP;QACF;IACF;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/login.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,KAAK,EAAE,sBAqCnB,CAAA"}
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/login.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,KAAK,EAAE,sBAuCnB,CAAA"}
@@ -2,8 +2,9 @@ import httpStatus from 'http-status';
2
2
  import { generatePayloadCookie } from 'payload/auth';
3
3
  import { loginOperation } from 'payload/operations';
4
4
  import { isNumber } from 'payload/utilities';
5
+ import { headersWithCors } from '../../../utilities/headersWithCors.js';
5
6
  export const login = async ({ collection, req })=>{
6
- const { searchParams } = req;
7
+ const { searchParams, t } = req;
7
8
  const depth = searchParams.get('depth');
8
9
  const result = await loginOperation({
9
10
  collection,
@@ -23,12 +24,14 @@ export const login = async ({ collection, req })=>{
23
24
  delete result.token;
24
25
  }
25
26
  return Response.json({
26
- // TODO(translate)
27
- message: 'Auth Passed',
27
+ message: t('authentication:passed'),
28
28
  ...result
29
29
  }, {
30
- headers: new Headers({
31
- 'Set-Cookie': cookie
30
+ headers: headersWithCors({
31
+ headers: new Headers({
32
+ 'Set-Cookie': cookie
33
+ }),
34
+ req
32
35
  }),
33
36
  status: httpStatus.OK
34
37
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/login.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie } from 'payload/auth'\nimport { loginOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const login: CollectionRouteHandler = async ({ collection, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await loginOperation({\n collection,\n data: {\n email: typeof req.data?.email === 'string' ? req.data.email : '',\n password: typeof req.data?.password === 'string' ? req.data.password : '',\n },\n depth: isNumber(depth) ? Number(depth) : undefined,\n req,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.token,\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.token\n }\n\n return Response.json(\n {\n // TODO(translate)\n message: 'Auth Passed',\n ...result,\n },\n {\n headers: new Headers({\n 'Set-Cookie': cookie,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generatePayloadCookie","loginOperation","isNumber","login","collection","req","searchParams","depth","get","result","data","email","password","Number","undefined","cookie","collectionConfig","config","payload","token","auth","removeTokenFromResponses","Response","json","message","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,cAAc,QAAQ,qBAAoB;AACnD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,OAAO,MAAMC,QAAgC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACrE,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMC,SAAS,MAAMR,eAAe;QAClCG;QACAM,MAAM;YACJC,OAAO,OAAON,IAAIK,IAAI,EAAEC,UAAU,WAAWN,IAAIK,IAAI,CAACC,KAAK,GAAG;YAC9DC,UAAU,OAAOP,IAAIK,IAAI,EAAEE,aAAa,WAAWP,IAAIK,IAAI,CAACE,QAAQ,GAAG;QACzE;QACAL,OAAOL,SAASK,SAASM,OAAON,SAASO;QACzCT;IACF;IAEA,MAAMU,SAASf,sBAAsB;QACnCgB,kBAAkBZ,WAAWa,MAAM;QACnCC,SAASb,IAAIa,OAAO;QACpBC,OAAOV,OAAOU,KAAK;IACrB;IAEA,IAAIf,WAAWa,MAAM,CAACG,IAAI,CAACC,wBAAwB,EAAE;QACnD,OAAOZ,OAAOU,KAAK;IACrB;IAEA,OAAOG,SAASC,IAAI,CAClB;QACE,kBAAkB;QAClBC,SAAS;QACT,GAAGf,MAAM;IACX,GACA;QACEgB,SAAS,IAAIC,QAAQ;YACnB,cAAcX;QAChB;QACAY,QAAQ5B,WAAW6B,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/login.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie } from 'payload/auth'\nimport { loginOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const login: CollectionRouteHandler = async ({ collection, req }) => {\n const { searchParams, t } = req\n const depth = searchParams.get('depth')\n\n const result = await loginOperation({\n collection,\n data: {\n email: typeof req.data?.email === 'string' ? req.data.email : '',\n password: typeof req.data?.password === 'string' ? req.data.password : '',\n },\n depth: isNumber(depth) ? Number(depth) : undefined,\n req,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.token,\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.token\n }\n\n return Response.json(\n {\n message: t('authentication:passed'),\n ...result,\n },\n {\n headers: headersWithCors({\n headers: new Headers({\n 'Set-Cookie': cookie,\n }),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generatePayloadCookie","loginOperation","isNumber","headersWithCors","login","collection","req","searchParams","t","depth","get","result","data","email","password","Number","undefined","cookie","collectionConfig","config","payload","token","auth","removeTokenFromResponses","Response","json","message","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,cAAc,QAAQ,qBAAoB;AACnD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,QAAgC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACrE,MAAM,EAAEC,YAAY,EAAEC,CAAC,EAAE,GAAGF;IAC5B,MAAMG,QAAQF,aAAaG,GAAG,CAAC;IAE/B,MAAMC,SAAS,MAAMV,eAAe;QAClCI;QACAO,MAAM;YACJC,OAAO,OAAOP,IAAIM,IAAI,EAAEC,UAAU,WAAWP,IAAIM,IAAI,CAACC,KAAK,GAAG;YAC9DC,UAAU,OAAOR,IAAIM,IAAI,EAAEE,aAAa,WAAWR,IAAIM,IAAI,CAACE,QAAQ,GAAG;QACzE;QACAL,OAAOP,SAASO,SAASM,OAAON,SAASO;QACzCV;IACF;IAEA,MAAMW,SAASjB,sBAAsB;QACnCkB,kBAAkBb,WAAWc,MAAM;QACnCC,SAASd,IAAIc,OAAO;QACpBC,OAAOV,OAAOU,KAAK;IACrB;IAEA,IAAIhB,WAAWc,MAAM,CAACG,IAAI,CAACC,wBAAwB,EAAE;QACnD,OAAOZ,OAAOU,KAAK;IACrB;IAEA,OAAOG,SAASC,IAAI,CAClB;QACEC,SAASlB,EAAE;QACX,GAAGG,MAAM;IACX,GACA;QACEgB,SAASxB,gBAAgB;YACvBwB,SAAS,IAAIC,QAAQ;gBACnB,cAAcX;YAChB;YACAX;QACF;QACAuB,QAAQ9B,WAAW+B,EAAE;IACvB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/logout.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,MAAM,EAAE,sBAkCpB,CAAA"}
1
+ {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/logout.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,MAAM,EAAE,sBAwCpB,CAAA"}
@@ -1,15 +1,22 @@
1
1
  import httpStatus from 'http-status';
2
2
  import { generateExpiredPayloadCookie } from 'payload/auth';
3
3
  import { logoutOperation } from 'payload/operations';
4
+ import { headersWithCors } from '../../../utilities/headersWithCors.js';
4
5
  export const logout = async ({ collection, req })=>{
6
+ const { t } = req;
5
7
  const result = await logoutOperation({
6
8
  collection,
7
9
  req
8
10
  });
11
+ const headers = headersWithCors({
12
+ headers: new Headers(),
13
+ req
14
+ });
9
15
  if (!result) {
10
16
  return Response.json({
11
- message: 'Logout failed.'
17
+ message: t('error:logoutFailed')
12
18
  }, {
19
+ headers,
13
20
  status: httpStatus.BAD_REQUEST
14
21
  });
15
22
  }
@@ -17,13 +24,11 @@ export const logout = async ({ collection, req })=>{
17
24
  collectionConfig: collection.config,
18
25
  payload: req.payload
19
26
  });
27
+ headers.set('Set-Cookie', expiredCookie);
20
28
  return Response.json({
21
- // TODO(translate)
22
- message: 'Logout successful.'
29
+ message: t('authentication:logoutSuccessful')
23
30
  }, {
24
- headers: new Headers({
25
- 'Set-Cookie': expiredCookie
26
- }),
31
+ headers,
27
32
  status: httpStatus.OK
28
33
  });
29
34
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/logout.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generateExpiredPayloadCookie } from 'payload/auth'\nimport { logoutOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const logout: CollectionRouteHandler = async ({ collection, req }) => {\n const result = await logoutOperation({\n collection,\n req,\n })\n\n if (!result) {\n return Response.json(\n {\n message: 'Logout failed.',\n },\n {\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n const expiredCookie = generateExpiredPayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n })\n\n return Response.json(\n {\n // TODO(translate)\n message: 'Logout successful.',\n },\n {\n headers: new Headers({\n 'Set-Cookie': expiredCookie,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generateExpiredPayloadCookie","logoutOperation","logout","collection","req","result","Response","json","message","status","BAD_REQUEST","expiredCookie","collectionConfig","config","payload","headers","Headers","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,eAAe,QAAQ,qBAAoB;AAIpD,OAAO,MAAMC,SAAiC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACtE,MAAMC,SAAS,MAAMJ,gBAAgB;QACnCE;QACAC;IACF;IAEA,IAAI,CAACC,QAAQ;QACX,OAAOC,SAASC,IAAI,CAClB;YACEC,SAAS;QACX,GACA;YACEC,QAAQV,WAAWW,WAAW;QAChC;IAEJ;IAEA,MAAMC,gBAAgBX,6BAA6B;QACjDY,kBAAkBT,WAAWU,MAAM;QACnCC,SAASV,IAAIU,OAAO;IACtB;IAEA,OAAOR,SAASC,IAAI,CAClB;QACE,kBAAkB;QAClBC,SAAS;IACX,GACA;QACEO,SAAS,IAAIC,QAAQ;YACnB,cAAcL;QAChB;QACAF,QAAQV,WAAWkB,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/logout.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generateExpiredPayloadCookie } from 'payload/auth'\nimport { logoutOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const logout: CollectionRouteHandler = async ({ collection, req }) => {\n const { t } = req\n const result = await logoutOperation({\n collection,\n req,\n })\n\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n if (!result) {\n return Response.json(\n {\n message: t('error:logoutFailed'),\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n const expiredCookie = generateExpiredPayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n })\n\n headers.set('Set-Cookie', expiredCookie)\n\n return Response.json(\n {\n message: t('authentication:logoutSuccessful'),\n },\n {\n headers,\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generateExpiredPayloadCookie","logoutOperation","headersWithCors","logout","collection","req","t","result","headers","Headers","Response","json","message","status","BAD_REQUEST","expiredCookie","collectionConfig","config","payload","set","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,eAAe,QAAQ,qBAAoB;AAIpD,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,SAAiC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACtE,MAAM,EAAEC,CAAC,EAAE,GAAGD;IACd,MAAME,SAAS,MAAMN,gBAAgB;QACnCG;QACAC;IACF;IAEA,MAAMG,UAAUN,gBAAgB;QAC9BM,SAAS,IAAIC;QACbJ;IACF;IAEA,IAAI,CAACE,QAAQ;QACX,OAAOG,SAASC,IAAI,CAClB;YACEC,SAASN,EAAE;QACb,GACA;YACEE;YACAK,QAAQd,WAAWe,WAAW;QAChC;IAEJ;IAEA,MAAMC,gBAAgBf,6BAA6B;QACjDgB,kBAAkBZ,WAAWa,MAAM;QACnCC,SAASb,IAAIa,OAAO;IACtB;IAEAV,QAAQW,GAAG,CAAC,cAAcJ;IAE1B,OAAOL,SAASC,IAAI,CAClB;QACEC,SAASN,EAAE;IACb,GACA;QACEE;QACAK,QAAQd,WAAWqB,EAAE;IACvB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"me.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/me.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,EAAE,EAAE,sBAsBhB,CAAA"}
1
+ {"version":3,"file":"me.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/me.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,EAAE,EAAE,sBA0BhB,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import httpStatus from 'http-status';
2
2
  import { extractJWT } from 'payload/auth';
3
3
  import { meOperation } from 'payload/operations';
4
+ import { headersWithCors } from '../../../utilities/headersWithCors.js';
4
5
  export const me = async ({ collection, req })=>{
5
6
  const currentToken = extractJWT(req);
6
7
  const result = await meOperation({
@@ -15,6 +16,10 @@ export const me = async ({ collection, req })=>{
15
16
  ...result,
16
17
  message: req.t('authentication:account')
17
18
  }, {
19
+ headers: headersWithCors({
20
+ headers: new Headers(),
21
+ req
22
+ }),
18
23
  status: httpStatus.OK
19
24
  });
20
25
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/me.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { extractJWT } from 'payload/auth'\nimport { meOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const me: CollectionRouteHandler = async ({ collection, req }) => {\n const currentToken = extractJWT(req)\n\n const result = await meOperation({\n collection,\n currentToken,\n req,\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.token\n }\n\n return Response.json(\n {\n ...result,\n message: req.t('authentication:account'),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","extractJWT","meOperation","me","collection","req","currentToken","result","config","auth","removeTokenFromResponses","token","Response","json","message","t","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,WAAW,QAAQ,qBAAoB;AAIhD,OAAO,MAAMC,KAA6B,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAClE,MAAMC,eAAeL,WAAWI;IAEhC,MAAME,SAAS,MAAML,YAAY;QAC/BE;QACAE;QACAD;IACF;IAEA,IAAID,WAAWI,MAAM,CAACC,IAAI,CAACC,wBAAwB,EAAE;QACnD,OAAOH,OAAOI,KAAK;IACrB;IAEA,OAAOC,SAASC,IAAI,CAClB;QACE,GAAGN,MAAM;QACTO,SAAST,IAAIU,CAAC,CAAC;IACjB,GACA;QACEC,QAAQhB,WAAWiB,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/me.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { extractJWT } from 'payload/auth'\nimport { meOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const me: CollectionRouteHandler = async ({ collection, req }) => {\n const currentToken = extractJWT(req)\n\n const result = await meOperation({\n collection,\n currentToken,\n req,\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.token\n }\n\n return Response.json(\n {\n ...result,\n message: req.t('authentication:account'),\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","extractJWT","meOperation","headersWithCors","me","collection","req","currentToken","result","config","auth","removeTokenFromResponses","token","Response","json","message","t","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,WAAW,QAAQ,qBAAoB;AAIhD,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,KAA6B,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAClE,MAAMC,eAAeN,WAAWK;IAEhC,MAAME,SAAS,MAAMN,YAAY;QAC/BG;QACAE;QACAD;IACF;IAEA,IAAID,WAAWI,MAAM,CAACC,IAAI,CAACC,wBAAwB,EAAE;QACnD,OAAOH,OAAOI,KAAK;IACrB;IAEA,OAAOC,SAASC,IAAI,CAClB;QACE,GAAGN,MAAM;QACTO,SAAST,IAAIU,CAAC,CAAC;IACjB,GACA;QACEC,SAASd,gBAAgB;YACvBc,SAAS,IAAIC;YACbZ;QACF;QACAa,QAAQnB,WAAWoB,EAAE;IACvB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/refresh.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,OAAO,EAAE,sBA4CrB,CAAA"}
1
+ {"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/refresh.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,OAAO,EAAE,sBAiDrB,CAAA"}
@@ -2,13 +2,19 @@ import httpStatus from 'http-status';
2
2
  import { extractJWT } from 'payload/auth';
3
3
  import { generatePayloadCookie } from 'payload/auth';
4
4
  import { refreshOperation } from 'payload/operations';
5
+ import { headersWithCors } from '../../../utilities/headersWithCors.js';
5
6
  export const refresh = async ({ collection, req })=>{
7
+ const { t } = req;
6
8
  const token = typeof req.data?.token === 'string' ? req.data.token : extractJWT(req);
9
+ const headers = headersWithCors({
10
+ headers: new Headers(),
11
+ req
12
+ });
7
13
  if (!token) {
8
14
  return Response.json({
9
- // TODO(translate)
10
- message: 'Token not provided.'
15
+ message: t('error:tokenNotProvided')
11
16
  }, {
17
+ headers,
12
18
  status: httpStatus.UNAUTHORIZED
13
19
  });
14
20
  }
@@ -25,14 +31,12 @@ export const refresh = async ({ collection, req })=>{
25
31
  if (collection.config.auth.removeTokenFromResponses) {
26
32
  delete result.refreshedToken;
27
33
  }
34
+ headers.set('Set-Cookie', cookie);
28
35
  return Response.json({
29
- // TODO(translate)
30
- message: 'Token refresh successful',
36
+ message: t('authentication:tokenRefreshSuccessful'),
31
37
  ...result
32
38
  }, {
33
- headers: new Headers({
34
- 'Set-Cookie': cookie
35
- }),
39
+ headers,
36
40
  status: httpStatus.OK
37
41
  });
38
42
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/refresh.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { extractJWT } from 'payload/auth'\nimport { generatePayloadCookie } from 'payload/auth'\nimport { refreshOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const refresh: CollectionRouteHandler = async ({ collection, req }) => {\n const token = typeof req.data?.token === 'string' ? req.data.token : extractJWT(req)\n\n if (!token) {\n return Response.json(\n {\n // TODO(translate)\n message: 'Token not provided.',\n },\n {\n status: httpStatus.UNAUTHORIZED,\n },\n )\n }\n\n const result = await refreshOperation({\n collection,\n req,\n token,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.refreshedToken,\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.refreshedToken\n }\n\n return Response.json(\n {\n // TODO(translate)\n message: 'Token refresh successful',\n ...result,\n },\n {\n headers: new Headers({\n 'Set-Cookie': cookie,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","extractJWT","generatePayloadCookie","refreshOperation","refresh","collection","req","token","data","Response","json","message","status","UNAUTHORIZED","result","cookie","collectionConfig","config","payload","refreshedToken","auth","removeTokenFromResponses","headers","Headers","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,gBAAgB,QAAQ,qBAAoB;AAIrD,OAAO,MAAMC,UAAkC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACvE,MAAMC,QAAQ,OAAOD,IAAIE,IAAI,EAAED,UAAU,WAAWD,IAAIE,IAAI,CAACD,KAAK,GAAGN,WAAWK;IAEhF,IAAI,CAACC,OAAO;QACV,OAAOE,SAASC,IAAI,CAClB;YACE,kBAAkB;YAClBC,SAAS;QACX,GACA;YACEC,QAAQZ,WAAWa,YAAY;QACjC;IAEJ;IAEA,MAAMC,SAAS,MAAMX,iBAAiB;QACpCE;QACAC;QACAC;IACF;IAEA,MAAMQ,SAASb,sBAAsB;QACnCc,kBAAkBX,WAAWY,MAAM;QACnCC,SAASZ,IAAIY,OAAO;QACpBX,OAAOO,OAAOK,cAAc;IAC9B;IAEA,IAAId,WAAWY,MAAM,CAACG,IAAI,CAACC,wBAAwB,EAAE;QACnD,OAAOP,OAAOK,cAAc;IAC9B;IAEA,OAAOV,SAASC,IAAI,CAClB;QACE,kBAAkB;QAClBC,SAAS;QACT,GAAGG,MAAM;IACX,GACA;QACEQ,SAAS,IAAIC,QAAQ;YACnB,cAAcR;QAChB;QACAH,QAAQZ,WAAWwB,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/refresh.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { extractJWT } from 'payload/auth'\nimport { generatePayloadCookie } from 'payload/auth'\nimport { refreshOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const refresh: CollectionRouteHandler = async ({ collection, req }) => {\n const { t } = req\n const token = typeof req.data?.token === 'string' ? req.data.token : extractJWT(req)\n\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n if (!token) {\n return Response.json(\n {\n message: t('error:tokenNotProvided'),\n },\n {\n headers,\n status: httpStatus.UNAUTHORIZED,\n },\n )\n }\n\n const result = await refreshOperation({\n collection,\n req,\n token,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.refreshedToken,\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.refreshedToken\n }\n\n headers.set('Set-Cookie', cookie)\n\n return Response.json(\n {\n message: t('authentication:tokenRefreshSuccessful'),\n ...result,\n },\n {\n headers,\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","extractJWT","generatePayloadCookie","refreshOperation","headersWithCors","refresh","collection","req","t","token","data","headers","Headers","Response","json","message","status","UNAUTHORIZED","result","cookie","collectionConfig","config","payload","refreshedToken","auth","removeTokenFromResponses","set","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,gBAAgB,QAAQ,qBAAoB;AAIrD,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,UAAkC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACvE,MAAM,EAAEC,CAAC,EAAE,GAAGD;IACd,MAAME,QAAQ,OAAOF,IAAIG,IAAI,EAAED,UAAU,WAAWF,IAAIG,IAAI,CAACD,KAAK,GAAGR,WAAWM;IAEhF,MAAMI,UAAUP,gBAAgB;QAC9BO,SAAS,IAAIC;QACbL;IACF;IAEA,IAAI,CAACE,OAAO;QACV,OAAOI,SAASC,IAAI,CAClB;YACEC,SAASP,EAAE;QACb,GACA;YACEG;YACAK,QAAQhB,WAAWiB,YAAY;QACjC;IAEJ;IAEA,MAAMC,SAAS,MAAMf,iBAAiB;QACpCG;QACAC;QACAE;IACF;IAEA,MAAMU,SAASjB,sBAAsB;QACnCkB,kBAAkBd,WAAWe,MAAM;QACnCC,SAASf,IAAIe,OAAO;QACpBb,OAAOS,OAAOK,cAAc;IAC9B;IAEA,IAAIjB,WAAWe,MAAM,CAACG,IAAI,CAACC,wBAAwB,EAAE;QACnD,OAAOP,OAAOK,cAAc;IAC9B;IAEAZ,QAAQe,GAAG,CAAC,cAAcP;IAE1B,OAAON,SAASC,IAAI,CAClB;QACEC,SAASP,EAAE;QACX,GAAGU,MAAM;IACX,GACA;QACEP;QACAK,QAAQhB,WAAW2B,EAAE;IACvB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"registerFirstUser.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,iBAAiB,EAAE,sBAkC/B,CAAA"}
1
+ {"version":3,"file":"registerFirstUser.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,iBAAiB,EAAE,sBA6C/B,CAAA"}
@@ -1,8 +1,18 @@
1
1
  import httpStatus from 'http-status';
2
2
  import { generatePayloadCookie } from 'payload/auth';
3
+ import { ValidationError } from 'payload/errors';
3
4
  import { registerFirstUserOperation } from 'payload/operations';
5
+ import { headersWithCors } from '../../../utilities/headersWithCors.js';
4
6
  export const registerFirstUser = async ({ collection, req })=>{
5
- const data = req.data;
7
+ const { data, t } = req;
8
+ if (data?.password !== data['confirm-password']) {
9
+ throw new ValidationError([
10
+ {
11
+ field: 'confirm-password',
12
+ message: req.t('Password and confirm password fields do not match.')
13
+ }
14
+ ]);
15
+ }
6
16
  const result = await registerFirstUserOperation({
7
17
  collection,
8
18
  data: {
@@ -19,13 +29,15 @@ export const registerFirstUser = async ({ collection, req })=>{
19
29
  });
20
30
  return Response.json({
21
31
  exp: result.exp,
22
- // TODO(translate)
23
- message: 'Successfully registered first user.',
32
+ message: t('authentication:successfullyRegisteredFirstUser'),
24
33
  token: result.token,
25
34
  user: result.user
26
35
  }, {
27
- headers: new Headers({
28
- 'Set-Cookie': cookie
36
+ headers: headersWithCors({
37
+ headers: new Headers({
38
+ 'Set-Cookie': cookie
39
+ }),
40
+ req
29
41
  }),
30
42
  status: httpStatus.OK
31
43
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie } from 'payload/auth'\nimport { registerFirstUserOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const registerFirstUser: CollectionRouteHandler = async ({ collection, req }) => {\n const data = req.data\n\n const result = await registerFirstUserOperation({\n collection,\n data: {\n ...data,\n email: typeof data?.email === 'string' ? data.email : '',\n password: typeof data?.password === 'string' ? data.password : '',\n },\n req,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.token,\n })\n\n return Response.json(\n {\n exp: result.exp,\n // TODO(translate)\n message: 'Successfully registered first user.',\n token: result.token,\n user: result.user,\n },\n {\n headers: new Headers({\n 'Set-Cookie': cookie,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generatePayloadCookie","registerFirstUserOperation","registerFirstUser","collection","req","data","result","email","password","cookie","collectionConfig","config","payload","token","Response","json","exp","message","user","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,0BAA0B,QAAQ,qBAAoB;AAI/D,OAAO,MAAMC,oBAA4C,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACjF,MAAMC,OAAOD,IAAIC,IAAI;IAErB,MAAMC,SAAS,MAAML,2BAA2B;QAC9CE;QACAE,MAAM;YACJ,GAAGA,IAAI;YACPE,OAAO,OAAOF,MAAME,UAAU,WAAWF,KAAKE,KAAK,GAAG;YACtDC,UAAU,OAAOH,MAAMG,aAAa,WAAWH,KAAKG,QAAQ,GAAG;QACjE;QACAJ;IACF;IAEA,MAAMK,SAAST,sBAAsB;QACnCU,kBAAkBP,WAAWQ,MAAM;QACnCC,SAASR,IAAIQ,OAAO;QACpBC,OAAOP,OAAOO,KAAK;IACrB;IAEA,OAAOC,SAASC,IAAI,CAClB;QACEC,KAAKV,OAAOU,GAAG;QACf,kBAAkB;QAClBC,SAAS;QACTJ,OAAOP,OAAOO,KAAK;QACnBK,MAAMZ,OAAOY,IAAI;IACnB,GACA;QACEC,SAAS,IAAIC,QAAQ;YACnB,cAAcX;QAChB;QACAY,QAAQtB,WAAWuB,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/registerFirstUser.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie } from 'payload/auth'\nimport { ValidationError } from 'payload/errors'\nimport { registerFirstUserOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const registerFirstUser: CollectionRouteHandler = async ({ collection, req }) => {\n const { data, t } = req\n\n if (data?.password !== data['confirm-password']) {\n throw new ValidationError([\n {\n field: 'confirm-password',\n message: req.t('Password and confirm password fields do not match.'),\n },\n ])\n }\n\n const result = await registerFirstUserOperation({\n collection,\n data: {\n ...data,\n email: typeof data?.email === 'string' ? data.email : '',\n password: typeof data?.password === 'string' ? data.password : '',\n },\n req,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.token,\n })\n\n return Response.json(\n {\n exp: result.exp,\n message: t('authentication:successfullyRegisteredFirstUser'),\n token: result.token,\n user: result.user,\n },\n {\n headers: headersWithCors({\n headers: new Headers({\n 'Set-Cookie': cookie,\n }),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generatePayloadCookie","ValidationError","registerFirstUserOperation","headersWithCors","registerFirstUser","collection","req","data","t","password","field","message","result","email","cookie","collectionConfig","config","payload","token","Response","json","exp","user","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,eAAe,QAAQ,iBAAgB;AAChD,SAASC,0BAA0B,QAAQ,qBAAoB;AAI/D,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,oBAA4C,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACjF,MAAM,EAAEC,IAAI,EAAEC,CAAC,EAAE,GAAGF;IAEpB,IAAIC,MAAME,aAAaF,IAAI,CAAC,mBAAmB,EAAE;QAC/C,MAAM,IAAIN,gBAAgB;YACxB;gBACES,OAAO;gBACPC,SAASL,IAAIE,CAAC,CAAC;YACjB;SACD;IACH;IAEA,MAAMI,SAAS,MAAMV,2BAA2B;QAC9CG;QACAE,MAAM;YACJ,GAAGA,IAAI;YACPM,OAAO,OAAON,MAAMM,UAAU,WAAWN,KAAKM,KAAK,GAAG;YACtDJ,UAAU,OAAOF,MAAME,aAAa,WAAWF,KAAKE,QAAQ,GAAG;QACjE;QACAH;IACF;IAEA,MAAMQ,SAASd,sBAAsB;QACnCe,kBAAkBV,WAAWW,MAAM;QACnCC,SAASX,IAAIW,OAAO;QACpBC,OAAON,OAAOM,KAAK;IACrB;IAEA,OAAOC,SAASC,IAAI,CAClB;QACEC,KAAKT,OAAOS,GAAG;QACfV,SAASH,EAAE;QACXU,OAAON,OAAOM,KAAK;QACnBI,MAAMV,OAAOU,IAAI;IACnB,GACA;QACEC,SAASpB,gBAAgB;YACvBoB,SAAS,IAAIC,QAAQ;gBACnB,cAAcV;YAChB;YACAR;QACF;QACAmB,QAAQ1B,WAAW2B,EAAE;IACvB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/resetPassword.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,aAAa,EAAE,sBAqC3B,CAAA"}
1
+ {"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/resetPassword.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,aAAa,EAAE,sBAuC3B,CAAA"}
@@ -1,8 +1,9 @@
1
1
  import httpStatus from 'http-status';
2
2
  import { generatePayloadCookie } from 'payload/auth';
3
3
  import { resetPasswordOperation } from 'payload/operations';
4
+ import { headersWithCors } from '../../../utilities/headersWithCors.js';
4
5
  export const resetPassword = async ({ collection, req })=>{
5
- const { searchParams } = req;
6
+ const { searchParams, t } = req;
6
7
  const depth = searchParams.get('depth');
7
8
  const result = await resetPasswordOperation({
8
9
  collection,
@@ -22,12 +23,14 @@ export const resetPassword = async ({ collection, req })=>{
22
23
  delete result.token;
23
24
  }
24
25
  return Response.json({
25
- // TODO(translate)
26
- message: 'Password reset successfully.',
26
+ message: t('authentication:passwordResetSuccessfully'),
27
27
  ...result
28
28
  }, {
29
- headers: new Headers({
30
- 'Set-Cookie': cookie
29
+ headers: headersWithCors({
30
+ headers: new Headers({
31
+ 'Set-Cookie': cookie
32
+ }),
33
+ req
31
34
  }),
32
35
  status: httpStatus.OK
33
36
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/resetPassword.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie } from 'payload/auth'\nimport { resetPasswordOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const resetPassword: CollectionRouteHandler = async ({ collection, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await resetPasswordOperation({\n collection,\n data: {\n password: typeof req.data?.password === 'string' ? req.data.password : '',\n token: typeof req.data?.token === 'string' ? req.data.token : '',\n },\n depth: depth ? Number(depth) : undefined,\n req,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.token,\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.token\n }\n\n return Response.json(\n {\n // TODO(translate)\n message: 'Password reset successfully.',\n ...result,\n },\n {\n headers: new Headers({\n 'Set-Cookie': cookie,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generatePayloadCookie","resetPasswordOperation","resetPassword","collection","req","searchParams","depth","get","result","data","password","token","Number","undefined","cookie","collectionConfig","config","payload","auth","removeTokenFromResponses","Response","json","message","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,sBAAsB,QAAQ,qBAAoB;AAI3D,OAAO,MAAMC,gBAAwC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAC7E,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMC,SAAS,MAAMP,uBAAuB;QAC1CE;QACAM,MAAM;YACJC,UAAU,OAAON,IAAIK,IAAI,EAAEC,aAAa,WAAWN,IAAIK,IAAI,CAACC,QAAQ,GAAG;YACvEC,OAAO,OAAOP,IAAIK,IAAI,EAAEE,UAAU,WAAWP,IAAIK,IAAI,CAACE,KAAK,GAAG;QAChE;QACAL,OAAOA,QAAQM,OAAON,SAASO;QAC/BT;IACF;IAEA,MAAMU,SAASd,sBAAsB;QACnCe,kBAAkBZ,WAAWa,MAAM;QACnCC,SAASb,IAAIa,OAAO;QACpBN,OAAOH,OAAOG,KAAK;IACrB;IAEA,IAAIR,WAAWa,MAAM,CAACE,IAAI,CAACC,wBAAwB,EAAE;QACnD,OAAOX,OAAOG,KAAK;IACrB;IAEA,OAAOS,SAASC,IAAI,CAClB;QACE,kBAAkB;QAClBC,SAAS;QACT,GAAGd,MAAM;IACX,GACA;QACEe,SAAS,IAAIC,QAAQ;YACnB,cAAcV;QAChB;QACAW,QAAQ1B,WAAW2B,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/resetPassword.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generatePayloadCookie } from 'payload/auth'\nimport { resetPasswordOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const resetPassword: CollectionRouteHandler = async ({ collection, req }) => {\n const { searchParams, t } = req\n const depth = searchParams.get('depth')\n\n const result = await resetPasswordOperation({\n collection,\n data: {\n password: typeof req.data?.password === 'string' ? req.data.password : '',\n token: typeof req.data?.token === 'string' ? req.data.token : '',\n },\n depth: depth ? Number(depth) : undefined,\n req,\n })\n\n const cookie = generatePayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n token: result.token,\n })\n\n if (collection.config.auth.removeTokenFromResponses) {\n delete result.token\n }\n\n return Response.json(\n {\n message: t('authentication:passwordResetSuccessfully'),\n ...result,\n },\n {\n headers: headersWithCors({\n headers: new Headers({\n 'Set-Cookie': cookie,\n }),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generatePayloadCookie","resetPasswordOperation","headersWithCors","resetPassword","collection","req","searchParams","t","depth","get","result","data","password","token","Number","undefined","cookie","collectionConfig","config","payload","auth","removeTokenFromResponses","Response","json","message","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,sBAAsB,QAAQ,qBAAoB;AAI3D,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,gBAAwC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IAC7E,MAAM,EAAEC,YAAY,EAAEC,CAAC,EAAE,GAAGF;IAC5B,MAAMG,QAAQF,aAAaG,GAAG,CAAC;IAE/B,MAAMC,SAAS,MAAMT,uBAAuB;QAC1CG;QACAO,MAAM;YACJC,UAAU,OAAOP,IAAIM,IAAI,EAAEC,aAAa,WAAWP,IAAIM,IAAI,CAACC,QAAQ,GAAG;YACvEC,OAAO,OAAOR,IAAIM,IAAI,EAAEE,UAAU,WAAWR,IAAIM,IAAI,CAACE,KAAK,GAAG;QAChE;QACAL,OAAOA,QAAQM,OAAON,SAASO;QAC/BV;IACF;IAEA,MAAMW,SAAShB,sBAAsB;QACnCiB,kBAAkBb,WAAWc,MAAM;QACnCC,SAASd,IAAIc,OAAO;QACpBN,OAAOH,OAAOG,KAAK;IACrB;IAEA,IAAIT,WAAWc,MAAM,CAACE,IAAI,CAACC,wBAAwB,EAAE;QACnD,OAAOX,OAAOG,KAAK;IACrB;IAEA,OAAOS,SAASC,IAAI,CAClB;QACEC,SAASjB,EAAE;QACX,GAAGG,MAAM;IACX,GACA;QACEe,SAASvB,gBAAgB;YACvBuB,SAAS,IAAIC,QAAQ;gBACnB,cAAcV;YAChB;YACAX;QACF;QACAsB,QAAQ5B,WAAW6B,EAAE;IACvB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"unlock.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/unlock.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,MAAM,EAAE,sBAgBpB,CAAA"}
1
+ {"version":3,"file":"unlock.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/unlock.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD,eAAO,MAAM,MAAM,EAAE,sBAqBpB,CAAA"}
@@ -1,6 +1,8 @@
1
1
  import httpStatus from 'http-status';
2
2
  import { unlockOperation } from 'payload/operations';
3
+ import { headersWithCors } from '../../../utilities/headersWithCors.js';
3
4
  export const unlock = async ({ collection, req })=>{
5
+ const { t } = req;
4
6
  await unlockOperation({
5
7
  collection,
6
8
  data: {
@@ -9,9 +11,12 @@ export const unlock = async ({ collection, req })=>{
9
11
  req
10
12
  });
11
13
  return Response.json({
12
- // TODO(translate)
13
- message: 'Success'
14
+ message: t('general:success')
14
15
  }, {
16
+ headers: headersWithCors({
17
+ headers: new Headers(),
18
+ req
19
+ }),
15
20
  status: httpStatus.OK
16
21
  });
17
22
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/unlock.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { unlockOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const unlock: CollectionRouteHandler = async ({ collection, req }) => {\n await unlockOperation({\n collection,\n data: { email: req.data.email as string },\n req,\n })\n\n return Response.json(\n {\n // TODO(translate)\n message: 'Success',\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","unlockOperation","unlock","collection","req","data","email","Response","json","message","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,eAAe,QAAQ,qBAAoB;AAIpD,OAAO,MAAMC,SAAiC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACtE,MAAMH,gBAAgB;QACpBE;QACAE,MAAM;YAAEC,OAAOF,IAAIC,IAAI,CAACC,KAAK;QAAW;QACxCF;IACF;IAEA,OAAOG,SAASC,IAAI,CAClB;QACE,kBAAkB;QAClBC,SAAS;IACX,GACA;QACEC,QAAQV,WAAWW,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/unlock.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { unlockOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const unlock: CollectionRouteHandler = async ({ collection, req }) => {\n const { t } = req\n\n await unlockOperation({\n collection,\n data: { email: req.data.email as string },\n req,\n })\n\n return Response.json(\n {\n message: t('general:success'),\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","unlockOperation","headersWithCors","unlock","collection","req","t","data","email","Response","json","message","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,eAAe,QAAQ,qBAAoB;AAIpD,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,SAAiC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACtE,MAAM,EAAEC,CAAC,EAAE,GAAGD;IAEd,MAAMJ,gBAAgB;QACpBG;QACAG,MAAM;YAAEC,OAAOH,IAAIE,IAAI,CAACC,KAAK;QAAW;QACxCH;IACF;IAEA,OAAOI,SAASC,IAAI,CAClB;QACEC,SAASL,EAAE;IACb,GACA;QACEM,SAASV,gBAAgB;YACvBU,SAAS,IAAIC;YACbR;QACF;QACAS,QAAQd,WAAWe,EAAE;IACvB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"verifyEmail.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/verifyEmail.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAE/D,eAAO,MAAM,WAAW,EAAE,4BAgBzB,CAAA"}
1
+ {"version":3,"file":"verifyEmail.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/auth/verifyEmail.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAI/D,eAAO,MAAM,WAAW,EAAE,4BAoBzB,CAAA"}
@@ -1,15 +1,20 @@
1
1
  import httpStatus from 'http-status';
2
2
  import { verifyEmailOperation } from 'payload/operations';
3
+ import { headersWithCors } from '../../../utilities/headersWithCors.js';
3
4
  export const verifyEmail = async ({ id, collection, req })=>{
5
+ const { t } = req;
4
6
  await verifyEmailOperation({
5
7
  collection,
6
8
  req,
7
9
  token: id
8
10
  });
9
11
  return Response.json({
10
- // TODO(translate)
11
- message: 'Email verified successfully.'
12
+ message: t('authentication:emailVerified')
12
13
  }, {
14
+ headers: headersWithCors({
15
+ headers: new Headers(),
16
+ req
17
+ }),
13
18
  status: httpStatus.OK
14
19
  });
15
20
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/routes/rest/auth/verifyEmail.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { verifyEmailOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nexport const verifyEmail: CollectionRouteHandlerWithID = async ({ id, collection, req }) => {\n await verifyEmailOperation({\n collection,\n req,\n token: id,\n })\n\n return Response.json(\n {\n // TODO(translate)\n message: 'Email verified successfully.',\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","verifyEmailOperation","verifyEmail","id","collection","req","token","Response","json","message","status","OK"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,oBAAoB,QAAQ,qBAAoB;AAIzD,OAAO,MAAMC,cAA4C,OAAO,EAAEC,EAAE,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACrF,MAAMJ,qBAAqB;QACzBG;QACAC;QACAC,OAAOH;IACT;IAEA,OAAOI,SAASC,IAAI,CAClB;QACE,kBAAkB;QAClBC,SAAS;IACX,GACA;QACEC,QAAQV,WAAWW,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../../src/routes/rest/auth/verifyEmail.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { verifyEmailOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { headersWithCors } from '../../../utilities/headersWithCors.js'\n\nexport const verifyEmail: CollectionRouteHandlerWithID = async ({ id, collection, req }) => {\n const { t } = req\n await verifyEmailOperation({\n collection,\n req,\n token: id,\n })\n\n return Response.json(\n {\n message: t('authentication:emailVerified'),\n },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","verifyEmailOperation","headersWithCors","verifyEmail","id","collection","req","t","token","Response","json","message","headers","Headers","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,oBAAoB,QAAQ,qBAAoB;AAIzD,SAASC,eAAe,QAAQ,wCAAuC;AAEvE,OAAO,MAAMC,cAA4C,OAAO,EAAEC,EAAE,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACrF,MAAM,EAAEC,CAAC,EAAE,GAAGD;IACd,MAAML,qBAAqB;QACzBI;QACAC;QACAE,OAAOJ;IACT;IAEA,OAAOK,SAASC,IAAI,CAClB;QACEC,SAASJ,EAAE;IACb,GACA;QACEK,SAASV,gBAAgB;YACvBU,SAAS,IAAIC;YACbP;QACF;QACAQ,QAAQd,WAAWe,EAAE;IACvB;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,cAAc,EAAc,MAAM,eAAe,CAAA;AAM3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAWlF,eAAO,MAAM,iBAAiB,QAAS,cAAc,mBAQpD,CAAA;AAED,eAAO,MAAM,cAAc,YAAmB;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,sBAwLpE,CAAA"}
1
+ {"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,cAAc,EAAc,MAAM,eAAe,CAAA;AAM3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAYlF,eAAO,MAAM,iBAAiB,QAAS,cAAc,mBAQpD,CAAA;AAED,eAAO,MAAM,cAAc,YAAmB;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,sBAmMpE,CAAA"}
@@ -2,6 +2,7 @@ import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'
2
2
  import { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues';
3
3
  import httpStatus from 'http-status';
4
4
  import { buildFieldSchemaMap } from '../../utilities/buildFieldSchemaMap/index.js';
5
+ import { headersWithCors } from '../../utilities/headersWithCors.js';
5
6
  let cached = global._payload_fieldSchemaMap;
6
7
  if (!cached) {
7
8
  // eslint-disable-next-line no-multi-assign
@@ -15,6 +16,10 @@ export const getFieldSchemaMap = (req)=>{
15
16
  return cached;
16
17
  };
17
18
  export const buildFormState = async ({ req })=>{
19
+ const headers = headersWithCors({
20
+ headers: new Headers(),
21
+ req
22
+ });
18
23
  try {
19
24
  const reqData = req.data;
20
25
  const { collectionSlug, formState, globalSlug, locale, operation, schemaPath } = reqData;
@@ -30,17 +35,20 @@ export const buildFormState = async ({ req })=>{
30
35
  });
31
36
  if (!canAccessAdmin) {
32
37
  return Response.json(null, {
38
+ headers,
33
39
  status: httpStatus.UNAUTHORIZED
34
40
  });
35
41
  }
36
42
  // Match the user collection to the global admin config
37
43
  } else if (adminUserSlug !== incomingUserSlug) {
38
44
  return Response.json(null, {
45
+ headers,
39
46
  status: httpStatus.UNAUTHORIZED
40
47
  });
41
48
  }
42
49
  } else {
43
50
  return Response.json(null, {
51
+ headers,
44
52
  status: httpStatus.UNAUTHORIZED
45
53
  });
46
54
  }
@@ -61,6 +69,7 @@ export const buildFormState = async ({ req })=>{
61
69
  return Response.json({
62
70
  message: 'Could not find field schema for given path'
63
71
  }, {
72
+ headers,
64
73
  status: httpStatus.BAD_REQUEST
65
74
  });
66
75
  }
@@ -150,12 +159,14 @@ export const buildFormState = async ({ req })=>{
150
159
  result.file = formState.file;
151
160
  }
152
161
  return Response.json(result, {
162
+ headers,
153
163
  status: httpStatus.OK
154
164
  });
155
165
  } catch (err) {
156
166
  return Response.json({
157
167
  message: 'There was an error building form state'
158
168
  }, {
169
+ headers,
159
170
  status: httpStatus.BAD_REQUEST
160
171
  });
161
172
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport type { DocumentPreferences, Field, PayloadRequest, TypeWithID } from 'payload/types'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport httpStatus from 'http-status'\n\nimport type { FieldSchemaMap } from '../../utilities/buildFieldSchemaMap/types.js'\n\nimport { buildFieldSchemaMap } from '../../utilities/buildFieldSchemaMap/index.js'\n\nlet cached = global._payload_fieldSchemaMap\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload_fieldSchemaMap = null\n}\n\nexport const getFieldSchemaMap = (req: PayloadRequest): FieldSchemaMap => {\n if (cached && process.env.NODE_ENV !== 'development') {\n return cached\n }\n\n cached = buildFieldSchemaMap(req)\n\n return cached\n}\n\nexport const buildFormState = async ({ req }: { req: PayloadRequest }) => {\n try {\n const reqData: BuildFormStateArgs = req.data as BuildFormStateArgs\n const { collectionSlug, formState, globalSlug, locale, operation, schemaPath } = reqData\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n return Response.json(null, {\n status: httpStatus.UNAUTHORIZED,\n })\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n return Response.json(null, {\n status: httpStatus.UNAUTHORIZED,\n })\n }\n } else {\n return Response.json(null, {\n status: httpStatus.UNAUTHORIZED,\n })\n }\n\n const fieldSchemaMap = getFieldSchemaMap(req)\n\n const id = collectionSlug ? reqData.id : undefined\n const schemaPathSegments = schemaPath.split('.')\n\n let fieldSchema: Field[]\n\n if (schemaPathSegments.length === 1) {\n if (req.payload.collections[schemaPath]) {\n fieldSchema = req.payload.collections[schemaPath].config.fields\n } else {\n fieldSchema = req.payload.config.globals.find(\n (global) => global.slug === schemaPath,\n )?.fields\n }\n } else if (fieldSchemaMap.has(schemaPath)) {\n fieldSchema = fieldSchemaMap.get(schemaPath)\n }\n\n if (!fieldSchema) {\n return Response.json(\n {\n message: 'Could not find field schema for given path',\n },\n {\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n let docPreferences = reqData.docPreferences\n let data = reqData.data\n\n const promises: {\n data?: Promise<void>\n preferences?: Promise<void>\n } = {}\n\n // If the request does not include doc preferences,\n // we should fetch them. This is useful for DocumentInfoProvider\n // as it reduces the amount of client-side fetches necessary\n // when we fetch data for the Edit view\n if (!docPreferences) {\n let preferencesKey\n\n if (collectionSlug && id) {\n preferencesKey = `collection-${collectionSlug}-${id}`\n }\n\n if (globalSlug) {\n preferencesKey = `global-${globalSlug}`\n }\n\n if (preferencesKey) {\n const fetchPreferences = async () => {\n const preferencesResult = (await req.payload.find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n where: {\n key: {\n equals: preferencesKey,\n },\n },\n })) as unknown as { docs: { value: DocumentPreferences }[] }\n\n if (preferencesResult?.docs?.[0]?.value) docPreferences = preferencesResult.docs[0].value\n }\n\n promises.preferences = fetchPreferences()\n }\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) data = reduceFieldsToValues(formState, true)\n\n // If we do not have data at this point,\n // we can fetch it. This is useful for DocumentInfoProvider\n // to reduce the amount of fetches required\n if (!data) {\n const fetchData = async () => {\n let resolvedData: TypeWithID\n\n if (collectionSlug && id) {\n resolvedData = await req.payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n if (globalSlug && schemaPath === globalSlug) {\n resolvedData = await req.payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n data = resolvedData\n }\n\n promises.data = fetchData()\n }\n\n if (Object.keys(promises).length > 0) {\n await Promise.all(Object.values(promises))\n }\n\n const result = await buildStateFromSchema({\n id,\n data,\n fieldSchema,\n operation,\n preferences: docPreferences || { fields: {} },\n req,\n })\n\n // Maintain form state of file\n if (\n collectionSlug &&\n req.payload.collections[collectionSlug]?.config?.upload &&\n formState &&\n formState.file\n ) {\n result.file = formState.file\n }\n\n return Response.json(result, {\n status: httpStatus.OK,\n })\n } catch (err) {\n return Response.json(\n {\n message: 'There was an error building form state',\n },\n {\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n}\n"],"names":["buildStateFromSchema","reduceFieldsToValues","httpStatus","buildFieldSchemaMap","cached","global","_payload_fieldSchemaMap","getFieldSchemaMap","req","process","env","NODE_ENV","buildFormState","reqData","data","collectionSlug","formState","globalSlug","locale","operation","schemaPath","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Response","json","status","UNAUTHORIZED","fieldSchemaMap","id","undefined","schemaPathSegments","split","fieldSchema","length","fields","globals","find","slug","has","get","message","BAD_REQUEST","docPreferences","promises","preferencesKey","fetchPreferences","preferencesResult","depth","limit","where","key","equals","docs","value","preferences","fetchData","resolvedData","findByID","draft","fallbackLocale","overrideAccess","findGlobal","Object","keys","Promise","all","values","result","upload","file","OK","err"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,oBAAoB,QAAQ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B,OAAO,CAACI,WAAW,CAACd,eAAe,EAAEW,QAAQmD,UACjD7D,aACAA,UAAU8D,IAAI,EACd;YACAF,OAAOE,IAAI,GAAG9D,UAAU8D,IAAI;QAC9B;QAEA,OAAO9C,SAASC,IAAI,CAAC2C,QAAQ;YAC3B1C,QAAQhC,WAAW6E,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZ,OAAOhD,SAASC,IAAI,CAClB;YACEgB,SAAS;QACX,GACA;YACEf,QAAQhC,WAAWgD,WAAW;QAChC;IAEJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport type { DocumentPreferences, Field, PayloadRequest, TypeWithID } from 'payload/types'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport httpStatus from 'http-status'\n\nimport type { FieldSchemaMap } from '../../utilities/buildFieldSchemaMap/types.js'\n\nimport { buildFieldSchemaMap } from '../../utilities/buildFieldSchemaMap/index.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\n\nlet cached = global._payload_fieldSchemaMap\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload_fieldSchemaMap = null\n}\n\nexport const getFieldSchemaMap = (req: PayloadRequest): FieldSchemaMap => {\n if (cached && process.env.NODE_ENV !== 'development') {\n return cached\n }\n\n cached = buildFieldSchemaMap(req)\n\n return cached\n}\n\nexport const buildFormState = async ({ req }: { req: PayloadRequest }) => {\n const headers = headersWithCors({\n headers: new Headers(),\n req,\n })\n\n try {\n const reqData: BuildFormStateArgs = req.data as BuildFormStateArgs\n const { collectionSlug, formState, globalSlug, locale, operation, schemaPath } = reqData\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n } else {\n return Response.json(null, {\n headers,\n status: httpStatus.UNAUTHORIZED,\n })\n }\n\n const fieldSchemaMap = getFieldSchemaMap(req)\n\n const id = collectionSlug ? reqData.id : undefined\n const schemaPathSegments = schemaPath.split('.')\n\n let fieldSchema: Field[]\n\n if (schemaPathSegments.length === 1) {\n if (req.payload.collections[schemaPath]) {\n fieldSchema = req.payload.collections[schemaPath].config.fields\n } else {\n fieldSchema = req.payload.config.globals.find(\n (global) => global.slug === schemaPath,\n )?.fields\n }\n } else if (fieldSchemaMap.has(schemaPath)) {\n fieldSchema = fieldSchemaMap.get(schemaPath)\n }\n\n if (!fieldSchema) {\n return Response.json(\n {\n message: 'Could not find field schema for given path',\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n let docPreferences = reqData.docPreferences\n let data = reqData.data\n\n const promises: {\n data?: Promise<void>\n preferences?: Promise<void>\n } = {}\n\n // If the request does not include doc preferences,\n // we should fetch them. This is useful for DocumentInfoProvider\n // as it reduces the amount of client-side fetches necessary\n // when we fetch data for the Edit view\n if (!docPreferences) {\n let preferencesKey\n\n if (collectionSlug && id) {\n preferencesKey = `collection-${collectionSlug}-${id}`\n }\n\n if (globalSlug) {\n preferencesKey = `global-${globalSlug}`\n }\n\n if (preferencesKey) {\n const fetchPreferences = async () => {\n const preferencesResult = (await req.payload.find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n where: {\n key: {\n equals: preferencesKey,\n },\n },\n })) as unknown as { docs: { value: DocumentPreferences }[] }\n\n if (preferencesResult?.docs?.[0]?.value) docPreferences = preferencesResult.docs[0].value\n }\n\n promises.preferences = fetchPreferences()\n }\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) data = reduceFieldsToValues(formState, true)\n\n // If we do not have data at this point,\n // we can fetch it. This is useful for DocumentInfoProvider\n // to reduce the amount of fetches required\n if (!data) {\n const fetchData = async () => {\n let resolvedData: TypeWithID\n\n if (collectionSlug && id) {\n resolvedData = await req.payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n if (globalSlug && schemaPath === globalSlug) {\n resolvedData = await req.payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n data = resolvedData\n }\n\n promises.data = fetchData()\n }\n\n if (Object.keys(promises).length > 0) {\n await Promise.all(Object.values(promises))\n }\n\n const result = await buildStateFromSchema({\n id,\n data,\n fieldSchema,\n operation,\n preferences: docPreferences || { fields: {} },\n req,\n })\n\n // Maintain form state of file\n if (\n collectionSlug &&\n req.payload.collections[collectionSlug]?.config?.upload &&\n formState &&\n formState.file\n ) {\n result.file = formState.file\n }\n\n return Response.json(result, {\n headers,\n status: httpStatus.OK,\n })\n } catch (err) {\n return Response.json(\n {\n message: 'There was an error building form state',\n },\n {\n headers,\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n}\n"],"names":["buildStateFromSchema","reduceFieldsToValues","httpStatus","buildFieldSchemaMap","headersWithCors","cached","global","_payload_fieldSchemaMap","getFieldSchemaMap","req","process","env","NODE_ENV","buildFormState","headers","Headers","reqData","data","collectionSlug","formState","globalSlug","locale","operation","schemaPath","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Response","json","status","UNAUTHORIZED","fieldSchemaMap","id","undefined","schemaPathSegments","split","fieldSchema","length","fields","globals","find","slug","has","get","message","BAD_REQUEST","docPreferences","promises","preferencesKey","fetchPreferences","preferencesResult","depth","limit","where","key","equals","docs","value","preferences","fetchData","resolvedData","findByID","draft","fallbackLocale","overrideAccess","findGlobal","Object","keys","Promise","all","values","result","upload","file","OK","err"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,oBAAoB,QAAQ,4CAA2C;AAChF,SAASC,oBAAoB,QAAQ,gDAA+C;AACpF,OAAOC,gBAAgB,cAAa;AAIpC,SAASC,mBAAmB,QAAQ,+CAA8C;AAClF,SAASC,eAAe,QAAQ,qCAAoC;AAEpE,IAAIC,SAASC,OAAOC,uBAAuB;AAE3C,IAAI,CAACF,QAAQ;IACX,2CAA2C;IAC3CA,SAASC,OAAOC,uBAAuB,GAAG;AAC5C;AAEA,OAAO,MAAMC,oBAAoB,CAACC;IAChC,IAAIJ,UAAUK,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;QACpD,OAAOP;IACT;IAEAA,SAASF,oBAAoBM;IAE7B,OAAOJ;AACT,EAAC;AAED,OAAO,MAAMQ,iBAAiB,OAAO,EAAEJ,GAAG,EAA2B;IACnE,MAAMK,UAAUV,gBAAgB;QAC9BU,SAAS,IAAIC;QACbN;IACF;IAEA,IAAI;QACF,MAAMO,UAA8BP,IAAIQ,IAAI;QAC5C,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGP;QAEjF,MAAMQ,mBAAmBf,IAAIgB,IAAI,EAAEC;QACnC,MAAMC,gBAAgBlB,IAAImB,OAAO,CAACC,MAAM,CAACC,KAAK,CAACL,IAAI;QAEnD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AAY;oBAC3CgD,eAAe,MAAM3D,IAAImB,OAAO,CAAC6C,UAAU,CAAC;wBAC1CxB,MAAM7B;wBACNuC,OAAO;wBACPW,OAAO;wBACPC,gBAAgB;wBAChBlD;wBACAmD,gBAAgB;wBAChB/C,MAAMhB,IAAIgB,IAAI;oBAChB;gBACF;gBAEAR,OAAOmD;YACT;YAEAb,SAAStC,IAAI,GAAGkD;QAClB;QAEA,IAAIO,OAAOC,IAAI,CAACpB,UAAUV,MAAM,GAAG,GAAG;YACpC,MAAM+B,QAAQC,GAAG,CAACH,OAAOI,MAAM,CAACvB;QAClC;QAEA,MAAMwB,SAAS,MAAM/E,qBAAqB;YACxCwC;YACAvB;YACA2B;YACAtB;YACA4C,aAAaZ,kBAAkB;gBAAER,QAAQ,CAAC;YAAE;YAC5CrC;QACF;QAEA,8BAA8B;QAC9B,IACES,kBACAT,IAAImB,OAAO,CAACI,WAAW,CAACd,eAAe,EAAEW,QAAQmD,UACjD7D,aACAA,UAAU8D,IAAI,EACd;YACAF,OAAOE,IAAI,GAAG9D,UAAU8D,IAAI;QAC9B;QAEA,OAAO9C,SAASC,IAAI,CAAC2C,QAAQ;YAC3BjE;YACAuB,QAAQnC,WAAWgF,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZ,OAAOhD,SAASC,IAAI,CAClB;YACEgB,SAAS;QACX,GACA;YACEtC;YACAuB,QAAQnC,WAAWmD,WAAW;QAChC;IAEJ;AACF,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CollectionRouteHandler } from '../types.js';
2
+ export declare const count: CollectionRouteHandler;
3
+ //# sourceMappingURL=count.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/count.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,KAAK,EAAE,sBAcnB,CAAA"}