payload 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/admin/RichText.d.ts.map +1 -1
  2. package/dist/admin/RichText.js.map +1 -1
  3. package/dist/admin/forms/Field.d.ts +2 -1
  4. package/dist/admin/forms/Field.d.ts.map +1 -1
  5. package/dist/admin/forms/Field.js.map +1 -1
  6. package/dist/admin/types.d.ts +5 -1
  7. package/dist/admin/types.d.ts.map +1 -1
  8. package/dist/admin/types.js.map +1 -1
  9. package/dist/admin/views/types.d.ts.map +1 -1
  10. package/dist/admin/views/types.js.map +1 -1
  11. package/dist/auth/baseFields/apiKey.js +3 -3
  12. package/dist/auth/baseFields/apiKey.js.map +1 -1
  13. package/dist/auth/cookies.d.ts +1 -1
  14. package/dist/auth/cookies.d.ts.map +1 -1
  15. package/dist/auth/cookies.js +2 -2
  16. package/dist/auth/cookies.js.map +1 -1
  17. package/dist/auth/getAccessResults.js +1 -1
  18. package/dist/auth/getAccessResults.js.map +1 -1
  19. package/dist/auth/getAuthFields.d.ts.map +1 -1
  20. package/dist/auth/getAuthFields.js +4 -1
  21. package/dist/auth/getAuthFields.js.map +1 -1
  22. package/dist/auth/getFieldsToSign.js +1 -1
  23. package/dist/auth/getFieldsToSign.js.map +1 -1
  24. package/dist/auth/getLoginOptions.d.ts +6 -0
  25. package/dist/auth/getLoginOptions.d.ts.map +1 -0
  26. package/dist/auth/getLoginOptions.js +8 -0
  27. package/dist/auth/getLoginOptions.js.map +1 -0
  28. package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
  29. package/dist/auth/operations/forgotPassword.js +4 -4
  30. package/dist/auth/operations/forgotPassword.js.map +1 -1
  31. package/dist/auth/operations/local/forgotPassword.d.ts +2 -1
  32. package/dist/auth/operations/local/forgotPassword.d.ts.map +1 -1
  33. package/dist/auth/operations/local/forgotPassword.js +1 -1
  34. package/dist/auth/operations/local/forgotPassword.js.map +1 -1
  35. package/dist/auth/operations/local/index.d.ts +7 -14
  36. package/dist/auth/operations/local/index.d.ts.map +1 -1
  37. package/dist/auth/operations/local/index.js +6 -13
  38. package/dist/auth/operations/local/index.js.map +1 -1
  39. package/dist/auth/operations/local/login.d.ts +2 -2
  40. package/dist/auth/operations/local/login.d.ts.map +1 -1
  41. package/dist/auth/operations/local/login.js +2 -2
  42. package/dist/auth/operations/local/login.js.map +1 -1
  43. package/dist/auth/operations/local/resetPassword.d.ts +2 -1
  44. package/dist/auth/operations/local/resetPassword.d.ts.map +1 -1
  45. package/dist/auth/operations/local/resetPassword.js +1 -1
  46. package/dist/auth/operations/local/resetPassword.js.map +1 -1
  47. package/dist/auth/operations/local/unlock.d.ts +2 -1
  48. package/dist/auth/operations/local/unlock.d.ts.map +1 -1
  49. package/dist/auth/operations/local/unlock.js +1 -1
  50. package/dist/auth/operations/local/unlock.js.map +1 -1
  51. package/dist/auth/operations/local/verifyEmail.d.ts +2 -1
  52. package/dist/auth/operations/local/verifyEmail.d.ts.map +1 -1
  53. package/dist/auth/operations/local/verifyEmail.js +1 -1
  54. package/dist/auth/operations/local/verifyEmail.js.map +1 -1
  55. package/dist/auth/operations/login.d.ts.map +1 -1
  56. package/dist/auth/operations/login.js +2 -2
  57. package/dist/auth/operations/login.js.map +1 -1
  58. package/dist/auth/operations/unlock.d.ts.map +1 -1
  59. package/dist/auth/operations/unlock.js +2 -2
  60. package/dist/auth/operations/unlock.js.map +1 -1
  61. package/dist/auth/strategies/jwt.js +3 -3
  62. package/dist/auth/strategies/jwt.js.map +1 -1
  63. package/dist/auth/strategies/local/register.d.ts.map +1 -1
  64. package/dist/auth/strategies/local/register.js +7 -5
  65. package/dist/auth/strategies/local/register.js.map +1 -1
  66. package/dist/checkPayloadDependencies.d.ts +1 -1
  67. package/dist/checkPayloadDependencies.d.ts.map +1 -1
  68. package/dist/checkPayloadDependencies.js +2 -2
  69. package/dist/checkPayloadDependencies.js.map +1 -1
  70. package/dist/collections/config/client.d.ts +4 -1
  71. package/dist/collections/config/client.d.ts.map +1 -1
  72. package/dist/collections/config/client.js +127 -68
  73. package/dist/collections/config/client.js.map +1 -1
  74. package/dist/collections/config/sanitize.js +2 -2
  75. package/dist/collections/config/sanitize.js.map +1 -1
  76. package/dist/collections/config/useAsTitle.js +1 -1
  77. package/dist/collections/config/useAsTitle.js.map +1 -1
  78. package/dist/collections/operations/find.js +1 -1
  79. package/dist/collections/operations/find.js.map +1 -1
  80. package/dist/collections/operations/findByID.d.ts.map +1 -1
  81. package/dist/collections/operations/findByID.js +13 -9
  82. package/dist/collections/operations/findByID.js.map +1 -1
  83. package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
  84. package/dist/collections/operations/findVersionByID.js +3 -0
  85. package/dist/collections/operations/findVersionByID.js.map +1 -1
  86. package/dist/collections/operations/findVersions.d.ts.map +1 -1
  87. package/dist/collections/operations/findVersions.js +4 -0
  88. package/dist/collections/operations/findVersions.js.map +1 -1
  89. package/dist/collections/operations/local/index.d.ts +2 -8
  90. package/dist/collections/operations/local/index.d.ts.map +1 -1
  91. package/dist/collections/operations/local/index.js +1 -1
  92. package/dist/collections/operations/local/index.js.map +1 -1
  93. package/dist/collections/operations/update.js +1 -1
  94. package/dist/collections/operations/update.js.map +1 -1
  95. package/dist/config/client.d.ts +0 -1
  96. package/dist/config/client.d.ts.map +1 -1
  97. package/dist/config/client.js +85 -32
  98. package/dist/config/client.js.map +1 -1
  99. package/dist/database/sanitizeJoinQuery.d.ts.map +1 -1
  100. package/dist/database/sanitizeJoinQuery.js +6 -4
  101. package/dist/database/sanitizeJoinQuery.js.map +1 -1
  102. package/dist/exports/shared.d.ts +1 -0
  103. package/dist/exports/shared.d.ts.map +1 -1
  104. package/dist/exports/shared.js +1 -0
  105. package/dist/exports/shared.js.map +1 -1
  106. package/dist/fields/config/client.d.ts +2 -4
  107. package/dist/fields/config/client.d.ts.map +1 -1
  108. package/dist/fields/config/client.js +89 -66
  109. package/dist/fields/config/client.js.map +1 -1
  110. package/dist/fields/getFieldPaths.d.ts +2 -2
  111. package/dist/fields/getFieldPaths.d.ts.map +1 -1
  112. package/dist/fields/getFieldPaths.js.map +1 -1
  113. package/dist/globals/config/client.d.ts +1 -1
  114. package/dist/globals/config/client.d.ts.map +1 -1
  115. package/dist/globals/config/client.js +49 -27
  116. package/dist/globals/config/client.js.map +1 -1
  117. package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
  118. package/dist/globals/operations/findVersionByID.js +3 -0
  119. package/dist/globals/operations/findVersionByID.js.map +1 -1
  120. package/dist/globals/operations/findVersions.d.ts.map +1 -1
  121. package/dist/globals/operations/findVersions.js +3 -0
  122. package/dist/globals/operations/findVersions.js.map +1 -1
  123. package/dist/index.d.ts.map +1 -1
  124. package/dist/index.js +8 -1
  125. package/dist/index.js.map +1 -1
  126. package/dist/versions/saveVersion.d.ts.map +1 -1
  127. package/dist/versions/saveVersion.js +6 -4
  128. package/dist/versions/saveVersion.js.map +1 -1
  129. package/package.json +2 -2
@@ -11,13 +11,13 @@ async function autoLogin({ isGraphQL, payload }) {
11
11
  or: []
12
12
  };
13
13
  if (payload.config.admin?.autoLogin.email) {
14
- where.or.push({
14
+ where.or?.push({
15
15
  email: {
16
16
  equals: payload.config.admin?.autoLogin.email
17
17
  }
18
18
  });
19
19
  } else if (payload.config.admin?.autoLogin.username) {
20
- where.or.push({
20
+ where.or?.push({
21
21
  username: {
22
22
  equals: payload.config.admin?.autoLogin.username
23
23
  }
@@ -81,7 +81,7 @@ export const JWTAuthentication = async ({ headers, isGraphQL = false, payload })
81
81
  user: null
82
82
  };
83
83
  }
84
- } catch (error) {
84
+ } catch (ignore) {
85
85
  if (headers.get('DisableAutologin') !== 'true') {
86
86
  return await autoLogin({
87
87
  isGraphQL,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/strategies/jwt.ts"],"sourcesContent":["import { jwtVerify } from 'jose'\n\nimport type { Payload, Where } from '../../types/index.js'\nimport type { AuthStrategyFunction, User } from '../index.js'\n\nimport { extractJWT } from '../extractJWT.js'\n\ntype JWTToken = {\n collection: string\n id: string\n}\n\nasync function autoLogin({\n isGraphQL,\n payload,\n}: {\n isGraphQL: boolean\n payload: Payload\n}): Promise<{\n user: null | User\n}> {\n if (\n typeof payload?.config?.admin?.autoLogin !== 'object' ||\n payload.config.admin?.autoLogin.prefillOnly ||\n !payload?.config?.admin?.autoLogin ||\n (!payload.config.admin?.autoLogin.email && !payload.config.admin?.autoLogin.username)\n ) {\n return { user: null }\n }\n\n const collection = payload.collections[payload.config.admin.user]\n\n const where: Where = {\n or: [],\n }\n if (payload.config.admin?.autoLogin.email) {\n where.or.push({\n email: {\n equals: payload.config.admin?.autoLogin.email,\n },\n })\n } else if (payload.config.admin?.autoLogin.username) {\n where.or.push({\n username: {\n equals: payload.config.admin?.autoLogin.username,\n },\n })\n }\n\n const user = (\n await payload.find({\n collection: collection.config.slug,\n depth: isGraphQL ? 0 : collection.config.auth.depth,\n where,\n })\n ).docs[0]\n\n if (!user) {\n return { user: null }\n }\n user.collection = collection.config.slug\n user._strategy = 'local-jwt'\n\n return {\n user: user as User,\n }\n}\n\nexport const JWTAuthentication: AuthStrategyFunction = async ({\n headers,\n isGraphQL = false,\n payload,\n}) => {\n try {\n const token = extractJWT({ headers, payload })\n\n if (!token) {\n if (headers.get('DisableAutologin') !== 'true') {\n return await autoLogin({ isGraphQL, payload })\n }\n return { user: null }\n }\n\n const secretKey = new TextEncoder().encode(payload.secret)\n const { payload: decodedPayload } = await jwtVerify<JWTToken>(token, secretKey)\n const collection = payload.collections[decodedPayload.collection]\n\n const user = await payload.findByID({\n id: decodedPayload.id,\n collection: decodedPayload.collection,\n depth: isGraphQL ? 0 : collection.config.auth.depth,\n })\n\n if (user && (!collection.config.auth.verify || user._verified)) {\n user.collection = collection.config.slug\n user._strategy = 'local-jwt'\n return {\n user: user as User,\n }\n } else {\n if (headers.get('DisableAutologin') !== 'true') {\n return await autoLogin({ isGraphQL, payload })\n }\n return { user: null }\n }\n } catch (error) {\n if (headers.get('DisableAutologin') !== 'true') {\n return await autoLogin({ isGraphQL, payload })\n }\n return { user: null }\n }\n}\n"],"names":["jwtVerify","extractJWT","autoLogin","isGraphQL","payload","config","admin","prefillOnly","email","username","user","collection","collections","where","or","push","equals","find","slug","depth","auth","docs","_strategy","JWTAuthentication","headers","token","get","secretKey","TextEncoder","encode","secret","decodedPayload","findByID","id","verify","_verified","error"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAM;AAKhC,SAASC,UAAU,QAAQ,mBAAkB;AAO7C,eAAeC,UAAU,EACvBC,SAAS,EACTC,OAAO,EAIR;IAGC,IACE,OAAOA,SAASC,QAAQC,OAAOJ,cAAc,YAC7CE,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUK,eAChC,CAACH,SAASC,QAAQC,OAAOJ,aACxB,CAACE,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUM,SAAS,CAACJ,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUO,UAC5E;QACA,OAAO;YAAEC,MAAM;QAAK;IACtB;IAEA,MAAMC,aAAaP,QAAQQ,WAAW,CAACR,QAAQC,MAAM,CAACC,KAAK,CAACI,IAAI,CAAC;IAEjE,MAAMG,QAAe;QACnBC,IAAI,EAAE;IACR;IACA,IAAIV,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUM,OAAO;QACzCK,MAAMC,EAAE,CAACC,IAAI,CAAC;YACZP,OAAO;gBACLQ,QAAQZ,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUM;YAC1C;QACF;IACF,OAAO,IAAIJ,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUO,UAAU;QACnDI,MAAMC,EAAE,CAACC,IAAI,CAAC;YACZN,UAAU;gBACRO,QAAQZ,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUO;YAC1C;QACF;IACF;IAEA,MAAMC,OAAO,AACX,CAAA,MAAMN,QAAQa,IAAI,CAAC;QACjB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ACR;QACF,OAAO;YACL,IAAIc,QAAQE,GAAG,CAAC,wBAAwB,QAAQ;gBAC9C,OAAO,MAAMxB,UAAU;oBAAEC;oBAAWC;gBAAQ;YAC9C;YACA,OAAO;gBAAEM,MAAM;YAAK;QACtB;IACF,EAAE,OAAO0B,OAAO;QACd,IAAIZ,QAAQE,GAAG,CAAC,wBAAwB,QAAQ;YAC9C,OAAO,MAAMxB,UAAU;gBAAEC;gBAAWC;YAAQ;QAC9C;QACA,OAAO;YAAEM,MAAM;QAAK;IACtB;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/strategies/jwt.ts"],"sourcesContent":["import { jwtVerify } from 'jose'\n\nimport type { Payload, Where } from '../../types/index.js'\nimport type { AuthStrategyFunction, User } from '../index.js'\n\nimport { extractJWT } from '../extractJWT.js'\n\ntype JWTToken = {\n collection: string\n id: string\n}\n\nasync function autoLogin({\n isGraphQL,\n payload,\n}: {\n isGraphQL: boolean\n payload: Payload\n}): Promise<{\n user: null | User\n}> {\n if (\n typeof payload?.config?.admin?.autoLogin !== 'object' ||\n payload.config.admin?.autoLogin.prefillOnly ||\n !payload?.config?.admin?.autoLogin ||\n (!payload.config.admin?.autoLogin.email && !payload.config.admin?.autoLogin.username)\n ) {\n return { user: null }\n }\n\n const collection = payload.collections[payload.config.admin.user]\n\n const where: Where = {\n or: [],\n }\n if (payload.config.admin?.autoLogin.email) {\n where.or?.push({\n email: {\n equals: payload.config.admin?.autoLogin.email,\n },\n })\n } else if (payload.config.admin?.autoLogin.username) {\n where.or?.push({\n username: {\n equals: payload.config.admin?.autoLogin.username,\n },\n })\n }\n\n const user = (\n await payload.find({\n collection: collection.config.slug,\n depth: isGraphQL ? 0 : collection.config.auth.depth,\n where,\n })\n ).docs[0]\n\n if (!user) {\n return { user: null }\n }\n user.collection = collection.config.slug\n user._strategy = 'local-jwt'\n\n return {\n user: user as User,\n }\n}\n\nexport const JWTAuthentication: AuthStrategyFunction = async ({\n headers,\n isGraphQL = false,\n payload,\n}) => {\n try {\n const token = extractJWT({ headers, payload })\n\n if (!token) {\n if (headers.get('DisableAutologin') !== 'true') {\n return await autoLogin({ isGraphQL, payload })\n }\n return { user: null }\n }\n\n const secretKey = new TextEncoder().encode(payload.secret)\n const { payload: decodedPayload } = await jwtVerify<JWTToken>(token, secretKey)\n const collection = payload.collections[decodedPayload.collection]\n\n const user = await payload.findByID({\n id: decodedPayload.id,\n collection: decodedPayload.collection,\n depth: isGraphQL ? 0 : collection.config.auth.depth,\n })\n\n if (user && (!collection.config.auth.verify || user._verified)) {\n user.collection = collection.config.slug\n user._strategy = 'local-jwt'\n return {\n user: user as User,\n }\n } else {\n if (headers.get('DisableAutologin') !== 'true') {\n return await autoLogin({ isGraphQL, payload })\n }\n return { user: null }\n }\n } catch (ignore) {\n if (headers.get('DisableAutologin') !== 'true') {\n return await autoLogin({ isGraphQL, payload })\n }\n return { user: null }\n }\n}\n"],"names":["jwtVerify","extractJWT","autoLogin","isGraphQL","payload","config","admin","prefillOnly","email","username","user","collection","collections","where","or","push","equals","find","slug","depth","auth","docs","_strategy","JWTAuthentication","headers","token","get","secretKey","TextEncoder","encode","secret","decodedPayload","findByID","id","verify","_verified","ignore"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAM;AAKhC,SAASC,UAAU,QAAQ,mBAAkB;AAO7C,eAAeC,UAAU,EACvBC,SAAS,EACTC,OAAO,EAIR;IAGC,IACE,OAAOA,SAASC,QAAQC,OAAOJ,cAAc,YAC7CE,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUK,eAChC,CAACH,SAASC,QAAQC,OAAOJ,aACxB,CAACE,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUM,SAAS,CAACJ,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUO,UAC5E;QACA,OAAO;YAAEC,MAAM;QAAK;IACtB;IAEA,MAAMC,aAAaP,QAAQQ,WAAW,CAACR,QAAQC,MAAM,CAACC,KAAK,CAACI,IAAI,CAAC;IAE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AO,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,qBAAqB,yDAO/B,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyExC,CAAA"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAS,MAAM,yBAAyB,CAAA;AAMhF,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,CAAA;IACrC,GAAG,EAAE,UAAU,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,qBAAqB,yDAO/B,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2ExC,CAAA"}
@@ -1,9 +1,11 @@
1
1
  import { ValidationError } from '../../../errors/index.js';
2
+ import { getLoginOptions } from '../../getLoginOptions.js';
2
3
  import { generatePasswordSaltHash } from './generatePasswordSaltHash.js';
3
4
  export const registerLocalStrategy = async ({ collection, doc, password, payload, req, select })=>{
4
5
  const loginWithUsername = collection?.auth?.loginWithUsername;
6
+ const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername);
5
7
  let whereConstraint;
6
- if (!loginWithUsername) {
8
+ if (!canLoginWithUsername) {
7
9
  whereConstraint = {
8
10
  email: {
9
11
  equals: doc.email
@@ -13,15 +15,15 @@ export const registerLocalStrategy = async ({ collection, doc, password, payload
13
15
  whereConstraint = {
14
16
  or: []
15
17
  };
16
- if (doc.email) {
17
- whereConstraint.or.push({
18
+ if (canLoginWithEmail && doc.email) {
19
+ whereConstraint.or?.push({
18
20
  email: {
19
21
  equals: doc.email
20
22
  }
21
23
  });
22
24
  }
23
25
  if (doc.username) {
24
- whereConstraint.or.push({
26
+ whereConstraint.or?.push({
25
27
  username: {
26
28
  equals: doc.username
27
29
  }
@@ -40,7 +42,7 @@ export const registerLocalStrategy = async ({ collection, doc, password, payload
40
42
  throw new ValidationError({
41
43
  collection: collection.slug,
42
44
  errors: [
43
- loginWithUsername ? {
45
+ canLoginWithUsername ? {
44
46
  message: req.t('error:usernameAlreadyRegistered'),
45
47
  path: 'username'
46
48
  } : {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/auth/strategies/local/register.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { JsonObject, Payload } from '../../../index.js'\nimport type { PayloadRequest, SelectType, Where } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { generatePasswordSaltHash } from './generatePasswordSaltHash.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig\n doc: JsonObject\n password: string\n payload: Payload\n req: PayloadRequest\n select?: SelectType\n}\n\nexport const registerLocalStrategy = async ({\n collection,\n doc,\n password,\n payload,\n req,\n select,\n}: Args): Promise<Record<string, unknown>> => {\n const loginWithUsername = collection?.auth?.loginWithUsername\n\n let whereConstraint: Where\n\n if (!loginWithUsername) {\n whereConstraint = {\n email: {\n equals: doc.email,\n },\n }\n } else {\n whereConstraint = {\n or: [],\n }\n\n if (doc.email) {\n whereConstraint.or.push({\n email: {\n equals: doc.email,\n },\n })\n }\n\n if (doc.username) {\n whereConstraint.or.push({\n username: {\n equals: doc.username,\n },\n })\n }\n }\n\n const existingUser = await payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n where: whereConstraint,\n })\n\n if (existingUser.docs.length > 0) {\n throw new ValidationError({\n collection: collection.slug,\n errors: [\n loginWithUsername\n ? {\n message: req.t('error:usernameAlreadyRegistered'),\n path: 'username',\n }\n : { message: req.t('error:userEmailAlreadyRegistered'), path: 'email' },\n ],\n })\n }\n\n const { hash, salt } = await generatePasswordSaltHash({ collection, password, req })\n\n const sanitizedDoc = { ...doc }\n if (sanitizedDoc.password) {\n delete sanitizedDoc.password\n }\n\n return payload.db.create({\n collection: collection.slug,\n data: {\n ...sanitizedDoc,\n hash,\n salt,\n },\n req,\n select,\n })\n}\n"],"names":["ValidationError","generatePasswordSaltHash","registerLocalStrategy","collection","doc","password","payload","req","select","loginWithUsername","auth","whereConstraint","email","equals","or","push","username","existingUser","find","slug","depth","limit","pagination","where","docs","length","errors","message","t","path","hash","salt","sanitizedDoc","db","create","data"],"mappings":"AAIA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,wBAAwB,QAAQ,gCAA+B;AAWxE,OAAO,MAAMC,wBAAwB,OAAO,EAC1CC,UAAU,EACVC,GAAG,EACHC,QAAQ,EACRC,OAAO,EACPC,GAAG,EACHC,MAAM,EACD;IACL,MAAMC,oBAAoBN,YAAYO,MAAMD;IAE5C,IAAIE;IAEJ,IAAI,CAACF,mBAAmB;QACtBE,kBAAkB;YAChBC,OAAO;gBACLC,QAAQT,IAAIQ,KAAK;YACnB;QACF;IACF,OAAO;QACLD,kBAAkB;YAChBG,IAAI,EAAE;QACR;QAEA,IAAIV,IAAIQ,KAAK,EAAE;YACbD,gBAAgBG,EAAE,CAACC,IAAI,CAAC;gBACtBH,OAAO;oBACLC,QAAQT,IAAIQ,KAAK;gBACnB;YACF;QACF;QAEA,IAAIR,IAAIY,QAAQ,EAAE;YAChBL,gBAAgBG,EAAE,CAACC,IAAI,CAAC;gBACtBC,UAAU;oBACRH,QAAQT,IAAIY,QAAQ;gBACtB;YACF;QACF;IACF;IAEA,MAAMC,eAAe,MAAMX,QAAQY,IAAI,CAAC;QACtCf,YAAYA,WAAWgB,IAAI;QAC3BC,OAAO;QACPC,OAAO;QACPC,YAAY;QACZf;QACAgB,OAAOZ;IACT;IAEA,IAAIM,aAAaO,IAAI,CAACC,MAAM,GAAG,GAAG;QAChC,MAAM,IAAIzB,gBAAgB;YACxBG,YAAYA,WAAWgB,IAAI;YAC3BO,QAAQ;gBACNjB,oBACI;oBACEkB,SAASpB,IAAIqB,CAAC,CAAC;oBACfC,MAAM;gBACR,IACA;oBAAEF,SAASpB,IAAIqB,CAAC,CAAC;oBAAqCC,MAAM;gBAAQ;aACzE;QACH;IACF;IAEA,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAG,MAAM9B,yBAAyB;QAAEE;QAAYE;QAAUE;IAAI;IAElF,MAAMyB,eAAe;QAAE,GAAG5B,GAAG;IAAC;IAC9B,IAAI4B,aAAa3B,QAAQ,EAAE;QACzB,OAAO2B,aAAa3B,QAAQ;IAC9B;IAEA,OAAOC,QAAQ2B,EAAE,CAACC,MAAM,CAAC;QACvB/B,YAAYA,WAAWgB,IAAI;QAC3BgB,MAAM;YACJ,GAAGH,YAAY;YACfF;YACAC;QACF;QACAxB;QACAC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/auth/strategies/local/register.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { JsonObject, Payload } from '../../../index.js'\nimport type { PayloadRequest, SelectType, Where } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { getLoginOptions } from '../../getLoginOptions.js'\nimport { generatePasswordSaltHash } from './generatePasswordSaltHash.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig\n doc: JsonObject\n password: string\n payload: Payload\n req: PayloadRequest\n select?: SelectType\n}\n\nexport const registerLocalStrategy = async ({\n collection,\n doc,\n password,\n payload,\n req,\n select,\n}: Args): Promise<Record<string, unknown>> => {\n const loginWithUsername = collection?.auth?.loginWithUsername\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n let whereConstraint: Where\n\n if (!canLoginWithUsername) {\n whereConstraint = {\n email: {\n equals: doc.email,\n },\n }\n } else {\n whereConstraint = {\n or: [],\n }\n\n if (canLoginWithEmail && doc.email) {\n whereConstraint.or?.push({\n email: {\n equals: doc.email,\n },\n })\n }\n\n if (doc.username) {\n whereConstraint.or?.push({\n username: {\n equals: doc.username,\n },\n })\n }\n }\n\n const existingUser = await payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n where: whereConstraint,\n })\n\n if (existingUser.docs.length > 0) {\n throw new ValidationError({\n collection: collection.slug,\n errors: [\n canLoginWithUsername\n ? {\n message: req.t('error:usernameAlreadyRegistered'),\n path: 'username',\n }\n : { message: req.t('error:userEmailAlreadyRegistered'), path: 'email' },\n ],\n })\n }\n\n const { hash, salt } = await generatePasswordSaltHash({ collection, password, req })\n\n const sanitizedDoc = { ...doc }\n if (sanitizedDoc.password) {\n delete sanitizedDoc.password\n }\n\n return payload.db.create({\n collection: collection.slug,\n data: {\n ...sanitizedDoc,\n hash,\n salt,\n },\n req,\n select,\n })\n}\n"],"names":["ValidationError","getLoginOptions","generatePasswordSaltHash","registerLocalStrategy","collection","doc","password","payload","req","select","loginWithUsername","auth","canLoginWithEmail","canLoginWithUsername","whereConstraint","email","equals","or","push","username","existingUser","find","slug","depth","limit","pagination","where","docs","length","errors","message","t","path","hash","salt","sanitizedDoc","db","create","data"],"mappings":"AAIA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,wBAAwB,QAAQ,gCAA+B;AAWxE,OAAO,MAAMC,wBAAwB,OAAO,EAC1CC,UAAU,EACVC,GAAG,EACHC,QAAQ,EACRC,OAAO,EACPC,GAAG,EACHC,MAAM,EACD;IACL,MAAMC,oBAAoBN,YAAYO,MAAMD;IAE5C,MAAM,EAAEE,iBAAiB,EAAEC,oBAAoB,EAAE,GAAGZ,gBAAgBS;IAEpE,IAAII;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export declare function checkPayloadDependencies(): Promise<void>;
1
+ export declare function checkPayloadDependencies(): void;
2
2
  //# sourceMappingURL=checkPayloadDependencies.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkPayloadDependencies.d.ts","sourceRoot":"","sources":["../src/checkPayloadDependencies.ts"],"names":[],"mappings":"AAGA,wBAAsB,wBAAwB,kBAiB7C"}
1
+ {"version":3,"file":"checkPayloadDependencies.d.ts","sourceRoot":"","sources":["../src/checkPayloadDependencies.ts"],"names":[],"mappings":"AAGA,wBAAgB,wBAAwB,SAiBvC"}
@@ -1,6 +1,6 @@
1
1
  import { checkDependencies } from './utilities/dependencies/dependencyChecker.js';
2
2
  import { PAYLOAD_PACKAGE_LIST } from './versions/payloadPackageList.js';
3
- export async function checkPayloadDependencies() {
3
+ export function checkPayloadDependencies() {
4
4
  const dependencies = [
5
5
  ...PAYLOAD_PACKAGE_LIST
6
6
  ];
@@ -8,7 +8,7 @@ export async function checkPayloadDependencies() {
8
8
  dependencies.push('@payloadcms/plugin-sentry');
9
9
  }
10
10
  // First load. First check if there are mismatching dependency versions of payload packages
11
- await checkDependencies({
11
+ void checkDependencies({
12
12
  dependencyGroups: [
13
13
  {
14
14
  name: 'payload',
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/checkPayloadDependencies.ts"],"sourcesContent":["import { checkDependencies } from './utilities/dependencies/dependencyChecker.js'\nimport { PAYLOAD_PACKAGE_LIST } from './versions/payloadPackageList.js'\n\nexport async function checkPayloadDependencies() {\n const dependencies = [...PAYLOAD_PACKAGE_LIST]\n\n if (process.env.PAYLOAD_CI_DEPENDENCY_CHECKER !== 'true') {\n dependencies.push('@payloadcms/plugin-sentry')\n }\n\n // First load. First check if there are mismatching dependency versions of payload packages\n await checkDependencies({\n dependencyGroups: [\n {\n name: 'payload',\n dependencies,\n targetVersionDependency: 'payload',\n },\n ],\n })\n}\n"],"names":["checkDependencies","PAYLOAD_PACKAGE_LIST","checkPayloadDependencies","dependencies","process","env","PAYLOAD_CI_DEPENDENCY_CHECKER","push","dependencyGroups","name","targetVersionDependency"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,gDAA+C;AACjF,SAASC,oBAAoB,QAAQ,mCAAkC;AAEvE,OAAO,eAAeC;IACpB,MAAMC,eAAe;WAAIF;KAAqB;IAE9C,IAAIG,QAAQC,GAAG,CAACC,6BAA6B,KAAK,QAAQ;QACxDH,aAAaI,IAAI,CAAC;IACpB;IAEA,2FAA2F;IAC3F,MAAMP,kBAAkB;QACtBQ,kBAAkB;YAChB;gBACEC,MAAM;gBACNN;gBACAO,yBAAyB;YAC3B;SACD;IACH;AACF"}
1
+ {"version":3,"sources":["../src/checkPayloadDependencies.ts"],"sourcesContent":["import { checkDependencies } from './utilities/dependencies/dependencyChecker.js'\nimport { PAYLOAD_PACKAGE_LIST } from './versions/payloadPackageList.js'\n\nexport function checkPayloadDependencies() {\n const dependencies = [...PAYLOAD_PACKAGE_LIST]\n\n if (process.env.PAYLOAD_CI_DEPENDENCY_CHECKER !== 'true') {\n dependencies.push('@payloadcms/plugin-sentry')\n }\n\n // First load. First check if there are mismatching dependency versions of payload packages\n void checkDependencies({\n dependencyGroups: [\n {\n name: 'payload',\n dependencies,\n targetVersionDependency: 'payload',\n },\n ],\n })\n}\n"],"names":["checkDependencies","PAYLOAD_PACKAGE_LIST","checkPayloadDependencies","dependencies","process","env","PAYLOAD_CI_DEPENDENCY_CHECKER","push","dependencyGroups","name","targetVersionDependency"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,gDAA+C;AACjF,SAASC,oBAAoB,QAAQ,mCAAkC;AAEvE,OAAO,SAASC;IACd,MAAMC,eAAe;WAAIF;KAAqB;IAE9C,IAAIG,QAAQC,GAAG,CAACC,6BAA6B,KAAK,QAAQ;QACxDH,aAAaI,IAAI,CAAC;IACpB;IAEA,2FAA2F;IAC3F,KAAKP,kBAAkB;QACrBQ,kBAAkB;YAChB;gBACEC,MAAM;gBACNN;gBACAO,yBAAyB;YAC3B;SACD;IACH;AACF"}
@@ -14,12 +14,15 @@ export type ClientCollectionConfig = {
14
14
  livePreview?: Omit<LivePreviewConfig, ServerOnlyLivePreviewProperties>;
15
15
  preview?: boolean;
16
16
  } & Omit<SanitizedCollectionConfig['admin'], 'components' | 'description' | 'joins' | 'livePreview' | 'preview' | ServerOnlyCollectionAdminProperties>;
17
+ auth?: {
18
+ verify?: true;
19
+ } & Omit<SanitizedCollectionConfig['auth'], 'forgotPassword' | 'strategies' | 'verify'>;
17
20
  fields: ClientField[];
18
21
  labels: {
19
22
  plural: StaticLabel;
20
23
  singular: StaticLabel;
21
24
  };
22
- } & Omit<SanitizedCollectionConfig, 'admin' | 'fields' | 'labels' | ServerOnlyCollectionProperties>;
25
+ } & Omit<SanitizedCollectionConfig, 'admin' | 'auth' | 'fields' | 'labels' | ServerOnlyCollectionProperties>;
23
26
  export declare const createClientCollectionConfig: ({ collection, defaultIDType, i18n, importMap, }: {
24
27
  collection: SanitizedCollectionConfig;
25
28
  defaultIDType: Payload["config"]["db"]["defaultIDType"];
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/collections/config/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAC/B,WAAW,EACZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAK3D,MAAM,MAAM,8BAA8B,GAAG,MAAM,IAAI,CACrD,yBAAyB,EACzB,QAAQ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,CAAC,iBAAiB,EAAE,+BAA+B,CAAC,CAAA;QACtE,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,GAAG,IAAI,CACN,yBAAyB,CAAC,OAAO,CAAC,EAChC,YAAY,GACZ,aAAa,GACb,OAAO,GACP,aAAa,GACb,SAAS,GACT,mCAAmC,CACtC,CAAA;IACD,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI,CAC7B,yBAAyB,CAAC,MAAM,CAAC,EACjC,gBAAgB,GAAG,YAAY,GAAG,QAAQ,CAC3C,CAAA;IACD,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,MAAM,EAAE;QACN,MAAM,EAAE,WAAW,CAAA;QACnB,QAAQ,EAAE,WAAW,CAAA;KACtB,CAAA;CACF,GAAG,IAAI,CACN,yBAAyB,EACzB,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,8BAA8B,CACxE,CAAA;AA8BD,eAAO,MAAM,4BAA4B,oDAKtC;IACD,UAAU,EAAE,yBAAyB,CAAA;IACrC,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,CAAA;IACvD,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,SAAS,CAAA;CACrB,KAAG,sBA8IH,CAAA;AAED,eAAO,MAAM,6BAA6B,qDAKvC;IACD,WAAW,EAAE,yBAAyB,EAAE,CAAA;IACxC,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,CAAA;IACvD,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,SAAS,CAAA;CACrB,KAAG,sBAAsB,EAezB,CAAA"}
@@ -1,5 +1,4 @@
1
1
  import { createClientFields } from '../../fields/config/client.js';
2
- import { deepCopyObjectSimple } from '../../utilities/deepCopyObject.js';
3
2
  const serverOnlyCollectionProperties = [
4
3
  'hooks',
5
4
  'access',
@@ -21,78 +20,138 @@ const serverOnlyCollectionAdminProperties = [
21
20
  'components'
22
21
  ];
23
22
  export const createClientCollectionConfig = ({ collection, defaultIDType, i18n, importMap })=>{
24
- const clientCollection = deepCopyObjectSimple(collection, true);
25
- clientCollection.fields = createClientFields({
26
- clientFields: clientCollection?.fields || [],
27
- defaultIDType,
28
- fields: collection.fields,
29
- i18n,
30
- importMap
31
- });
32
- serverOnlyCollectionProperties.forEach((key)=>{
33
- if (key in clientCollection) {
34
- delete clientCollection[key];
23
+ const clientCollection = {};
24
+ for(const key in collection){
25
+ if (serverOnlyCollectionProperties.includes(key)) {
26
+ continue;
35
27
  }
36
- });
37
- if ('upload' in clientCollection && typeof clientCollection.upload === 'object') {
38
- serverOnlyUploadProperties.forEach((key)=>{
39
- if (key in clientCollection.upload) {
40
- delete clientCollection.upload[key];
41
- }
42
- });
43
- if ('imageSizes' in clientCollection.upload && clientCollection.upload.imageSizes.length) {
44
- clientCollection.upload.imageSizes = clientCollection.upload.imageSizes.map((size)=>{
45
- const sanitizedSize = {
46
- ...size
47
- };
48
- if ('generateImageName' in sanitizedSize) {
49
- delete sanitizedSize.generateImageName;
28
+ switch(key){
29
+ case 'admin':
30
+ if (!collection.admin) {
31
+ break;
50
32
  }
51
- return sanitizedSize;
52
- });
53
- }
54
- }
55
- if ('auth' in clientCollection && typeof clientCollection.auth === 'object') {
56
- delete clientCollection.auth.strategies;
57
- delete clientCollection.auth.forgotPassword;
58
- delete clientCollection.auth.verify;
59
- }
60
- if (collection.labels) {
61
- Object.entries(collection.labels).forEach(([labelType, collectionLabel])=>{
62
- if (typeof collectionLabel === 'function') {
63
- clientCollection.labels[labelType] = collectionLabel({
64
- t: i18n.t
33
+ clientCollection.admin = {};
34
+ for(const adminKey in collection.admin){
35
+ if (serverOnlyCollectionAdminProperties.includes(adminKey)) {
36
+ continue;
37
+ }
38
+ switch(adminKey){
39
+ case 'description':
40
+ if (typeof collection.admin.description === 'string' || typeof collection.admin.description === 'object') {
41
+ if (collection.admin.description) {
42
+ clientCollection.admin.description = collection.admin.description;
43
+ }
44
+ } else if (typeof collection.admin.description === 'function') {
45
+ const description = collection.admin.description({
46
+ t: i18n.t
47
+ });
48
+ if (description) {
49
+ clientCollection.admin.description = description;
50
+ }
51
+ }
52
+ break;
53
+ case 'livePreview':
54
+ clientCollection.admin.livePreview = {};
55
+ if (collection.admin.livePreview.breakpoints) {
56
+ clientCollection.admin.livePreview.breakpoints = collection.admin.livePreview.breakpoints;
57
+ }
58
+ break;
59
+ case 'preview':
60
+ if (collection.admin.preview) {
61
+ clientCollection.admin.preview = true;
62
+ }
63
+ break;
64
+ default:
65
+ clientCollection.admin[adminKey] = collection.admin[adminKey];
66
+ }
67
+ }
68
+ break;
69
+ case 'auth':
70
+ if (!collection.auth) {
71
+ break;
72
+ }
73
+ clientCollection.auth = {};
74
+ if (collection.auth.cookies) {
75
+ clientCollection.auth.cookies = collection.auth.cookies;
76
+ }
77
+ if (collection.auth.depth !== undefined) {
78
+ // Check for undefined as it can be a number (0)
79
+ clientCollection.auth.depth = collection.auth.depth;
80
+ }
81
+ if (collection.auth.disableLocalStrategy) {
82
+ clientCollection.auth.disableLocalStrategy = collection.auth.disableLocalStrategy;
83
+ }
84
+ if (collection.auth.lockTime !== undefined) {
85
+ // Check for undefined as it can be a number (0)
86
+ clientCollection.auth.lockTime = collection.auth.lockTime;
87
+ }
88
+ if (collection.auth.loginWithUsername) {
89
+ clientCollection.auth.loginWithUsername = collection.auth.loginWithUsername;
90
+ }
91
+ if (collection.auth.maxLoginAttempts !== undefined) {
92
+ // Check for undefined as it can be a number (0)
93
+ clientCollection.auth.maxLoginAttempts = collection.auth.maxLoginAttempts;
94
+ }
95
+ if (collection.auth.removeTokenFromResponses) {
96
+ clientCollection.auth.removeTokenFromResponses = collection.auth.removeTokenFromResponses;
97
+ }
98
+ if (collection.auth.useAPIKey) {
99
+ clientCollection.auth.useAPIKey = collection.auth.useAPIKey;
100
+ }
101
+ if (collection.auth.tokenExpiration) {
102
+ clientCollection.auth.tokenExpiration = collection.auth.tokenExpiration;
103
+ }
104
+ if (collection.auth.verify) {
105
+ clientCollection.auth.verify = true;
106
+ }
107
+ break;
108
+ case 'fields':
109
+ clientCollection.fields = createClientFields({
110
+ defaultIDType,
111
+ fields: collection.fields,
112
+ i18n,
113
+ importMap
65
114
  });
66
- }
67
- });
68
- }
69
- if (!clientCollection.admin) {
70
- clientCollection.admin = {};
71
- }
72
- serverOnlyCollectionAdminProperties.forEach((key)=>{
73
- if (key in clientCollection.admin) {
74
- delete clientCollection.admin[key];
75
- }
76
- });
77
- if (collection.admin.preview) {
78
- clientCollection.admin.preview = true;
79
- }
80
- let description = undefined;
81
- if (collection.admin?.description) {
82
- if (typeof collection.admin?.description === 'string' || typeof collection.admin?.description === 'object') {
83
- description = collection.admin.description;
84
- } else if (typeof collection.admin?.description === 'function') {
85
- description = collection.admin?.description({
86
- t: i18n.t
87
- });
115
+ break;
116
+ case 'labels':
117
+ clientCollection.labels = {
118
+ plural: typeof collection.labels.plural === 'function' ? collection.labels.plural({
119
+ t: i18n.t
120
+ }) : collection.labels.plural,
121
+ singular: typeof collection.labels.singular === 'function' ? collection.labels.singular({
122
+ t: i18n.t
123
+ }) : collection.labels.singular
124
+ };
125
+ break;
126
+ case 'upload':
127
+ if (!collection.upload) {
128
+ break;
129
+ }
130
+ clientCollection.upload = {};
131
+ for(const uploadKey in collection.upload){
132
+ if (serverOnlyUploadProperties.includes(uploadKey)) {
133
+ continue;
134
+ }
135
+ if (uploadKey === 'imageSizes') {
136
+ clientCollection.upload.imageSizes = collection.upload.imageSizes.map((size)=>{
137
+ const sanitizedSize = {
138
+ ...size
139
+ };
140
+ if ('generateImageName' in sanitizedSize) {
141
+ delete sanitizedSize.generateImageName;
142
+ }
143
+ return sanitizedSize;
144
+ });
145
+ } else {
146
+ clientCollection.upload[uploadKey] = collection.upload[uploadKey];
147
+ }
148
+ }
149
+ break;
150
+ break;
151
+ default:
152
+ clientCollection[key] = collection[key];
88
153
  }
89
154
  }
90
- if (description) {
91
- clientCollection.admin.description = description;
92
- }
93
- if ('livePreview' in clientCollection.admin && clientCollection.admin.livePreview && 'url' in clientCollection.admin.livePreview) {
94
- delete clientCollection.admin.livePreview.url;
95
- }
96
155
  return clientCollection;
97
156
  };
98
157
  export const createClientCollectionConfigs = ({ collections, defaultIDType, i18n, importMap })=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\n\nimport type { StaticDescription } from '../../admin/types.js'\nimport type { ImportMap } from '../../bin/generateImportMap/index.js'\nimport type {\n LivePreviewConfig,\n ServerOnlyLivePreviewProperties,\n StaticLabel,\n} from '../../config/types.js'\nimport type { ClientField } from '../../fields/config/client.js'\nimport type { Payload } from '../../types/index.js'\nimport type { SanitizedCollectionConfig } from './types.js'\n\nimport { createClientFields } from '../../fields/config/client.js'\nimport { deepCopyObjectSimple } from '../../utilities/deepCopyObject.js'\n\nexport type ServerOnlyCollectionProperties = keyof Pick<\n SanitizedCollectionConfig,\n 'access' | 'custom' | 'endpoints' | 'flattenedFields' | 'hooks' | 'joins'\n>\n\nexport type ServerOnlyCollectionAdminProperties = keyof Pick<\n SanitizedCollectionConfig['admin'],\n 'baseListFilter' | 'components' | 'hidden'\n>\n\nexport type ServerOnlyUploadProperties = keyof Pick<\n SanitizedCollectionConfig['upload'],\n | 'adminThumbnail'\n | 'externalFileHeaderFilter'\n | 'handlers'\n | 'modifyResponseHeaders'\n | 'withMetadata'\n>\n\nexport type ClientCollectionConfig = {\n admin: {\n description?: StaticDescription\n livePreview?: Omit<LivePreviewConfig, ServerOnlyLivePreviewProperties>\n preview?: boolean\n } & Omit<\n SanitizedCollectionConfig['admin'],\n | 'components'\n | 'description'\n | 'joins'\n | 'livePreview'\n | 'preview'\n | ServerOnlyCollectionAdminProperties\n >\n fields: ClientField[]\n labels: {\n plural: StaticLabel\n singular: StaticLabel\n }\n} & Omit<SanitizedCollectionConfig, 'admin' | 'fields' | 'labels' | ServerOnlyCollectionProperties>\n\nconst serverOnlyCollectionProperties: Partial<ServerOnlyCollectionProperties>[] = [\n 'hooks',\n 'access',\n 'endpoints',\n 'custom',\n 'joins',\n 'flattenedFields',\n // `upload`\n // `admin`\n // are all handled separately\n]\n\nconst serverOnlyUploadProperties: Partial<ServerOnlyUploadProperties>[] = [\n 'adminThumbnail',\n 'externalFileHeaderFilter',\n 'handlers',\n 'modifyResponseHeaders',\n 'withMetadata',\n]\n\nconst serverOnlyCollectionAdminProperties: Partial<ServerOnlyCollectionAdminProperties>[] = [\n 'hidden',\n 'baseListFilter',\n 'components',\n // 'preview' is handled separately\n // `livePreview` is handled separately\n]\n\nexport const createClientCollectionConfig = ({\n collection,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collection: SanitizedCollectionConfig\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig => {\n const clientCollection = deepCopyObjectSimple(\n collection,\n true,\n ) as unknown as ClientCollectionConfig\n\n clientCollection.fields = createClientFields({\n clientFields: clientCollection?.fields || [],\n defaultIDType,\n fields: collection.fields,\n i18n,\n importMap,\n })\n\n serverOnlyCollectionProperties.forEach((key) => {\n if (key in clientCollection) {\n delete clientCollection[key]\n }\n })\n\n if ('upload' in clientCollection && typeof clientCollection.upload === 'object') {\n serverOnlyUploadProperties.forEach((key) => {\n if (key in clientCollection.upload) {\n delete clientCollection.upload[key]\n }\n })\n\n if ('imageSizes' in clientCollection.upload && clientCollection.upload.imageSizes.length) {\n clientCollection.upload.imageSizes = clientCollection.upload.imageSizes.map((size) => {\n const sanitizedSize = { ...size }\n if ('generateImageName' in sanitizedSize) {\n delete sanitizedSize.generateImageName\n }\n return sanitizedSize\n })\n }\n }\n\n if ('auth' in clientCollection && typeof clientCollection.auth === 'object') {\n delete clientCollection.auth.strategies\n delete clientCollection.auth.forgotPassword\n delete clientCollection.auth.verify\n }\n\n if (collection.labels) {\n Object.entries(collection.labels).forEach(([labelType, collectionLabel]) => {\n if (typeof collectionLabel === 'function') {\n clientCollection.labels[labelType] = collectionLabel({ t: i18n.t })\n }\n })\n }\n\n if (!clientCollection.admin) {\n clientCollection.admin = {} as ClientCollectionConfig['admin']\n }\n\n serverOnlyCollectionAdminProperties.forEach((key) => {\n if (key in clientCollection.admin) {\n delete clientCollection.admin[key]\n }\n })\n\n if (collection.admin.preview) {\n clientCollection.admin.preview = true\n }\n\n let description = undefined\n\n if (collection.admin?.description) {\n if (\n typeof collection.admin?.description === 'string' ||\n typeof collection.admin?.description === 'object'\n ) {\n description = collection.admin.description\n } else if (typeof collection.admin?.description === 'function') {\n description = collection.admin?.description({ t: i18n.t })\n }\n }\n\n if (description) {\n clientCollection.admin.description = description\n }\n\n if (\n 'livePreview' in clientCollection.admin &&\n clientCollection.admin.livePreview &&\n 'url' in clientCollection.admin.livePreview\n ) {\n delete clientCollection.admin.livePreview.url\n }\n\n return clientCollection\n}\n\nexport const createClientCollectionConfigs = ({\n collections,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collections: SanitizedCollectionConfig[]\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig[] => {\n const clientCollections = new Array(collections.length)\n\n for (let i = 0; i < collections.length; i++) {\n const collection = collections[i]\n\n clientCollections[i] = createClientCollectionConfig({\n collection,\n defaultIDType,\n i18n,\n importMap,\n })\n }\n\n return clientCollections\n}\n"],"names":["createClientFields","deepCopyObjectSimple","serverOnlyCollectionProperties","serverOnlyUploadProperties","serverOnlyCollectionAdminProperties","createClientCollectionConfig","collection","defaultIDType","i18n","importMap","clientCollection","fields","clientFields","forEach","key","upload","imageSizes","length","map","size","sanitizedSize","generateImageName","auth","strategies","forgotPassword","verify","labels","Object","entries","labelType","collectionLabel","t","admin","preview","description","undefined","livePreview","url","createClientCollectionConfigs","collections","clientCollections","Array","i"],"mappings":"AAaA,SAASA,k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sB,KAAK,CAACI,WAAW,CAACC,GAAG;IAC/C;IAEA,OAAO3B;AACT,EAAC;AAED,OAAO,MAAM4B,gCAAgC,CAAC,EAC5CC,WAAW,EACXhC,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAM+B,oBAAoB,IAAIC,MAAMF,YAAYtB,MAAM;IAEtD,IAAK,IAAIyB,IAAI,GAAGA,IAAIH,YAAYtB,MAAM,EAAEyB,IAAK;QAC3C,MAAMpC,aAAaiC,WAAW,CAACG,EAAE;QAEjCF,iBAAiB,CAACE,EAAE,GAAGrC,6BAA6B;YAClDC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO+B;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\n\nimport type { StaticDescription } from '../../admin/types.js'\nimport type { ImportMap } from '../../bin/generateImportMap/index.js'\nimport type {\n LivePreviewConfig,\n ServerOnlyLivePreviewProperties,\n StaticLabel,\n} from '../../config/types.js'\nimport type { ClientField } from '../../fields/config/client.js'\nimport type { Payload } from '../../types/index.js'\nimport type { SanitizedUploadConfig } from '../../uploads/types.js'\nimport type { SanitizedCollectionConfig } from './types.js'\n\nimport { createClientFields } from '../../fields/config/client.js'\n\nexport type ServerOnlyCollectionProperties = keyof Pick<\n SanitizedCollectionConfig,\n 'access' | 'custom' | 'endpoints' | 'flattenedFields' | 'hooks' | 'joins'\n>\n\nexport type ServerOnlyCollectionAdminProperties = keyof Pick<\n SanitizedCollectionConfig['admin'],\n 'baseListFilter' | 'components' | 'hidden'\n>\n\nexport type ServerOnlyUploadProperties = keyof Pick<\n SanitizedCollectionConfig['upload'],\n | 'adminThumbnail'\n | 'externalFileHeaderFilter'\n | 'handlers'\n | 'modifyResponseHeaders'\n | 'withMetadata'\n>\n\nexport type ClientCollectionConfig = {\n admin: {\n description?: StaticDescription\n livePreview?: Omit<LivePreviewConfig, ServerOnlyLivePreviewProperties>\n preview?: boolean\n } & Omit<\n SanitizedCollectionConfig['admin'],\n | 'components'\n | 'description'\n | 'joins'\n | 'livePreview'\n | 'preview'\n | ServerOnlyCollectionAdminProperties\n >\n auth?: { verify?: true } & Omit<\n SanitizedCollectionConfig['auth'],\n 'forgotPassword' | 'strategies' | 'verify'\n >\n fields: ClientField[]\n labels: {\n plural: StaticLabel\n singular: StaticLabel\n }\n} & Omit<\n SanitizedCollectionConfig,\n 'admin' | 'auth' | 'fields' | 'labels' | ServerOnlyCollectionProperties\n>\n\nconst serverOnlyCollectionProperties: Partial<ServerOnlyCollectionProperties>[] = [\n 'hooks',\n 'access',\n 'endpoints',\n 'custom',\n 'joins',\n 'flattenedFields',\n // `upload`\n // `admin`\n // are all handled separately\n]\n\nconst serverOnlyUploadProperties: Partial<ServerOnlyUploadProperties>[] = [\n 'adminThumbnail',\n 'externalFileHeaderFilter',\n 'handlers',\n 'modifyResponseHeaders',\n 'withMetadata',\n]\n\nconst serverOnlyCollectionAdminProperties: Partial<ServerOnlyCollectionAdminProperties>[] = [\n 'hidden',\n 'baseListFilter',\n 'components',\n // 'preview' is handled separately\n // `livePreview` is handled separately\n]\n\nexport const createClientCollectionConfig = ({\n collection,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collection: SanitizedCollectionConfig\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig => {\n const clientCollection = {} as Partial<ClientCollectionConfig>\n\n for (const key in collection) {\n if (serverOnlyCollectionProperties.includes(key as any)) {\n continue\n }\n switch (key) {\n case 'admin':\n if (!collection.admin) {\n break\n }\n clientCollection.admin = {} as ClientCollectionConfig['admin']\n for (const adminKey in collection.admin) {\n if (serverOnlyCollectionAdminProperties.includes(adminKey as any)) {\n continue\n }\n\n switch (adminKey) {\n case 'description':\n if (\n typeof collection.admin.description === 'string' ||\n typeof collection.admin.description === 'object'\n ) {\n if (collection.admin.description) {\n clientCollection.admin.description = collection.admin.description\n }\n } else if (typeof collection.admin.description === 'function') {\n const description = collection.admin.description({ t: i18n.t })\n if (description) {\n clientCollection.admin.description = description\n }\n }\n break\n case 'livePreview':\n clientCollection.admin.livePreview =\n {} as ClientCollectionConfig['admin']['livePreview']\n if (collection.admin.livePreview.breakpoints) {\n clientCollection.admin.livePreview.breakpoints =\n collection.admin.livePreview.breakpoints\n }\n break\n case 'preview':\n if (collection.admin.preview) {\n clientCollection.admin.preview = true\n }\n break\n default:\n clientCollection.admin[adminKey] = collection.admin[adminKey]\n }\n }\n break\n case 'auth':\n if (!collection.auth) {\n break\n }\n clientCollection.auth = {} as { verify?: true } & SanitizedCollectionConfig['auth']\n if (collection.auth.cookies) {\n clientCollection.auth.cookies = collection.auth.cookies\n }\n if (collection.auth.depth !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.depth = collection.auth.depth\n }\n if (collection.auth.disableLocalStrategy) {\n clientCollection.auth.disableLocalStrategy = collection.auth.disableLocalStrategy\n }\n if (collection.auth.lockTime !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.lockTime = collection.auth.lockTime\n }\n if (collection.auth.loginWithUsername) {\n clientCollection.auth.loginWithUsername = collection.auth.loginWithUsername\n }\n if (collection.auth.maxLoginAttempts !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.maxLoginAttempts = collection.auth.maxLoginAttempts\n }\n if (collection.auth.removeTokenFromResponses) {\n clientCollection.auth.removeTokenFromResponses = collection.auth.removeTokenFromResponses\n }\n\n if (collection.auth.useAPIKey) {\n clientCollection.auth.useAPIKey = collection.auth.useAPIKey\n }\n if (collection.auth.tokenExpiration) {\n clientCollection.auth.tokenExpiration = collection.auth.tokenExpiration\n }\n if (collection.auth.verify) {\n clientCollection.auth.verify = true\n }\n break\n case 'fields':\n clientCollection.fields = createClientFields({\n defaultIDType,\n fields: collection.fields,\n i18n,\n importMap,\n })\n break\n case 'labels':\n clientCollection.labels = {\n plural:\n typeof collection.labels.plural === 'function'\n ? collection.labels.plural({ t: i18n.t })\n : collection.labels.plural,\n singular:\n typeof collection.labels.singular === 'function'\n ? collection.labels.singular({ t: i18n.t })\n : collection.labels.singular,\n }\n break\n case 'upload':\n if (!collection.upload) {\n break\n }\n clientCollection.upload = {} as SanitizedUploadConfig\n for (const uploadKey in collection.upload) {\n if (serverOnlyUploadProperties.includes(uploadKey as any)) {\n continue\n }\n if (uploadKey === 'imageSizes') {\n clientCollection.upload.imageSizes = collection.upload.imageSizes.map((size) => {\n const sanitizedSize = { ...size }\n if ('generateImageName' in sanitizedSize) {\n delete sanitizedSize.generateImageName\n }\n return sanitizedSize\n })\n } else {\n clientCollection.upload[uploadKey] = collection.upload[uploadKey]\n }\n }\n break\n\n break\n default:\n clientCollection[key] = collection[key]\n }\n }\n\n return clientCollection as ClientCollectionConfig\n}\n\nexport const createClientCollectionConfigs = ({\n collections,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collections: SanitizedCollectionConfig[]\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig[] => {\n const clientCollections = new Array(collections.length)\n\n for (let i = 0; i < collections.length; i++) {\n const collection = collections[i]\n\n clientCollections[i] = createClientCollectionConfig({\n collection,\n defaultIDType,\n i18n,\n importMap,\n })\n }\n\n return clientCollections\n}\n"],"names":["createClientFields","serverOnlyCollectionProperties","serverOnlyUploadProperties","serverOnlyCollectionAdminProperties","createClientCollectionConfig","collection","defaultIDType","i18n","importMap","clientCollection","key","includes","admin","adminKey","description","t","livePreview","breakpoints","preview","auth","cookies","depth","undefined","disableLocalStrategy","lockTime","loginWithUsername","maxLoginAttempts","removeTokenFromResponses","useAPIKey","tokenExpiration","verify","fields","labels","plural","singular","upload","uploadKey","imageSizes","map","size","sanitizedSize","generateImageName","createClientCollectionConfigs","collections","clientCollections","Array","length","i"],"mappings":"AAcA,SAASA,kBAAkB,QAAQ,gCAA+B;AAiDlE,MAAMC,iCAA4E;IAChF;IACA;IACA;IACA;IACA;I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,CAAC,CAACC;4BACrE,MAAMC,gBAAgB;gCAAE,GAAGD,IAAI;4BAAC;4BAChC,IAAI,uBAAuBC,eAAe;gCACxC,OAAOA,cAAcC,iBAAiB;4BACxC;4BACA,OAAOD;wBACT;oBACF,OAAO;wBACL/B,iBAAiB0B,MAAM,CAACC,UAAU,GAAG/B,WAAW8B,MAAM,CAACC,UAAU;oBACnE;gBACF;gBACA;gBAEA;YACF;gBACE3B,gBAAgB,CAACC,IAAI,GAAGL,UAAU,CAACK,IAAI;QAC3C;IACF;IAEA,OAAOD;AACT,EAAC;AAED,OAAO,MAAMiC,gCAAgC,CAAC,EAC5CC,WAAW,EACXrC,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMoC,oBAAoB,IAAIC,MAAMF,YAAYG,MAAM;IAEtD,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,YAAYG,MAAM,EAAEC,IAAK;QAC3C,MAAM1C,aAAasC,WAAW,CAACI,EAAE;QAEjCH,iBAAiB,CAACG,EAAE,GAAG3C,6BAA6B;YAClDC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOoC;AACT,EAAC"}
@@ -23,7 +23,7 @@ export const sanitizeCollection = async (config, collection, /**
23
23
  // /////////////////////////////////
24
24
  // Sanitize fields
25
25
  // /////////////////////////////////
26
- const validRelationships = config.collections.reduce((acc, c)=>{
26
+ const validRelationships = (config.collections || []).reduce((acc, c)=>{
27
27
  acc.push(c.slug);
28
28
  return acc;
29
29
  }, [
@@ -119,7 +119,7 @@ export const sanitizeCollection = async (config, collection, /**
119
119
  sanitizeUploadFields(sanitized.fields, sanitized);
120
120
  sanitized.upload.bulkUpload = sanitized.upload?.bulkUpload ?? true;
121
121
  sanitized.upload.staticDir = sanitized.upload.staticDir || sanitized.slug;
122
- sanitized.admin.useAsTitle = sanitized.admin.useAsTitle && sanitized.admin.useAsTitle !== 'id' ? sanitized.admin.useAsTitle : 'filename';
122
+ sanitized.admin.useAsTitle = sanitized.admin?.useAsTitle && sanitized.admin.useAsTitle !== 'id' ? sanitized.admin.useAsTitle : 'filename';
123
123
  const uploadFields = getBaseUploadFields({
124
124
  collection: sanitized,
125
125
  config
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/config/sanitize.ts"],"sourcesContent":["import type { LoginWithUsernameOptions } from '../../auth/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { CollectionConfig, SanitizedCollectionConfig, SanitizedJoins } from './types.js'\n\nimport { getBaseAuthFields } from '../../auth/getAuthFields.js'\nimport { TimestampsRequired } from '../../errors/TimestampsRequired.js'\nimport { sanitizeFields } from '../../fields/config/sanitize.js'\nimport { fieldAffectsData } from '../../fields/config/types.js'\nimport mergeBaseFields from '../../fields/mergeBaseFields.js'\nimport { getBaseUploadFields } from '../../uploads/getBaseFields.js'\nimport { deepMergeWithReactComponents } from '../../utilities/deepMerge.js'\nimport { flattenAllFields } from '../../utilities/flattenAllFields.js'\nimport { formatLabels } from '../../utilities/formatLabels.js'\nimport baseVersionFields from '../../versions/baseFields.js'\nimport { versionDefaults } from '../../versions/defaults.js'\nimport { authDefaults, defaults, loginWithUsernameDefaults } from './defaults.js'\nimport { sanitizeAuthFields, sanitizeUploadFields } from './reservedFieldNames.js'\nimport { validateUseAsTitle } from './useAsTitle.js'\n\nexport const sanitizeCollection = async (\n config: Config,\n collection: CollectionConfig,\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>,\n): Promise<SanitizedCollectionConfig> => {\n // /////////////////////////////////\n // Make copy of collection config\n // /////////////////////////////////\n\n const sanitized: CollectionConfig = deepMergeWithReactComponents(defaults, collection)\n\n // /////////////////////////////////\n // Sanitize fields\n // /////////////////////////////////\n\n const validRelationships = config.collections.reduce(\n (acc, c) => {\n acc.push(c.slug)\n return acc\n },\n [collection.slug],\n )\n const joins: SanitizedJoins = {}\n sanitized.fields = await sanitizeFields({\n collectionConfig: sanitized,\n config,\n fields: sanitized.fields,\n joinPath: '',\n joins,\n parentIsLocalized: false,\n richTextSanitizationPromises,\n validRelationships,\n })\n\n if (sanitized.timestamps !== false) {\n // add default timestamps fields only as needed\n let hasUpdatedAt = null\n let hasCreatedAt = null\n sanitized.fields.some((field) => {\n if (fieldAffectsData(field)) {\n if (field.name === 'updatedAt') {\n hasUpdatedAt = true\n }\n if (field.name === 'createdAt') {\n hasCreatedAt = true\n }\n }\n return hasCreatedAt && hasUpdatedAt\n })\n if (!hasUpdatedAt) {\n sanitized.fields.push({\n name: 'updatedAt',\n type: 'date',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n index: true,\n label: ({ t }) => t('general:updatedAt'),\n })\n }\n if (!hasCreatedAt) {\n sanitized.fields.push({\n name: 'createdAt',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n // The default sort for list view is createdAt. Thus, enabling indexing by default, is a major performance improvement, especially for large or a large amount of collections.\n type: 'date',\n index: true,\n label: ({ t }) => t('general:createdAt'),\n })\n }\n }\n\n sanitized.labels = sanitized.labels || formatLabels(sanitized.slug)\n\n if (sanitized.versions) {\n if (sanitized.versions === true) {\n sanitized.versions = { drafts: false, maxPerDoc: 100 }\n }\n\n if (sanitized.timestamps === false) {\n throw new TimestampsRequired(collection)\n }\n\n sanitized.versions.maxPerDoc =\n typeof sanitized.versions.maxPerDoc === 'number' ? sanitized.versions.maxPerDoc : 100\n\n if (sanitized.versions.drafts) {\n if (sanitized.versions.drafts === true) {\n sanitized.versions.drafts = {\n autosave: false,\n validate: false,\n }\n }\n\n if (sanitized.versions.drafts.autosave === true) {\n sanitized.versions.drafts.autosave = {\n interval: versionDefaults.autosaveInterval,\n }\n }\n\n if (sanitized.versions.drafts.validate === undefined) {\n sanitized.versions.drafts.validate = false\n }\n\n sanitized.fields = mergeBaseFields(sanitized.fields, baseVersionFields)\n }\n }\n\n if (sanitized.upload) {\n if (sanitized.upload === true) {\n sanitized.upload = {}\n }\n\n // sanitize fields for reserved names\n sanitizeUploadFields(sanitized.fields, sanitized)\n\n sanitized.upload.bulkUpload = sanitized.upload?.bulkUpload ?? true\n sanitized.upload.staticDir = sanitized.upload.staticDir || sanitized.slug\n sanitized.admin.useAsTitle =\n sanitized.admin.useAsTitle && sanitized.admin.useAsTitle !== 'id'\n ? sanitized.admin.useAsTitle\n : 'filename'\n\n const uploadFields = getBaseUploadFields({\n collection: sanitized,\n config,\n })\n\n sanitized.fields = mergeBaseFields(sanitized.fields, uploadFields)\n }\n\n if (sanitized.auth) {\n // sanitize fields for reserved names\n sanitizeAuthFields(sanitized.fields, sanitized)\n\n sanitized.auth = deepMergeWithReactComponents(\n authDefaults,\n typeof sanitized.auth === 'object' ? sanitized.auth : {},\n )\n\n if (!sanitized.auth.disableLocalStrategy && sanitized.auth.verify === true) {\n sanitized.auth.verify = {}\n }\n\n // disable duplicate for auth enabled collections by default\n sanitized.disableDuplicate = sanitized.disableDuplicate ?? true\n\n if (!sanitized.auth.strategies) {\n sanitized.auth.strategies = []\n }\n\n if (sanitized.auth.loginWithUsername) {\n if (sanitized.auth.loginWithUsername === true) {\n sanitized.auth.loginWithUsername = loginWithUsernameDefaults\n } else {\n const loginWithUsernameWithDefaults = {\n ...loginWithUsernameDefaults,\n ...sanitized.auth.loginWithUsername,\n } as LoginWithUsernameOptions\n\n // if allowEmailLogin is false, requireUsername must be true\n if (loginWithUsernameWithDefaults.allowEmailLogin === false) {\n loginWithUsernameWithDefaults.requireUsername = true\n }\n sanitized.auth.loginWithUsername = loginWithUsernameWithDefaults\n }\n } else {\n sanitized.auth.loginWithUsername = false\n }\n\n sanitized.fields = mergeBaseFields(sanitized.fields, getBaseAuthFields(sanitized.auth))\n }\n\n if (collection?.admin?.pagination?.limits?.length) {\n sanitized.admin.pagination.limits = collection.admin.pagination.limits\n }\n\n validateUseAsTitle(sanitized)\n\n const sanitizedConfig = sanitized as SanitizedCollectionConfig\n\n sanitizedConfig.joins = joins\n\n sanitizedConfig.flattenedFields = flattenAllFields({ fields: sanitizedConfig.fields })\n\n return sanitizedConfig\n}\n"],"names":["getBaseAuthFields","TimestampsRequired","sanitizeFields","fieldAffectsData","mergeBaseFields","getBaseUploadFields","deepMergeWithReactComponents","flattenAllFields","formatLabels","baseVersionFields","versionDefaults","authDefaults","defaults","loginWithUsernameDefaults","sanitizeAuthFields","sanitizeUploadFields","validateUseAsTitle","sanitizeCollection","config","collection","richTextSanitizationPromises","sanitized","validRelationships","collections","reduce","acc","c","push","slug","joins","fields","collectionConfig","joinPath","parentIsLocalized","timestamps","hasUpdatedAt","hasCreatedAt","some","field","name","type","admin","disableBulkEdit","hidden","index","label","t","labels","versions","drafts","maxPerDoc","autosave","validate","interval","autosaveInterval","undefined","upload","bulkUpload","staticDir","useAsTitle","uploadFields","auth","disableLocalStrategy","verify","disableDuplicate","strategies","loginWithUsername","loginWithUsernameWithDefaults","allowEmailLogin","requireUsername","pagination","limits","length","sanitizedConfig","flattenedFields"],"mappings":"AAIA,SAASA,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,cAAc,QAAQ,kCAAiC;AAChE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,OAAOC,qBAAqB,kCAAiC;AAC7D,SAASC,mBAAmB,QAAQ,iCAAgC;AACpE,SAASC,4BAA4B,QAAQ,+BAA8B;AAC3E,SAASC,gBAAgB,QAAQ,sCAAqC;AACtE,SAASC,YAAY,QAAQ,kCAAiC;AAC9D,OAAOC,uBAAuB,+BAA8B;AAC5D,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,YAAY,EAAEC,QAAQ,EAAEC,yBAAyB,QAAQ,gBAAe;AACjF,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,0BAAyB;AAClF,SAASC,kBAAkB,QAAQ,kBAAiB;AAEpD,OAAO,MAAMC,qBAAqB,OAChCC,QACAC,YACA;;;GAGC,G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3DD,8BAA8BE,eAAe,GAAG;gBAClD;gBACAhD,UAAUwC,IAAI,CAACK,iBAAiB,GAAGC;YACrC;QACF,OAAO;YACL9C,UAAUwC,IAAI,CAACK,iBAAiB,GAAG;QACrC;QAEA7C,UAAUS,MAAM,GAAG1B,gBAAgBiB,UAAUS,MAAM,EAAE9B,kBAAkBqB,UAAUwC,IAAI;IACvF;IAEA,IAAI1C,YAAYsB,OAAO6B,YAAYC,QAAQC,QAAQ;QACjDnD,UAAUoB,KAAK,CAAC6B,UAAU,CAACC,MAAM,GAAGpD,WAAWsB,KAAK,CAAC6B,UAAU,CAACC,MAAM;IACxE;IAEAvD,mBAAmBK;IAEnB,MAAMoD,kBAAkBpD;IAExBoD,gBAAgB5C,KAAK,GAAGA;IAExB4C,gBAAgBC,eAAe,GAAGnE,iBAAiB;QAAEuB,QAAQ2C,gBAAgB3C,MAAM;IAAC;IAEpF,OAAO2C;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/config/sanitize.ts"],"sourcesContent":["import type { LoginWithUsernameOptions } from '../../auth/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { CollectionConfig, SanitizedCollectionConfig, SanitizedJoins } from './types.js'\n\nimport { getBaseAuthFields } from '../../auth/getAuthFields.js'\nimport { TimestampsRequired } from '../../errors/TimestampsRequired.js'\nimport { sanitizeFields } from '../../fields/config/sanitize.js'\nimport { fieldAffectsData } from '../../fields/config/types.js'\nimport mergeBaseFields from '../../fields/mergeBaseFields.js'\nimport { getBaseUploadFields } from '../../uploads/getBaseFields.js'\nimport { deepMergeWithReactComponents } from '../../utilities/deepMerge.js'\nimport { flattenAllFields } from '../../utilities/flattenAllFields.js'\nimport { formatLabels } from '../../utilities/formatLabels.js'\nimport baseVersionFields from '../../versions/baseFields.js'\nimport { versionDefaults } from '../../versions/defaults.js'\nimport { authDefaults, defaults, loginWithUsernameDefaults } from './defaults.js'\nimport { sanitizeAuthFields, sanitizeUploadFields } from './reservedFieldNames.js'\nimport { validateUseAsTitle } from './useAsTitle.js'\n\nexport const sanitizeCollection = async (\n config: Config,\n collection: CollectionConfig,\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>,\n): Promise<SanitizedCollectionConfig> => {\n // /////////////////////////////////\n // Make copy of collection config\n // /////////////////////////////////\n\n const sanitized: CollectionConfig = deepMergeWithReactComponents(defaults, collection)\n\n // /////////////////////////////////\n // Sanitize fields\n // /////////////////////////////////\n\n const validRelationships = (config.collections || []).reduce(\n (acc, c) => {\n acc.push(c.slug)\n return acc\n },\n [collection.slug],\n )\n const joins: SanitizedJoins = {}\n sanitized.fields = await sanitizeFields({\n collectionConfig: sanitized,\n config,\n fields: sanitized.fields,\n joinPath: '',\n joins,\n parentIsLocalized: false,\n richTextSanitizationPromises,\n validRelationships,\n })\n\n if (sanitized.timestamps !== false) {\n // add default timestamps fields only as needed\n let hasUpdatedAt: boolean | null = null\n let hasCreatedAt: boolean | null = null\n sanitized.fields.some((field) => {\n if (fieldAffectsData(field)) {\n if (field.name === 'updatedAt') {\n hasUpdatedAt = true\n }\n if (field.name === 'createdAt') {\n hasCreatedAt = true\n }\n }\n return hasCreatedAt && hasUpdatedAt\n })\n if (!hasUpdatedAt) {\n sanitized.fields.push({\n name: 'updatedAt',\n type: 'date',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n index: true,\n label: ({ t }) => t('general:updatedAt'),\n })\n }\n if (!hasCreatedAt) {\n sanitized.fields.push({\n name: 'createdAt',\n admin: {\n disableBulkEdit: true,\n hidden: true,\n },\n // The default sort for list view is createdAt. Thus, enabling indexing by default, is a major performance improvement, especially for large or a large amount of collections.\n type: 'date',\n index: true,\n label: ({ t }) => t('general:createdAt'),\n })\n }\n }\n\n sanitized.labels = sanitized.labels || formatLabels(sanitized.slug)\n\n if (sanitized.versions) {\n if (sanitized.versions === true) {\n sanitized.versions = { drafts: false, maxPerDoc: 100 }\n }\n\n if (sanitized.timestamps === false) {\n throw new TimestampsRequired(collection)\n }\n\n sanitized.versions.maxPerDoc =\n typeof sanitized.versions.maxPerDoc === 'number' ? sanitized.versions.maxPerDoc : 100\n\n if (sanitized.versions.drafts) {\n if (sanitized.versions.drafts === true) {\n sanitized.versions.drafts = {\n autosave: false,\n validate: false,\n }\n }\n\n if (sanitized.versions.drafts.autosave === true) {\n sanitized.versions.drafts.autosave = {\n interval: versionDefaults.autosaveInterval,\n }\n }\n\n if (sanitized.versions.drafts.validate === undefined) {\n sanitized.versions.drafts.validate = false\n }\n\n sanitized.fields = mergeBaseFields(sanitized.fields, baseVersionFields)\n }\n }\n\n if (sanitized.upload) {\n if (sanitized.upload === true) {\n sanitized.upload = {}\n }\n\n // sanitize fields for reserved names\n sanitizeUploadFields(sanitized.fields, sanitized)\n\n sanitized.upload.bulkUpload = sanitized.upload?.bulkUpload ?? true\n sanitized.upload.staticDir = sanitized.upload.staticDir || sanitized.slug\n sanitized.admin.useAsTitle =\n sanitized.admin?.useAsTitle && sanitized.admin.useAsTitle !== 'id'\n ? sanitized.admin.useAsTitle\n : 'filename'\n\n const uploadFields = getBaseUploadFields({\n collection: sanitized,\n config,\n })\n\n sanitized.fields = mergeBaseFields(sanitized.fields, uploadFields)\n }\n\n if (sanitized.auth) {\n // sanitize fields for reserved names\n sanitizeAuthFields(sanitized.fields, sanitized)\n\n sanitized.auth = deepMergeWithReactComponents(\n authDefaults,\n typeof sanitized.auth === 'object' ? sanitized.auth : {},\n )\n\n if (!sanitized.auth.disableLocalStrategy && sanitized.auth.verify === true) {\n sanitized.auth.verify = {}\n }\n\n // disable duplicate for auth enabled collections by default\n sanitized.disableDuplicate = sanitized.disableDuplicate ?? true\n\n if (!sanitized.auth.strategies) {\n sanitized.auth.strategies = []\n }\n\n if (sanitized.auth.loginWithUsername) {\n if (sanitized.auth.loginWithUsername === true) {\n sanitized.auth.loginWithUsername = loginWithUsernameDefaults\n } else {\n const loginWithUsernameWithDefaults = {\n ...loginWithUsernameDefaults,\n ...sanitized.auth.loginWithUsername,\n } as LoginWithUsernameOptions\n\n // if allowEmailLogin is false, requireUsername must be true\n if (loginWithUsernameWithDefaults.allowEmailLogin === false) {\n loginWithUsernameWithDefaults.requireUsername = true\n }\n sanitized.auth.loginWithUsername = loginWithUsernameWithDefaults\n }\n } else {\n sanitized.auth.loginWithUsername = false\n }\n\n sanitized.fields = mergeBaseFields(sanitized.fields, getBaseAuthFields(sanitized.auth))\n }\n\n if (collection?.admin?.pagination?.limits?.length) {\n sanitized.admin.pagination.limits = collection.admin.pagination.limits\n }\n\n validateUseAsTitle(sanitized)\n\n const sanitizedConfig = sanitized as SanitizedCollectionConfig\n\n sanitizedConfig.joins = joins\n\n sanitizedConfig.flattenedFields = flattenAllFields({ fields: sanitizedConfig.fields })\n\n return sanitizedConfig\n}\n"],"names":["getBaseAuthFields","TimestampsRequired","sanitizeFields","fieldAffectsData","mergeBaseFields","getBaseUploadFields","deepMergeWithReactComponents","flattenAllFields","formatLabels","baseVersionFields","versionDefaults","authDefaults","defaults","loginWithUsernameDefaults","sanitizeAuthFields","sanitizeUploadFields","validateUseAsTitle","sanitizeCollection","config","collection","richTextSanitizationPromises","sanitized","validRelationships","collections","reduce","acc","c","push","slug","joins","fields","collectionConfig","joinPath","parentIsLocalized","timestamps","hasUpdatedAt","hasCreatedAt","some","field","name","type","admin","disableBulkEdit","hidden","index","label","t","labels","versions","drafts","maxPerDoc","autosave","validate","interval","autosaveInterval","undefined","upload","bulkUpload","staticDir","useAsTitle","uploadFields","auth","disableLocalStrategy","verify","disableDuplicate","strategies","loginWithUsername","loginWithUsernameWithDefaults","allowEmailLogin","requireUsername","pagination","limits","length","sanitizedConfig","flattenedFields"],"mappings":"AAIA,SAASA,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,cAAc,QAAQ,kCAAiC;AAChE,SAAS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EA,4DAA4D;QAC5D1C,UAAU2C,gBAAgB,GAAG3C,UAAU2C,gBAAgB,IAAI;QAE3D,IAAI,CAAC3C,UAAUwC,IAAI,CAACI,UAAU,EAAE;YAC9B5C,UAAUwC,IAAI,CAACI,UAAU,GAAG,EAAE;QAChC;QAEA,IAAI5C,UAAUwC,IAAI,CAACK,iBAAiB,EAAE;YACpC,IAAI7C,UAAUwC,IAAI,CAACK,iBAAiB,KAAK,MAAM;gBAC7C7C,UAAUwC,IAAI,CAACK,iBAAiB,GAAGrD;YACrC,OAAO;gBACL,MAAMsD,gCAAgC;oBACpC,GAAGtD,yBAAyB;oBAC5B,GAAGQ,UAAUwC,IAAI,CAACK,iBAAiB;gBACrC;gBAEA,4DAA4D;gBAC5D,IAAIC,8BAA8BC,eAAe,KAAK,OAAO;oBAC3DD,8BAA8BE,eAAe,GAAG;gBAClD;gBACAhD,UAAUwC,IAAI,CAACK,iBAAiB,GAAGC;YACrC;QACF,OAAO;YACL9C,UAAUwC,IAAI,CAACK,iBAAiB,GAAG;QACrC;QAEA7C,UAAUS,MAAM,GAAG1B,gBAAgBiB,UAAUS,MAAM,EAAE9B,kBAAkBqB,UAAUwC,IAAI;IACvF;IAEA,IAAI1C,YAAYsB,OAAO6B,YAAYC,QAAQC,QAAQ;QACjDnD,UAAUoB,KAAK,CAAC6B,UAAU,CAACC,MAAM,GAAGpD,WAAWsB,KAAK,CAAC6B,UAAU,CAACC,MAAM;IACxE;IAEAvD,mBAAmBK;IAEnB,MAAMoD,kBAAkBpD;IAExBoD,gBAAgB5C,KAAK,GAAGA;IAExB4C,gBAAgBC,eAAe,GAAGnE,iBAAiB;QAAEuB,QAAQ2C,gBAAgB3C,MAAM;IAAC;IAEpF,OAAO2C;AACT,EAAC"}
@@ -4,7 +4,7 @@ import flattenFields from '../../utilities/flattenTopLevelFields.js';
4
4
  /**
5
5
  * Validate useAsTitle for collections.
6
6
  */ export const validateUseAsTitle = (config)=>{
7
- if (config.admin.useAsTitle.includes('.')) {
7
+ if (config.admin?.useAsTitle?.includes('.')) {
8
8
  throw new InvalidConfiguration(`"useAsTitle" cannot be a nested field. Please specify a top-level field in the collection "${config.slug}"`);
9
9
  }
10
10
  if (config?.admin && config.admin?.useAsTitle && config.admin.useAsTitle !== 'id') {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/config/useAsTitle.ts"],"sourcesContent":["import type { CollectionConfig } from '../../index.js'\n\nimport { InvalidConfiguration } from '../../errors/InvalidConfiguration.js'\nimport { fieldAffectsData, fieldIsVirtual } from '../../fields/config/types.js'\nimport flattenFields from '../../utilities/flattenTopLevelFields.js'\n\n/**\n * Validate useAsTitle for collections.\n */\nexport const validateUseAsTitle = (config: CollectionConfig) => {\n if (config.admin.useAsTitle.includes('.')) {\n throw new InvalidConfiguration(\n `\"useAsTitle\" cannot be a nested field. Please specify a top-level field in the collection \"${config.slug}\"`,\n )\n }\n\n if (config?.admin && config.admin?.useAsTitle && config.admin.useAsTitle !== 'id') {\n const fields = flattenFields(config.fields)\n const useAsTitleField = fields.find((field) => {\n if (fieldAffectsData(field) && config.admin) {\n return field.name === config.admin.useAsTitle\n }\n return false\n })\n\n // If auth is enabled then we don't need to\n if (config.auth) {\n if (config.admin.useAsTitle !== 'email') {\n if (!useAsTitleField) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" does not exist in the collection \"${config.slug}\"`,\n )\n }\n }\n } else {\n if (useAsTitleField && fieldIsVirtual(useAsTitleField)) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" in the collection \"${config.slug}\" is virtual. A virtual field cannot be used as the title.`,\n )\n }\n if (!useAsTitleField) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" does not exist in the collection \"${config.slug}\"`,\n )\n }\n }\n }\n}\n"],"names":["InvalidConfiguration","fieldAffectsData","fieldIsVirtual","flattenFields","validateUseAsTitle","config","admin","useAsTitle","includes","slug","fields","useAsTitleField","find","field","name","auth"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,+BAA8B;AAC/E,OAAOC,mBAAmB,2CAA0C;AAEpE;;CAEC,GACD,OAAO,MAAMC,qBAAqB,CAACC;IACjC,IAAIA,OAAOC,KAAK,CAACC,UAAU,CAACC,QAAQ,CAAC,MAAM;QACzC,MAAM,IAAIR,qBACR,CAAC,2FAA2F,EAAEK,OAAOI,IAAI,CAAC,CAAC,CAAC;IAEhH;IAEA,IAAIJ,QAAQC,SAASD,OAAOC,KAAK,EAAEC,cAAcF,OAAOC,KAAK,CAACC,UAAU,KAAK,MAAM;QACjF,MAAMG,SAASP,cAAcE,OAAOK,MAAM;QAC1C,MAAMC,kBAAkBD,OAAOE,IAAI,CAAC,CAACC;YACnC,IAAIZ,iBAAiBY,UAAUR,OAAOC,KAAK,EAAE;gBAC3C,OAAOO,MAAMC,IAAI,KAAKT,OAAOC,KAAK,CAACC,UAAU;YAC/C;YACA,OAAO;QACT;QAEA,2CAA2C;QAC3C,IAAIF,OAAOU,IAAI,EAAE;YACf,IAAIV,OAAOC,KAAK,CAACC,UAAU,KAAK,SAAS;gBACvC,IAAI,CAACI,iBAAiB;oBACpB,MAAM,IAAIX,qBACR,CAAC,WAAW,EAAEK,OAAOC,KAAK,CAACC,UAAU,CAAC,oEAAoE,EAAEF,OAAOI,IAAI,CAAC,CAAC,CAAC;gBAE9H;YACF;QACF,OAAO;YACL,IAAIE,mBAAmBT,eAAeS,kBAAkB;gBACtD,MAAM,IAAIX,qBACR,CAAC,WAAW,EAAEK,OAAOC,KAAK,CAACC,UAAU,CAAC,qDAAqD,EAAEF,OAAOI,IAAI,CAAC,0DAA0D,CAAC;YAExK;YACA,IAAI,CAACE,iBAAiB;gBACpB,MAAM,IAAIX,qBACR,CAAC,WAAW,EAAEK,OAAOC,KAAK,CAACC,UAAU,CAAC,oEAAoE,EAAEF,OAAOI,IAAI,CAAC,CAAC,CAAC;YAE9H;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/config/useAsTitle.ts"],"sourcesContent":["import type { CollectionConfig } from '../../index.js'\n\nimport { InvalidConfiguration } from '../../errors/InvalidConfiguration.js'\nimport { fieldAffectsData, fieldIsVirtual } from '../../fields/config/types.js'\nimport flattenFields from '../../utilities/flattenTopLevelFields.js'\n\n/**\n * Validate useAsTitle for collections.\n */\nexport const validateUseAsTitle = (config: CollectionConfig) => {\n if (config.admin?.useAsTitle?.includes('.')) {\n throw new InvalidConfiguration(\n `\"useAsTitle\" cannot be a nested field. Please specify a top-level field in the collection \"${config.slug}\"`,\n )\n }\n\n if (config?.admin && config.admin?.useAsTitle && config.admin.useAsTitle !== 'id') {\n const fields = flattenFields(config.fields)\n const useAsTitleField = fields.find((field) => {\n if (fieldAffectsData(field) && config.admin) {\n return field.name === config.admin.useAsTitle\n }\n return false\n })\n\n // If auth is enabled then we don't need to\n if (config.auth) {\n if (config.admin.useAsTitle !== 'email') {\n if (!useAsTitleField) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" does not exist in the collection \"${config.slug}\"`,\n )\n }\n }\n } else {\n if (useAsTitleField && fieldIsVirtual(useAsTitleField)) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" in the collection \"${config.slug}\" is virtual. A virtual field cannot be used as the title.`,\n )\n }\n if (!useAsTitleField) {\n throw new InvalidConfiguration(\n `The field \"${config.admin.useAsTitle}\" specified in \"admin.useAsTitle\" does not exist in the collection \"${config.slug}\"`,\n )\n }\n }\n }\n}\n"],"names":["InvalidConfiguration","fieldAffectsData","fieldIsVirtual","flattenFields","validateUseAsTitle","config","admin","useAsTitle","includes","slug","fields","useAsTitleField","find","field","name","auth"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SA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gs)=>{
72
72
  overrideAccess,
73
73
  req,
74
74
  versionFields: buildVersionCollectionFields(payload.config, collection.config, true),
75
- where: fullWhere
75
+ where: appendVersionToQueryKey(where)
76
76
  });
77
77
  result = await payload.db.queryDrafts({
78
78
  collection: collectionConfig.slug,