payload 3.26.0 → 3.27.0-canary.672dace

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 (72) hide show
  1. package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
  2. package/dist/auth/operations/forgotPassword.js +7 -1
  3. package/dist/auth/operations/forgotPassword.js.map +1 -1
  4. package/dist/bin/generateImportMap/index.d.ts.map +1 -1
  5. package/dist/bin/generateImportMap/index.js +15 -7
  6. package/dist/bin/generateImportMap/index.js.map +1 -1
  7. package/dist/collections/config/client.d.ts +1 -1
  8. package/dist/collections/config/client.d.ts.map +1 -1
  9. package/dist/collections/config/client.js +3 -1
  10. package/dist/collections/config/client.js.map +1 -1
  11. package/dist/collections/config/defaults.d.ts +12 -0
  12. package/dist/collections/config/defaults.d.ts.map +1 -1
  13. package/dist/collections/config/defaults.js +92 -3
  14. package/dist/collections/config/defaults.js.map +1 -1
  15. package/dist/collections/config/sanitize.d.ts.map +1 -1
  16. package/dist/collections/config/sanitize.js +14 -15
  17. package/dist/collections/config/sanitize.js.map +1 -1
  18. package/dist/collections/config/sanitizeCompoundIndexes.d.ts +7 -0
  19. package/dist/collections/config/sanitizeCompoundIndexes.d.ts.map +1 -0
  20. package/dist/collections/config/sanitizeCompoundIndexes.js +39 -0
  21. package/dist/collections/config/sanitizeCompoundIndexes.js.map +1 -0
  22. package/dist/collections/config/types.d.ts +29 -0
  23. package/dist/collections/config/types.d.ts.map +1 -1
  24. package/dist/collections/config/types.js.map +1 -1
  25. package/dist/config/defaults.d.ts +4 -0
  26. package/dist/config/defaults.d.ts.map +1 -1
  27. package/dist/config/defaults.js +79 -1
  28. package/dist/config/defaults.js.map +1 -1
  29. package/dist/config/sanitize.d.ts.map +1 -1
  30. package/dist/config/sanitize.js +21 -57
  31. package/dist/config/sanitize.js.map +1 -1
  32. package/dist/config/types.d.ts +48 -19
  33. package/dist/config/types.d.ts.map +1 -1
  34. package/dist/config/types.js.map +1 -1
  35. package/dist/exports/shared.d.ts +1 -0
  36. package/dist/exports/shared.d.ts.map +1 -1
  37. package/dist/exports/shared.js +1 -0
  38. package/dist/exports/shared.js.map +1 -1
  39. package/dist/fields/config/sanitize.d.ts.map +1 -1
  40. package/dist/fields/config/sanitize.js +3 -3
  41. package/dist/fields/config/sanitize.js.map +1 -1
  42. package/dist/globals/config/sanitize.d.ts.map +1 -1
  43. package/dist/globals/config/sanitize.js +4 -1
  44. package/dist/globals/config/sanitize.js.map +1 -1
  45. package/dist/globals/config/types.d.ts +5 -0
  46. package/dist/globals/config/types.d.ts.map +1 -1
  47. package/dist/globals/config/types.js.map +1 -1
  48. package/dist/index.d.ts +3 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/queues/config/jobsCollection.d.ts.map +1 -1
  53. package/dist/queues/config/jobsCollection.js +2 -5
  54. package/dist/queues/config/jobsCollection.js.map +1 -1
  55. package/dist/utilities/configToJSONSchema.spec.js +73 -0
  56. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  57. package/dist/utilities/formatAdminURL.d.ts +9 -0
  58. package/dist/utilities/formatAdminURL.d.ts.map +1 -0
  59. package/dist/utilities/formatAdminURL.js +16 -0
  60. package/dist/utilities/formatAdminURL.js.map +1 -0
  61. package/dist/utilities/getFieldByPath.d.ts +17 -0
  62. package/dist/utilities/getFieldByPath.d.ts.map +1 -0
  63. package/dist/utilities/getFieldByPath.js +51 -0
  64. package/dist/utilities/getFieldByPath.js.map +1 -0
  65. package/dist/versions/buildVersionCompoundIndexes.d.ts +5 -0
  66. package/dist/versions/buildVersionCompoundIndexes.d.ts.map +1 -0
  67. package/dist/versions/buildVersionCompoundIndexes.js +13 -0
  68. package/dist/versions/buildVersionCompoundIndexes.js.map +1 -0
  69. package/dist/versions/payloadPackageList.d.ts.map +1 -1
  70. package/dist/versions/payloadPackageList.js +1 -0
  71. package/dist/versions/payloadPackageList.js.map +1 -1
  72. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"forgotPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/forgotPassword.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACX,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAA;AAUjE,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,GAAG,gCAAgC,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,CAAA;IAC7D,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,uBAAuB,GAAU,KAAK,SAAS,cAAc,gBAC1D,SAAS,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC,IAAI,GAAG,MAAM,CAwLvB,CAAA"}
1
+ {"version":3,"file":"forgotPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/forgotPassword.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACX,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAA;AAWjE,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,GAAG,gCAAgC,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,CAAA;IAC7D,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,uBAAuB,GAAU,KAAK,SAAS,cAAc,gBAC1D,SAAS,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC,IAAI,GAAG,MAAM,CA4LvB,CAAA"}
@@ -6,6 +6,7 @@ import { buildAfterOperation } from '../../collections/operations/utils.js';
6
6
  import { APIError } from '../../errors/index.js';
7
7
  import { Forbidden } from '../../index.js';
8
8
  import { commitTransaction } from '../../utilities/commitTransaction.js';
9
+ import { formatAdminURL } from '../../utilities/formatAdminURL.js';
9
10
  import { initTransaction } from '../../utilities/initTransaction.js';
10
11
  import { killTransaction } from '../../utilities/killTransaction.js';
11
12
  import { getLoginOptions } from '../getLoginOptions.js';
@@ -84,8 +85,13 @@ export const forgotPasswordOperation = async (incomingArgs)=>{
84
85
  const protocol = new URL(req.url).protocol // includes the final :
85
86
  ;
86
87
  const serverURL = config.serverURL !== null && config.serverURL !== '' ? config.serverURL : `${protocol}//${req.headers.get('host')}`;
88
+ const forgotURL = formatAdminURL({
89
+ adminRoute: config.routes.admin,
90
+ path: `${config.admin.routes.reset}/${token}`,
91
+ serverURL
92
+ });
87
93
  let html = `${req.t('authentication:youAreReceivingResetPassword')}
88
- <a href="${serverURL}${config.routes.admin}${config.admin.routes.reset}/${token}">${serverURL}${config.routes.admin}${config.admin.routes.reset}/${token}</a>
94
+ <a href="${forgotURL}">${forgotURL}</a>
89
95
  ${req.t('authentication:youDidNotRequestPassword')}`;
90
96
  if (typeof collectionConfig.auth.forgotPassword?.generateEmailHTML === 'function') {
91
97
  html = await collectionConfig.auth.forgotPassword.generateEmailHTML({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/operations/forgotPassword.ts"],"sourcesContent":["// @ts-strict-ignore\nimport crypto from 'crypto'\nimport { status as httpStatus } from 'http-status'\nimport { URL } from 'url'\n\nimport type {\n AuthOperationsFromCollectionSlug,\n Collection,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { APIError } from '../../errors/index.js'\nimport { Forbidden } from '../../index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLoginOptions } from '../getLoginOptions.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: {\n [key: string]: unknown\n } & AuthOperationsFromCollectionSlug<TSlug>['forgotPassword']\n disableEmail?: boolean\n expiration?: number\n req: PayloadRequest\n}\n\nexport type Result = string\n\nexport const forgotPasswordOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments<TSlug>,\n): Promise<null | string> => {\n const loginWithUsername = incomingArgs.collection.config.auth.loginWithUsername\n const { data } = incomingArgs\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n const sanitizedEmail =\n (canLoginWithEmail && (incomingArgs.data.email || '').toLowerCase().trim()) || null\n const sanitizedUsername =\n 'username' in data && typeof data?.username === 'string'\n ? data.username.toLowerCase().trim()\n : null\n\n let args = incomingArgs\n\n if (incomingArgs.collection.config.auth.disableLocalStrategy) {\n throw new Forbidden(incomingArgs.req.t)\n }\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'forgotPassword',\n req: args.req,\n })) || args\n }\n }\n\n const {\n collection: { config: collectionConfig },\n disableEmail,\n expiration,\n req: {\n payload: { config, email },\n payload,\n },\n req,\n } = args\n\n // /////////////////////////////////////\n // Forget password\n // /////////////////////////////////////\n\n let token: string = crypto.randomBytes(20).toString('hex')\n type UserDoc = {\n email?: string\n id: number | string\n resetPasswordExpiration?: string\n resetPasswordToken?: string\n }\n\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n let whereConstraint: Where = {}\n\n if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = {\n email: {\n equals: sanitizedEmail,\n },\n }\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = {\n username: {\n equals: sanitizedUsername,\n },\n }\n }\n\n let user = await payload.db.findOne<UserDoc>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n // We don't want to indicate specifically that an email was not found,\n // as doing so could lead to the exposure of registered emails.\n // Therefore, we prefer to fail silently.\n if (!user) {\n await commitTransaction(args.req)\n return null\n }\n\n user.resetPasswordToken = token\n user.resetPasswordExpiration = new Date(\n Date.now() + (collectionConfig.auth?.forgotPassword?.expiration ?? expiration ?? 3600000),\n ).toISOString()\n\n user = await payload.update({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n if (!disableEmail && user.email) {\n const protocol = new URL(req.url).protocol // includes the final :\n const serverURL =\n config.serverURL !== null && config.serverURL !== ''\n ? config.serverURL\n : `${protocol}//${req.headers.get('host')}`\n\n let html = `${req.t('authentication:youAreReceivingResetPassword')}\n <a href=\"${serverURL}${config.routes.admin}${config.admin.routes.reset}/${token}\">${serverURL}${config.routes.admin}${config.admin.routes.reset}/${token}</a>\n ${req.t('authentication:youDidNotRequestPassword')}`\n\n if (typeof collectionConfig.auth.forgotPassword?.generateEmailHTML === 'function') {\n html = await collectionConfig.auth.forgotPassword.generateEmailHTML({\n req,\n token,\n user,\n })\n }\n\n let subject = req.t('authentication:resetYourPassword')\n\n if (typeof collectionConfig.auth.forgotPassword?.generateEmailSubject === 'function') {\n subject = await collectionConfig.auth.forgotPassword.generateEmailSubject({\n req,\n token,\n user,\n })\n }\n\n await email.sendEmail({\n from: `\"${email.defaultFromName}\" <${email.defaultFromAddress}>`,\n html,\n subject,\n to: user.email,\n })\n }\n\n // /////////////////////////////////////\n // afterForgotPassword - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterForgotPassword?.length) {\n for (const hook of collectionConfig.hooks.afterForgotPassword) {\n await hook({ args, collection: args.collection?.config, context: req.context })\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n token = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'forgotPassword',\n result: token,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return token\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","status","httpStatus","URL","buildAfterOperation","APIError","Forbidden","commitTransaction","initTransaction","killTransaction","getLoginOptions","forgotPasswordOperation","incomingArgs","loginWithUsername","collection","config","auth","data","canLoginWithEmail","canLoginWithUsername","sanitizedEmail","email","toLowerCase","trim","sanitizedUsername","username","args","disableLocalStrategy","req","t","BAD_REQUEST","shouldCommit","hooks","beforeOperation","length","hook","context","operation","collectionConfig","disableEmail","expiration","payload","token","randomBytes","toString","whereConstraint","equals","user","db","findOne","slug","where","resetPasswordToken","resetPasswordExpiration","Date","now","forgotPassword","toISOString","update","id","protocol","url","serverURL","headers","get","html","routes","admin","reset","generateEmailHTML","subject","generateEmailSubject","sendEmail","from","defaultFromName","defaultFromAddress","to","afterForgotPassword","result","error"],"mappings":"AAAA,oBAAoB;AACpB,OAAOA,YAAY,SAAQ;A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BAAiBtB,IAAI,CAACwC,cAAc,CAACe,oBAAoB,CAAC;oBACxE3C;oBACAc;oBACAK;gBACF;YACF;YAEA,MAAM1B,MAAMmD,SAAS,CAAC;gBACpBC,MAAM,CAAC,CAAC,EAAEpD,MAAMqD,eAAe,CAAC,GAAG,EAAErD,MAAMsD,kBAAkB,CAAC,CAAC,CAAC;gBAChEV;gBACAK;gBACAM,IAAI7B,KAAK1B,KAAK;YAChB;QACF;QAEA,wCAAwC;QACxC,mCAAmC;QACnC,wCAAwC;QAExC,IAAIiB,iBAAiBN,KAAK,EAAE6C,qBAAqB3C,QAAQ;YACvD,KAAK,MAAMC,QAAQG,iBAAiBN,KAAK,CAAC6C,mBAAmB,CAAE;gBAC7D,MAAM1C,KAAK;oBAAET;oBAAMZ,YAAYY,KAAKZ,UAAU,EAAEC;oBAAQqB,SAASR,IAAIQ,OAAO;gBAAC;YAC/E;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCM,QAAQ,MAAMtC,oBAAoB;YAChCsB;YACAZ,YAAYY,KAAKZ,UAAU,EAAEC;YAC7BsB,WAAW;YACXyC,QAAQpC;QACV;QAEA,IAAIX,cAAc;YAChB,MAAMxB,kBAAkBqB;QAC1B;QAEA,OAAOc;IACT,EAAE,OAAOqC,OAAgB;QACvB,MAAMtE,gBAAgBiB,KAAKE,GAAG;QAC9B,MAAMmD;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/operations/forgotPassword.ts"],"sourcesContent":["// @ts-strict-ignore\nimport crypto from 'crypto'\nimport { status as httpStatus } from 'http-status'\nimport { URL } from 'url'\n\nimport type {\n AuthOperationsFromCollectionSlug,\n Collection,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { APIError } from '../../errors/index.js'\nimport { Forbidden } from '../../index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { formatAdminURL } from '../../utilities/formatAdminURL.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLoginOptions } from '../getLoginOptions.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: {\n [key: string]: unknown\n } & AuthOperationsFromCollectionSlug<TSlug>['forgotPassword']\n disableEmail?: boolean\n expiration?: number\n req: PayloadRequest\n}\n\nexport type Result = string\n\nexport const forgotPasswordOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments<TSlug>,\n): Promise<null | string> => {\n const loginWithUsername = incomingArgs.collection.config.auth.loginWithUsername\n const { data } = incomingArgs\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n const sanitizedEmail =\n (canLoginWithEmail && (incomingArgs.data.email || '').toLowerCase().trim()) || null\n const sanitizedUsername =\n 'username' in data && typeof data?.username === 'string'\n ? data.username.toLowerCase().trim()\n : null\n\n let args = incomingArgs\n\n if (incomingArgs.collection.config.auth.disableLocalStrategy) {\n throw new Forbidden(incomingArgs.req.t)\n }\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'forgotPassword',\n req: args.req,\n })) || args\n }\n }\n\n const {\n collection: { config: collectionConfig },\n disableEmail,\n expiration,\n req: {\n payload: { config, email },\n payload,\n },\n req,\n } = args\n\n // /////////////////////////////////////\n // Forget password\n // /////////////////////////////////////\n\n let token: string = crypto.randomBytes(20).toString('hex')\n type UserDoc = {\n email?: string\n id: number | string\n resetPasswordExpiration?: string\n resetPasswordToken?: string\n }\n\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n let whereConstraint: Where = {}\n\n if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = {\n email: {\n equals: sanitizedEmail,\n },\n }\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = {\n username: {\n equals: sanitizedUsername,\n },\n }\n }\n\n let user = await payload.db.findOne<UserDoc>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n // We don't want to indicate specifically that an email was not found,\n // as doing so could lead to the exposure of registered emails.\n // Therefore, we prefer to fail silently.\n if (!user) {\n await commitTransaction(args.req)\n return null\n }\n\n user.resetPasswordToken = token\n user.resetPasswordExpiration = new Date(\n Date.now() + (collectionConfig.auth?.forgotPassword?.expiration ?? expiration ?? 3600000),\n ).toISOString()\n\n user = await payload.update({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n if (!disableEmail && user.email) {\n const protocol = new URL(req.url).protocol // includes the final :\n const serverURL =\n config.serverURL !== null && config.serverURL !== ''\n ? config.serverURL\n : `${protocol}//${req.headers.get('host')}`\n const forgotURL = formatAdminURL({\n adminRoute: config.routes.admin,\n path: `${config.admin.routes.reset}/${token}`,\n serverURL,\n })\n let html = `${req.t('authentication:youAreReceivingResetPassword')}\n <a href=\"${forgotURL}\">${forgotURL}</a>\n ${req.t('authentication:youDidNotRequestPassword')}`\n\n if (typeof collectionConfig.auth.forgotPassword?.generateEmailHTML === 'function') {\n html = await collectionConfig.auth.forgotPassword.generateEmailHTML({\n req,\n token,\n user,\n })\n }\n\n let subject = req.t('authentication:resetYourPassword')\n\n if (typeof collectionConfig.auth.forgotPassword?.generateEmailSubject === 'function') {\n subject = await collectionConfig.auth.forgotPassword.generateEmailSubject({\n req,\n token,\n user,\n })\n }\n\n await email.sendEmail({\n from: `\"${email.defaultFromName}\" <${email.defaultFromAddress}>`,\n html,\n subject,\n to: user.email,\n })\n }\n\n // /////////////////////////////////////\n // afterForgotPassword - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterForgotPassword?.length) {\n for (const hook of collectionConfig.hooks.afterForgotPassword) {\n await hook({ args, collection: args.collection?.config, context: req.context })\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n token = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'forgotPassword',\n result: token,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return token\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","status","httpStatus","URL","buildAfterOperation","APIError","Forbidden","commitTransaction","formatAdminURL","initTransaction","killTransaction","getLoginOptions","forgotPasswordOperation","incomingArgs","loginWithUsername","collection","config","auth","data","canLoginWithEmail","canLoginWithUsername","sanitizedEmail","email","toLowerCase","trim","sanitizedUsername","username","args","disableLocalStrategy","req","t","BAD_REQUEST","shouldCommit","hooks","beforeOperation","length","hook","context","operation","collectionConfig","disableEmail","expiration","payload","token","randomBytes","toString","whereConstraint","equals","user","db","findOne","slug","where","resetPasswordToken","resetPasswordExpiration","Date","now","forgotPassword","toISOString","update","id","protocol","url","serverURL","headers","get","forgotURL","adminRoute","routes","admin","path","reset","html","generateEmailHTML","subject","generateEmailSubject","sendEmail","from","defaultFromName","defaultFromAddress","to","afterForgotPassword","result","error"],"mappings":"AAAA,oBAAoB;AACpB,OAAOA,YAAY,SAAQ;AAC3B,SAASC,UAAUC,UAAU,QAAQ,cAAa;AAClD,SAASC,GAAG,QAAQ,MAAK;AASzB,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SA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MAAM,CAAA;CAChB,iBA2DA"}
@@ -116,13 +116,22 @@ export async function generateImportMap(config, options) {
116
116
  });
117
117
  }
118
118
  export async function writeImportMap({ componentMap, config, fileName, force, importMap, log, rootDir }) {
119
- let importMapFolderPath = '';
120
- if (fs.existsSync(path.resolve(rootDir, `app/(payload)${config.routes.admin}/`))) {
121
- importMapFolderPath = path.resolve(rootDir, `app/(payload)${config.routes.admin}/`);
122
- } else if (fs.existsSync(path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`))) {
123
- importMapFolderPath = path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`);
119
+ let importMapFilePath = undefined;
120
+ if (config?.admin?.importMap?.importMapFile?.length) {
121
+ if (!fs.existsSync(config.admin.importMap.importMapFile)) {
122
+ throw new Error(`Could not find the import map file at ${config.admin.importMap.importMapFile}`);
123
+ }
124
+ importMapFilePath = config.admin.importMap.importMapFile;
124
125
  } else {
125
- throw new Error(`Could not find the payload admin directory. Looked in ${path.resolve(rootDir, `app/(payload)${config.routes.admin}/`)} and ${path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`)}`);
126
+ const appLocation = path.resolve(rootDir, `app/(payload)${config.routes.admin}/`);
127
+ const srcAppLocation = path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`);
128
+ if (fs.existsSync(appLocation)) {
129
+ importMapFilePath = path.resolve(appLocation, fileName);
130
+ } else if (fs.existsSync(srcAppLocation)) {
131
+ importMapFilePath = path.resolve(srcAppLocation, fileName);
132
+ } else {
133
+ throw new Error(`Could not find Payload import map folder. Looked in ${appLocation} and ${srcAppLocation}`);
134
+ }
126
135
  }
127
136
  const imports = [];
128
137
  for (const [identifier, { path, specifier }] of Object.entries(importMap)){
@@ -138,7 +147,6 @@ export const importMap = {
138
147
  ${mapKeys.join(',\n')}
139
148
  }
140
149
  `;
141
- const importMapFilePath = path.resolve(importMapFolderPath, fileName);
142
150
  if (!force) {
143
151
  // Read current import map and check in the IMPORTS if there are any new imports. If not, don't write the file.
144
152
  const currentImportMap = await fs.promises.readFile(importMapFilePath, 'utf-8');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/bin/generateImportMap/index.ts"],"sourcesContent":["import crypto from 'crypto'\nimport fs from 'fs'\nimport process from 'node:process'\nimport path from 'path'\n\nimport type { PayloadComponent, SanitizedConfig } from '../../config/types.js'\n\nimport { iterateConfig } from './iterateConfig.js'\nimport { parsePayloadComponent } from './parsePayloadComponent.js'\n\ntype ImportIdentifier = string\ntype ImportSpecifier = string\ntype ImportPath = string\ntype UserImportPath = string\n\n/**\n * Import Map before being written to the file. Only contains all paths\n */\nexport type InternalImportMap = {\n [path: UserImportPath]: ImportIdentifier\n}\n\n/**\n * Imports of the import map.\n */\nexport type Imports = {\n [identifier: ImportIdentifier]: {\n path: ImportPath\n specifier: ImportSpecifier\n }\n}\n\n/**\n * Import Map after being imported from the actual import map. Contains all the actual imported components\n */\nexport type ImportMap = {\n [path: UserImportPath]: any\n}\n\nexport function addPayloadComponentToImportMap({\n baseDir,\n importMap,\n imports,\n payloadComponent,\n}: {\n baseDir: string\n importMap: InternalImportMap\n imports: Imports\n payloadComponent: PayloadComponent\n}) {\n if (!payloadComponent) {\n return\n }\n const { exportName, path: componentPath } = parsePayloadComponent(payloadComponent)\n\n if (importMap[componentPath + '#' + exportName]) {\n return\n }\n\n const importIdentifier =\n exportName + '_' + crypto.createHash('md5').update(componentPath).digest('hex')\n\n // e.g. if baseDir is /test/fields and componentPath is /components/Field.tsx\n // then path needs to be /test/fields/components/Field.tsx NOT /users/username/project/test/fields/components/Field.tsx\n // so we need to append baseDir to componentPath\n\n if (componentPath.startsWith('.') || componentPath.startsWith('/')) {\n const normalizedBaseDir = baseDir.replace(/\\\\/g, '/')\n\n const finalPath = normalizedBaseDir.startsWith('/../')\n ? `${normalizedBaseDir}${componentPath.slice(1)}`\n : path.posix.join(normalizedBaseDir, componentPath.slice(1))\n\n imports[importIdentifier] = {\n path:\n componentPath.startsWith('.') || componentPath.startsWith('/') ? finalPath : componentPath,\n specifier: exportName,\n }\n } else {\n imports[importIdentifier] = {\n path: componentPath,\n specifier: exportName,\n }\n }\n importMap[componentPath + '#' + exportName] = importIdentifier\n}\n\nexport type AddToImportMap = (payloadComponent: PayloadComponent | PayloadComponent[]) => void\n\nexport async function generateImportMap(\n config: SanitizedConfig,\n options?: { force?: boolean; log: boolean },\n): Promise<void> {\n const shouldLog = options?.log ?? true\n\n if (shouldLog) {\n console.log('Generating import map')\n }\n\n const importMap: InternalImportMap = {}\n const imports: Imports = {}\n\n const rootDir = process.env.ROOT_DIR ?? process.cwd()\n\n // get componentsBaseDir.\n // E.g.:\n // config.admin.importMap.baseDir = /test/fields/\n // rootDir: /\n // componentsBaseDir = /test/fields/\n\n // or\n\n // E.g.:\n // config.admin.importMap.baseDir = /test/fields/\n // rootDir: /test\n // componentsBaseDir = /fields/\n\n // or\n // config.admin.importMap.baseDir = /\n // rootDir: /\n // componentsBaseDir = /\n\n // E.g.:\n // config.admin.importMap.baseDir = /test/fields/\n // rootDir: /test/fields/prod\n // componentsBaseDir = ../\n\n // Check if rootDir is a subdirectory of baseDir\n const baseDir = config.admin.importMap.baseDir\n const isSubdirectory = path.relative(baseDir, rootDir).startsWith('..')\n\n let componentsBaseDir\n\n if (isSubdirectory) {\n // Get the relative path from rootDir to baseDir\n componentsBaseDir = path.relative(rootDir, baseDir)\n } else {\n // If rootDir is not a subdirectory, just return baseDir relative to rootDir\n componentsBaseDir = `/${path.relative(rootDir, baseDir)}`\n }\n\n // Ensure result has a trailing slash\n if (!componentsBaseDir.endsWith('/')) {\n componentsBaseDir += '/'\n }\n\n const addToImportMap: AddToImportMap = (payloadComponent) => {\n if (!payloadComponent) {\n return\n }\n\n if (typeof payloadComponent !== 'object' && typeof payloadComponent !== 'string') {\n console.error(payloadComponent)\n throw new Error('addToImportMap > Payload component must be an object or a string')\n }\n\n if (Array.isArray(payloadComponent)) {\n for (const component of payloadComponent) {\n addPayloadComponentToImportMap({\n baseDir: componentsBaseDir,\n importMap,\n imports,\n payloadComponent: component,\n })\n }\n } else {\n addPayloadComponentToImportMap({\n baseDir: componentsBaseDir,\n importMap,\n imports,\n payloadComponent,\n })\n }\n }\n\n iterateConfig({\n addToImportMap,\n baseDir: config.admin.importMap.baseDir,\n config,\n importMap,\n imports,\n })\n\n await writeImportMap({\n componentMap: importMap,\n config,\n fileName: 'importMap.js',\n force: options?.force,\n importMap: imports,\n log: shouldLog,\n rootDir,\n })\n}\n\nexport async function writeImportMap({\n componentMap,\n config,\n fileName,\n force,\n importMap,\n log,\n rootDir,\n}: {\n componentMap: InternalImportMap\n config: SanitizedConfig\n fileName: string\n force?: boolean\n importMap: Imports\n log?: boolean\n rootDir: string\n}) {\n let importMapFolderPath = ''\n if (fs.existsSync(path.resolve(rootDir, `app/(payload)${config.routes.admin}/`))) {\n importMapFolderPath = path.resolve(rootDir, `app/(payload)${config.routes.admin}/`)\n } else if (fs.existsSync(path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`))) {\n importMapFolderPath = path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`)\n } else {\n throw new Error(\n `Could not find the payload admin directory. Looked in ${path.resolve(rootDir, `app/(payload)${config.routes.admin}/`)} and ${path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`)}`,\n )\n }\n\n const imports: string[] = []\n for (const [identifier, { path, specifier }] of Object.entries(importMap)) {\n imports.push(`import { ${specifier} as ${identifier} } from '${path}'`)\n }\n\n const mapKeys: string[] = []\n for (const [userPath, identifier] of Object.entries(componentMap)) {\n mapKeys.push(` \"${userPath}\": ${identifier}`)\n }\n\n const importMapOutputFile = `${imports.join('\\n')}\n\nexport const importMap = {\n${mapKeys.join(',\\n')}\n}\n`\n\n const importMapFilePath = path.resolve(importMapFolderPath, fileName)\n\n if (!force) {\n // Read current import map and check in the IMPORTS if there are any new imports. If not, don't write the file.\n const currentImportMap = await fs.promises.readFile(importMapFilePath, 'utf-8')\n\n if (currentImportMap?.trim() === importMapOutputFile?.trim()) {\n if (log) {\n console.log('No new imports found, skipping writing import map')\n }\n return\n }\n }\n\n if (log) {\n console.log('Writing import map to', importMapFilePath)\n }\n\n await fs.promises.writeFile(importMapFilePath, importMapOutputFile)\n}\n"],"names":["crypto","fs","process","path","iterateConfig","parsePayloadComponent","addPayloadComponentToImportMap","baseDir","importMap","imports","payloadComponent","exportName","componentPath","importIdentifier","createHash","update","digest","startsWith","normalizedBaseDir","replace","finalPath","slice","posix","join","specifier","generateImportMap","config","options","shouldLog","log","console","rootDir","env","ROOT_DIR","cwd","admin","isSubdirectory","relative","componentsBaseDir","endsWith","addToImportMap","error","Error","Array","isArray","component","writeImportMap","componentMap","fileName","force","importMapFolderPath","existsSync","resolve","routes","identifier","Object","entries","push","mapKeys","userPath","importMapOutputFile","importMapFilePath","currentImportMap","promises","readFile","trim","writeFile"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,QAAQ,KAAI;AACnB,OAAOC,aAAa,eAAc;AAClC,OAAOC,UAAU,OAAM;AAIvB,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,qBAAqB,QAAQ,6BAA4B;AA+BlE,OAAO,SAASC,+BAA+B,EAC7CC,OAAO,EACPC,SAAS,EACTC,OAAO,EACPC,gBAAgB,EAMjB;IACC,IAAI,CAACA,kBAAkB;QACrB;IACF;IACA,MAAM,EAAEC,UAAU,EAAER,MAAMS,aAAa,EAAE,GAAGP,sBAAsBK;IAElE,IAAIF,SAAS,CAACI,gBAAgB,MAAMD,WAAW,EAAE;QAC/C;IACF;IAEA,MAAME,mBACJF,aAAa,MAAMX,OAAOc,UAAU,CAAC,OAAOC,MAAM,CAACH,eAAeI,MAAM,CAAC;IAE3E,6EAA6E;IAC7E,uHAAuH;IACvH,gDAAgD;IAEhD,IAAIJ,cAAcK,UAAU,CAAC,QAAQL,cAAcK,UAAU,CAAC,MAAM;QAClE,MAAMC,oBAAoBX,QAAQY,OAAO,CAAC,OAAO;QAEjD,MAAMC,YAAY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D,IAAIpC,KAAK;gBACPC,QAAQD,GAAG,CAAC;YACd;YACA;QACF;IACF;IAEA,IAAIA,KAAK;QACPC,QAAQD,GAAG,CAAC,yBAAyBgC;IACvC;IAEA,MAAM5D,GAAG8D,QAAQ,CAACG,SAAS,CAACL,mBAAmBD;AACjD"}
1
+ {"version":3,"sources":["../../../src/bin/generateImportMap/index.ts"],"sourcesContent":["import crypto from 'crypto'\nimport fs from 'fs'\nimport process from 'node:process'\nimport path from 'path'\n\nimport type { PayloadComponent, SanitizedConfig } from '../../config/types.js'\n\nimport { iterateConfig } from './iterateConfig.js'\nimport { parsePayloadComponent } from './parsePayloadComponent.js'\n\ntype ImportIdentifier = string\ntype ImportSpecifier = string\ntype ImportPath = string\ntype UserImportPath = string\n\n/**\n * Import Map before being written to the file. Only contains all paths\n */\nexport type InternalImportMap = {\n [path: UserImportPath]: ImportIdentifier\n}\n\n/**\n * Imports of the import map.\n */\nexport type Imports = {\n [identifier: ImportIdentifier]: {\n path: ImportPath\n specifier: ImportSpecifier\n }\n}\n\n/**\n * Import Map after being imported from the actual import map. Contains all the actual imported components\n */\nexport type ImportMap = {\n [path: UserImportPath]: any\n}\n\nexport function addPayloadComponentToImportMap({\n baseDir,\n importMap,\n imports,\n payloadComponent,\n}: {\n baseDir: string\n importMap: InternalImportMap\n imports: Imports\n payloadComponent: PayloadComponent\n}) {\n if (!payloadComponent) {\n return\n }\n const { exportName, path: componentPath } = parsePayloadComponent(payloadComponent)\n\n if (importMap[componentPath + '#' + exportName]) {\n return\n }\n\n const importIdentifier =\n exportName + '_' + crypto.createHash('md5').update(componentPath).digest('hex')\n\n // e.g. if baseDir is /test/fields and componentPath is /components/Field.tsx\n // then path needs to be /test/fields/components/Field.tsx NOT /users/username/project/test/fields/components/Field.tsx\n // so we need to append baseDir to componentPath\n\n if (componentPath.startsWith('.') || componentPath.startsWith('/')) {\n const normalizedBaseDir = baseDir.replace(/\\\\/g, '/')\n\n const finalPath = normalizedBaseDir.startsWith('/../')\n ? `${normalizedBaseDir}${componentPath.slice(1)}`\n : path.posix.join(normalizedBaseDir, componentPath.slice(1))\n\n imports[importIdentifier] = {\n path:\n componentPath.startsWith('.') || componentPath.startsWith('/') ? finalPath : componentPath,\n specifier: exportName,\n }\n } else {\n imports[importIdentifier] = {\n path: componentPath,\n specifier: exportName,\n }\n }\n importMap[componentPath + '#' + exportName] = importIdentifier\n}\n\nexport type AddToImportMap = (payloadComponent: PayloadComponent | PayloadComponent[]) => void\n\nexport async function generateImportMap(\n config: SanitizedConfig,\n options?: { force?: boolean; log: boolean },\n): Promise<void> {\n const shouldLog = options?.log ?? true\n\n if (shouldLog) {\n console.log('Generating import map')\n }\n\n const importMap: InternalImportMap = {}\n const imports: Imports = {}\n\n const rootDir = process.env.ROOT_DIR ?? process.cwd()\n\n // get componentsBaseDir.\n // E.g.:\n // config.admin.importMap.baseDir = /test/fields/\n // rootDir: /\n // componentsBaseDir = /test/fields/\n\n // or\n\n // E.g.:\n // config.admin.importMap.baseDir = /test/fields/\n // rootDir: /test\n // componentsBaseDir = /fields/\n\n // or\n // config.admin.importMap.baseDir = /\n // rootDir: /\n // componentsBaseDir = /\n\n // E.g.:\n // config.admin.importMap.baseDir = /test/fields/\n // rootDir: /test/fields/prod\n // componentsBaseDir = ../\n\n // Check if rootDir is a subdirectory of baseDir\n const baseDir = config.admin.importMap.baseDir\n const isSubdirectory = path.relative(baseDir, rootDir).startsWith('..')\n\n let componentsBaseDir\n\n if (isSubdirectory) {\n // Get the relative path from rootDir to baseDir\n componentsBaseDir = path.relative(rootDir, baseDir)\n } else {\n // If rootDir is not a subdirectory, just return baseDir relative to rootDir\n componentsBaseDir = `/${path.relative(rootDir, baseDir)}`\n }\n\n // Ensure result has a trailing slash\n if (!componentsBaseDir.endsWith('/')) {\n componentsBaseDir += '/'\n }\n\n const addToImportMap: AddToImportMap = (payloadComponent) => {\n if (!payloadComponent) {\n return\n }\n\n if (typeof payloadComponent !== 'object' && typeof payloadComponent !== 'string') {\n console.error(payloadComponent)\n throw new Error('addToImportMap > Payload component must be an object or a string')\n }\n\n if (Array.isArray(payloadComponent)) {\n for (const component of payloadComponent) {\n addPayloadComponentToImportMap({\n baseDir: componentsBaseDir,\n importMap,\n imports,\n payloadComponent: component,\n })\n }\n } else {\n addPayloadComponentToImportMap({\n baseDir: componentsBaseDir,\n importMap,\n imports,\n payloadComponent,\n })\n }\n }\n\n iterateConfig({\n addToImportMap,\n baseDir: config.admin.importMap.baseDir,\n config,\n importMap,\n imports,\n })\n\n await writeImportMap({\n componentMap: importMap,\n config,\n fileName: 'importMap.js',\n force: options?.force,\n importMap: imports,\n log: shouldLog,\n rootDir,\n })\n}\n\nexport async function writeImportMap({\n componentMap,\n config,\n fileName,\n force,\n importMap,\n log,\n rootDir,\n}: {\n componentMap: InternalImportMap\n config: SanitizedConfig\n fileName: string\n force?: boolean\n importMap: Imports\n log?: boolean\n rootDir: string\n}) {\n let importMapFilePath: string | undefined = undefined\n\n if (config?.admin?.importMap?.importMapFile?.length) {\n if (!fs.existsSync(config.admin.importMap.importMapFile)) {\n throw new Error(\n `Could not find the import map file at ${config.admin.importMap.importMapFile}`,\n )\n }\n importMapFilePath = config.admin.importMap.importMapFile\n } else {\n const appLocation = path.resolve(rootDir, `app/(payload)${config.routes.admin}/`)\n const srcAppLocation = path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`)\n\n if (fs.existsSync(appLocation)) {\n importMapFilePath = path.resolve(appLocation, fileName)\n } else if (fs.existsSync(srcAppLocation)) {\n importMapFilePath = path.resolve(srcAppLocation, fileName)\n } else {\n throw new Error(\n `Could not find Payload import map folder. Looked in ${appLocation} and ${srcAppLocation}`,\n )\n }\n }\n\n const imports: string[] = []\n for (const [identifier, { path, specifier }] of Object.entries(importMap)) {\n imports.push(`import { ${specifier} as ${identifier} } from '${path}'`)\n }\n\n const mapKeys: string[] = []\n for (const [userPath, identifier] of Object.entries(componentMap)) {\n mapKeys.push(` \"${userPath}\": ${identifier}`)\n }\n\n const importMapOutputFile = `${imports.join('\\n')}\n\nexport const importMap = {\n${mapKeys.join(',\\n')}\n}\n`\n\n if (!force) {\n // Read current import map and check in the IMPORTS if there are any new imports. If not, don't write the file.\n const currentImportMap = await fs.promises.readFile(importMapFilePath, 'utf-8')\n\n if (currentImportMap?.trim() === importMapOutputFile?.trim()) {\n if (log) {\n console.log('No new imports found, skipping writing import map')\n }\n return\n }\n }\n\n if (log) {\n console.log('Writing import map to', importMapFilePath)\n }\n\n await fs.promises.writeFile(importMapFilePath, importMapOutputFile)\n}\n"],"names":["crypto","fs","process","path","iterateConfig","parsePayloadComponent","addPayloadComponentToImportMap","baseDir","importMap","imports","payloadComponent","exportName","componentPath","importIdentifier","createHash","update","digest","startsWith","normalizedBaseDir","replace","finalPath","slice","posix","join","specifier","generateImportMap","config","options","shouldLog","log","console","rootDir","env","ROOT_DIR","cwd","admin","isSubdirectory","relative","componentsBaseDir","endsWith","addToImportMap","error","Error","Array","isArray","component","writeImportMap","componentMap","fileName","force","importMapFilePath","undefined","importMapFile","length","existsSync","appLocation","resolve","routes","srcAppLocation","identifier","Object","entries","push","mapKeys","userPath","importMapOutputFile","currentImportMap","promises","readFile","trim","writeFile"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,QAAQ,KAAI;AACnB,OAAOC,aAAa,eAAc;AAClC,OAAOC,UAAU,OAAM;AAIvB,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,qBAAqB,QAAQ,6BAA4B;AA+BlE,OAAO,SAASC,+BAA+B,EAC7CC,OAAO,EACPC,SAAS,EACTC,OAAO,EACPC,gBAAgB,EAMjB;IACC,IAAI,CAACA,kBAAkB;QACrB;IACF;IACA,MAAM,EAAEC,UAAU,EAAER,MAAMS,aAAa,EAAE,GAAGP,sBAAsBK;IAElE,IAAIF,SAAS,CAACI,gBAAgB,MAAMD,WAAW,EAAE;QAC/C;IACF;IAEA,MAAME,mBACJF,aAAa,MAAMX,OAAOc,UAAU,CAAC,O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AEwC,QAAQxC,IAAI,CAAC,OAAO;;AAEtB,CAAC;IAEC,IAAI,CAAC0B,OAAO;QACV,+GAA+G;QAC/G,MAAMiB,mBAAmB,MAAMjE,GAAGkE,QAAQ,CAACC,QAAQ,CAAClB,mBAAmB;QAEvE,IAAIgB,kBAAkBG,WAAWJ,qBAAqBI,QAAQ;YAC5D,IAAIxC,KAAK;gBACPC,QAAQD,GAAG,CAAC;YACd;YACA;QACF;IACF;IAEA,IAAIA,KAAK;QACPC,QAAQD,GAAG,CAAC,yBAAyBqB;IACvC;IAEA,MAAMjD,GAAGkE,QAAQ,CAACG,SAAS,CAACpB,mBAAmBe;AACjD"}
@@ -5,7 +5,7 @@ import type { LivePreviewConfig, ServerOnlyLivePreviewProperties, StaticLabel }
5
5
  import type { ClientField } from '../../fields/config/client.js';
6
6
  import type { Payload } from '../../types/index.js';
7
7
  import type { SanitizedCollectionConfig } from './types.js';
8
- export type ServerOnlyCollectionProperties = keyof Pick<SanitizedCollectionConfig, 'access' | 'custom' | 'endpoints' | 'flattenedFields' | 'hooks' | 'joins' | 'polymorphicJoins'>;
8
+ export type ServerOnlyCollectionProperties = keyof Pick<SanitizedCollectionConfig, 'access' | 'custom' | 'endpoints' | 'flattenedFields' | 'hooks' | 'indexes' | 'joins' | 'polymorphicJoins' | 'sanitizedIndexes'>;
9
9
  export type ServerOnlyCollectionAdminProperties = keyof Pick<SanitizedCollectionConfig['admin'], 'baseListFilter' | 'components' | 'hidden'>;
10
10
  export type ServerOnlyUploadProperties = keyof Pick<SanitizedCollectionConfig['upload'], 'adminThumbnail' | 'externalFileHeaderFilter' | 'handlers' | 'modifyResponseHeaders' | 'withMetadata'>;
11
11
  export type ClientCollectionConfig = {
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/collections/config/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,KAAK,EAAE,iBA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xE,CAAA;AAiCD,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,sBA6IH,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"}
@@ -7,7 +7,9 @@ const serverOnlyCollectionProperties = [
7
7
  'custom',
8
8
  'joins',
9
9
  'polymorphicJoins',
10
- 'flattenedFields'
10
+ 'flattenedFields',
11
+ 'indexes',
12
+ 'sanitizedIndexes'
11
13
  ];
12
14
  const serverOnlyUploadProperties = [
13
15
  'adminThumbnail',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["// @ts-strict-ignore\nimport 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' | 'polymorphicJoins'\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 'polymorphicJoins',\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 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":"AAAA,oBAAoB;AAepB,SAASA,kBAAkB,QAAQ,gCAA+B;AAiDlE,MAAMC,iCAA4E;IAChF;IACA;IACA;IACA;IACA;IACA;IACA;CAID;AAED,MAAMC,6BAAoE;IACxE;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,sCAAsF;IAC1F;IACA;IACA;CAGD;AAED,OAAO,MAAMC,+BAA+B,CAAC,EAC3CC,UAAU,EACVC,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMC,mBAAmB,CAAC;IAE1B,IAAK,MAAMC,OAAOL,WAAY;QAC5B,IAAIJ,+BAA+BU,QAAQ,CAACD,MAAa;YACvD;QACF;QACA,OAAQA;YACN,KAAK;gBACH,IAAI,CAACL,WAAWO,KAAK,EAAE;oBACrB;gBACF;gBACAH,iBAAiBG,KAAK,GAAG,CAAC;gBAC1B,IAAK,MAAMC,YAAYR,WAAWO,KAAK,CAAE;oBACvC,IAAIT,oCAAoCQ,QAAQ,CAACE,WAAkB;wBACjE;oBACF;oBAEA,OAAQA;wBACN,KAAK;4BACH,IACE,OAAOR,WAAWO,KAAK,CAACE,WAAW,KAAK,YACxC,OAAOT,WAAWO,KAAK,CAACE,WAAW,KAAK,UACxC;gCACA,IAAIT,WAAWO,KAAK,CAACE,WAAW,EAAE;oCAChCL,iBAAiBG,KAAK,CAACE,WAAW,GAAGT,WAAWO,KAAK,CAACE,WAAW;gCACnE;4BACF,OAAO,IAAI,OAAOT,WAAWO,KAAK,CAACE,WAAW,KAAK,YAAY;gCAC7D,MAAMA,cAAcT,WAAWO,KAAK,CAACE,WAAW,CAA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AACE,QAAQ;gBAClC;gBACA;YACF,KAAK;gBACH,IAAI,CAAC7B,WAAW8B,MAAM,EAAE;oBACtB;gBACF;gBACA1B,iBAAiB0B,MAAM,GAAG,CAAC;gBAC3B,IAAK,MAAMC,aAAa/B,WAAW8B,MAAM,CAAE;oBACzC,IAAIjC,2BAA2BS,QAAQ,CAACyB,YAAmB;wBACzD;oBACF;oBACA,IAAIA,cAAc,cAAc;wBAC9B3B,iBAAiB0B,MAAM,CAACE,UAAU,GAAGhC,WAAW8B,MAAM,CAACE,UAAU,CAACC,GAAG,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;YAEF;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"}
1
+ {"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["// @ts-strict-ignore\nimport 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'\n | 'custom'\n | 'endpoints'\n | 'flattenedFields'\n | 'hooks'\n | 'indexes'\n | 'joins'\n | 'polymorphicJoins'\n | 'sanitizedIndexes'\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 'polymorphicJoins',\n 'flattenedFields',\n 'indexes',\n 'sanitizedIndexes',\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 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":"AAAA,oBAAoB;AAepB,SAASA,kBAAkB,QAAQ,gCAA+B;AAyDlE,MAAMC,iCAA4E;IAChF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CAID;AAED,MAAMC,6BAAoE;IACxE;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,sCAAsF;IAC1F;IACA;IACA;CAGD;AAED,OAAO,MAAMC,+BAA+B,CAAC,EAC3CC,UAAU,EACVC,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMC,mBAAmB,CAAC;IAE1B,IAAK,MAAMC,OAAOL,WAAY;QAC5B,IAAIJ,+BAA+BU,QAAQ,CAACD,MAAa;YACvD;QACF;QACA,OAAQA;YACN,KAAK;gBACH,IAAI,CAACL,WAAWO,KAAK,EAAE;oBACrB;gBACF;gBACAH,iBAAiBG,KAAK,GAAG,CAAC;gBAC1B,IAAK,MAAMC,YAAYR,WAAWO,KAAK,CAAE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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"}
@@ -1,6 +1,18 @@
1
1
  import type { IncomingAuthType, LoginWithUsernameOptions } from '../../auth/types.js';
2
2
  import type { CollectionConfig } from './types.js';
3
+ /**
4
+ * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.
5
+ */
3
6
  export declare const defaults: Partial<CollectionConfig>;
7
+ export declare const addDefaultsToCollectionConfig: (collection: CollectionConfig) => CollectionConfig;
8
+ /**
9
+ * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.
10
+ */
4
11
  export declare const authDefaults: IncomingAuthType;
12
+ export declare const addDefaultsToAuthConfig: (auth: IncomingAuthType) => IncomingAuthType;
13
+ /**
14
+ * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.
15
+ */
5
16
  export declare const loginWithUsernameDefaults: LoginWithUsernameOptions;
17
+ export declare const addDefaultsToLoginWithUsernameConfig: (loginWithUsername: LoginWithUsernameOptions) => LoginWithUsernameOptions;
6
18
  //# sourceMappingURL=defaults.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../src/collections/config/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAIlD,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,gBAAgB,CA6C9C,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,gBAW1B,CAAA;AAED,eAAO,MAAM,yBAAyB,EAAE,wBAIvC,CAAA"}
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../src/collections/config/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAIlD;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,gBAAgB,CA8C9C,CAAA;AAED,eAAO,MAAM,6BAA6B,eAAgB,gBAAgB,KAAG,gBAuD5E,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,gBAW1B,CAAA;AAED,eAAO,MAAM,uBAAuB,SAAU,gBAAgB,KAAG,gBAoBhE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,wBAIvC,CAAA;AAED,eAAO,MAAM,oCAAoC,sBAC5B,wBAAwB,KAC1C,wBAM6B,CAAA"}
@@ -1,5 +1,7 @@
1
1
  import defaultAccess from '../../auth/defaultAccess.js';
2
- export const defaults = {
2
+ /**
3
+ * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.
4
+ */ export const defaults = {
3
5
  access: {
4
6
  create: defaultAccess,
5
7
  delete: defaultAccess,
@@ -47,11 +49,71 @@ export const defaults = {
47
49
  me: [],
48
50
  refresh: []
49
51
  },
52
+ indexes: [],
50
53
  timestamps: true,
51
54
  upload: false,
52
55
  versions: false
53
56
  };
54
- export const authDefaults = {
57
+ export const addDefaultsToCollectionConfig = (collection)=>{
58
+ collection.access = {
59
+ create: defaultAccess,
60
+ delete: defaultAccess,
61
+ read: defaultAccess,
62
+ unlock: defaultAccess,
63
+ update: defaultAccess,
64
+ ...collection.access || {}
65
+ };
66
+ collection.admin = {
67
+ components: {},
68
+ custom: {},
69
+ enableRichTextLink: true,
70
+ enableRichTextRelationship: true,
71
+ useAsTitle: 'id',
72
+ ...collection.admin || {},
73
+ pagination: {
74
+ defaultLimit: 10,
75
+ limits: [
76
+ 5,
77
+ 10,
78
+ 25,
79
+ 50,
80
+ 100
81
+ ],
82
+ ...collection.admin?.pagination || {}
83
+ }
84
+ };
85
+ collection.auth = collection.auth ?? false;
86
+ collection.custom = collection.custom ?? {};
87
+ collection.endpoints = collection.endpoints ?? [];
88
+ collection.fields = collection.fields ?? [];
89
+ collection.hooks = {
90
+ afterChange: [],
91
+ afterDelete: [],
92
+ afterForgotPassword: [],
93
+ afterLogin: [],
94
+ afterLogout: [],
95
+ afterMe: [],
96
+ afterOperation: [],
97
+ afterRead: [],
98
+ afterRefresh: [],
99
+ beforeChange: [],
100
+ beforeDelete: [],
101
+ beforeLogin: [],
102
+ beforeOperation: [],
103
+ beforeRead: [],
104
+ beforeValidate: [],
105
+ me: [],
106
+ refresh: [],
107
+ ...collection.hooks || {}
108
+ };
109
+ collection.timestamps = collection.timestamps ?? true;
110
+ collection.upload = collection.upload ?? false;
111
+ collection.versions = collection.versions ?? false;
112
+ return collection;
113
+ };
114
+ /**
115
+ * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.
116
+ */ export const authDefaults = {
55
117
  cookies: {
56
118
  sameSite: 'Lax',
57
119
  secure: false
@@ -63,10 +125,37 @@ export const authDefaults = {
63
125
  tokenExpiration: 7200,
64
126
  verify: false
65
127
  };
66
- export const loginWithUsernameDefaults = {
128
+ export const addDefaultsToAuthConfig = (auth)=>{
129
+ auth.cookies = {
130
+ sameSite: 'Lax',
131
+ secure: false,
132
+ ...auth.cookies || {}
133
+ };
134
+ auth.forgotPassword = auth.forgotPassword ?? {};
135
+ auth.lockTime = auth.lockTime ?? 600000 // 10 minutes
136
+ ;
137
+ auth.loginWithUsername = auth.loginWithUsername ?? false;
138
+ auth.maxLoginAttempts = auth.maxLoginAttempts ?? 5;
139
+ auth.tokenExpiration = auth.tokenExpiration ?? 7200;
140
+ auth.verify = auth.verify ?? false;
141
+ auth.strategies = auth.strategies ?? [];
142
+ if (!auth.disableLocalStrategy && auth.verify === true) {
143
+ auth.verify = {};
144
+ }
145
+ return auth;
146
+ };
147
+ /**
148
+ * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.
149
+ */ export const loginWithUsernameDefaults = {
67
150
  allowEmailLogin: false,
68
151
  requireEmail: false,
69
152
  requireUsername: true
70
153
  };
154
+ export const addDefaultsToLoginWithUsernameConfig = (loginWithUsername)=>({
155
+ allowEmailLogin: false,
156
+ requireEmail: false,
157
+ requireUsername: true,
158
+ ...loginWithUsername || {}
159
+ });
71
160
 
72
161
  //# sourceMappingURL=defaults.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/config/defaults.ts"],"sourcesContent":["import type { IncomingAuthType, LoginWithUsernameOptions } from '../../auth/types.js'\nimport type { CollectionConfig } from './types.js'\n\nimport defaultAccess from '../../auth/defaultAccess.js'\n\nexport const defaults: Partial<CollectionConfig> = {\n access: {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n },\n admin: {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n },\n useAsTitle: 'id',\n },\n auth: false,\n custom: {},\n endpoints: [],\n fields: [],\n hooks: {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n },\n timestamps: true,\n upload: false,\n versions: false,\n}\n\nexport const authDefaults: IncomingAuthType = {\n cookies: {\n sameSite: 'Lax',\n secure: false,\n },\n forgotPassword: {},\n lockTime: 600000, // 10 minutes\n loginWithUsername: false,\n maxLoginAttempts: 5,\n tokenExpiration: 7200,\n verify: false,\n}\n\nexport const loginWithUsernameDefaults: LoginWithUsernameOptions = {\n allowEmailLogin: false,\n requireEmail: false,\n requireUsername: true,\n}\n"],"names":["defaultAccess","defaults","access","create","delete","read","unlock","update","admin","components","custom","enableRichTextLink","enableRichTextRelationship","pagination","defaultLimit","limits","useAsTitle","auth","endpoints","fields","hooks","afterChange","afterDelete","afterForgotPassword","afterLogin","afterLogout","afterMe","afterOperation","afterRead","afterRefresh","beforeChange","beforeDelete","beforeLogin","beforeOperation","beforeRead","beforeValidate","me","refresh","timestamps","upload","versions","authDefaults","cookies","sameSite","secure","forgotPassword","lockTime","loginWithUsername","maxLoginAttempts","tokenExpiration","verify","loginWithUsernameDefaults","allowEmailLogin","requireEmail","requireUsername"],"mappings":"AAGA,OAAOA,mBAAmB,8BAA6B;AAEvD,OAAO,MAAMC,WAAsC;IACjDC,QAAQ;QACNC,QAAQH;QACRI,QAAQJ;QACRK,MAAML;QACNM,QAAQN;QACRO,QAAQP;IACV;IACAQ,OAAO;QACLC,YAAY,CAAC;QACbC,QAAQ,CAAC;QACTC,oBAAoB;QACpBC,4BAA4B;QAC5BC,YAAY;YACVC,cAAc;YACdC,QAAQ;gBAAC;gBAAG;gBAAI;gBAAI;gBAAI;aAAI;QAC9B;QACAC,YAAY;IACd;IACAC,MAAM;IACNP,QAAQ,CAAC;IACTQ,WAAW,EAAE;IACbC,QAAQ,EAAE;IACVC,OAAO;QACLC,aAAa,EAAE;QACfC,aAAa,EAAE;QACfC,qBAAqB,EAAE;QACvBC,YAAY,EAAE;QACdC,aAAa,EAAE;QACfC,SAAS,EAAE;QACXC,gBAAgB,EAAE;QAClBC,WAAW,EAAE;QACbC,cAAc,EAAE;QAChBC,cAAc,EAAE;QAChBC,cAAc,EAAE;QAChBC,aAAa,EAAE;QACfC,iBAAiB,EAAE;QACnBC,YAAY,EAAE;QACdC,gBAAgB,EAAE;QAClBC,IAAI,EAAE;QACNC,SAAS,EAAE;IACb;IACAC,YAAY;IACZC,QAAQ;IACRC,UAAU;AACZ,EAAC;AAED,OAAO,MAAMC,eAAiC;IAC5CC,SAAS;QACPC,UAAU;QACVC,QAAQ;IACV;IACAC,gBAAgB,CAAC;IACjBC,UAAU;IACVC,mBAAmB;IACnBC,kBAAkB;IAClBC,iBAAiB;IACjBC,QAAQ;AACV,EAAC;AAED,OAAO,MAAMC,4BAAsD;IACjEC,iBAAiB;IACjBC,cAAc;IACdC,iBAAiB;AACnB,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/config/defaults.ts"],"sourcesContent":["import type { IncomingAuthType, LoginWithUsernameOptions } from '../../auth/types.js'\nimport type { CollectionConfig } from './types.js'\n\nimport defaultAccess from '../../auth/defaultAccess.js'\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const defaults: Partial<CollectionConfig> = {\n access: {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n },\n admin: {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n },\n useAsTitle: 'id',\n },\n auth: false,\n custom: {},\n endpoints: [],\n fields: [],\n hooks: {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n },\n indexes: [],\n timestamps: true,\n upload: false,\n versions: false,\n}\n\nexport const addDefaultsToCollectionConfig = (collection: CollectionConfig): CollectionConfig => {\n collection.access = {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n ...(collection.access || {}),\n }\n\n collection.admin = {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n useAsTitle: 'id',\n ...(collection.admin || {}),\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n ...(collection.admin?.pagination || {}),\n },\n }\n\n collection.auth = collection.auth ?? false\n collection.custom = collection.custom ?? {}\n collection.endpoints = collection.endpoints ?? []\n collection.fields = collection.fields ?? []\n\n collection.hooks = {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n ...(collection.hooks || {}),\n }\n\n collection.timestamps = collection.timestamps ?? true\n collection.upload = collection.upload ?? false\n collection.versions = collection.versions ?? false\n\n return collection\n}\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const authDefaults: IncomingAuthType = {\n cookies: {\n sameSite: 'Lax',\n secure: false,\n },\n forgotPassword: {},\n lockTime: 600000, // 10 minutes\n loginWithUsername: false,\n maxLoginAttempts: 5,\n tokenExpiration: 7200,\n verify: false,\n}\n\nexport const addDefaultsToAuthConfig = (auth: IncomingAuthType): IncomingAuthType => {\n auth.cookies = {\n sameSite: 'Lax',\n secure: false,\n ...(auth.cookies || {}),\n }\n\n auth.forgotPassword = auth.forgotPassword ?? {}\n auth.lockTime = auth.lockTime ?? 600000 // 10 minutes\n auth.loginWithUsername = auth.loginWithUsername ?? false\n auth.maxLoginAttempts = auth.maxLoginAttempts ?? 5\n auth.tokenExpiration = auth.tokenExpiration ?? 7200\n auth.verify = auth.verify ?? false\n auth.strategies = auth.strategies ?? []\n\n if (!auth.disableLocalStrategy && auth.verify === true) {\n auth.verify = {}\n }\n\n return auth\n}\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const loginWithUsernameDefaults: LoginWithUsernameOptions = {\n allowEmailLogin: false,\n requireEmail: false,\n requireUsername: true,\n}\n\nexport const addDefaultsToLoginWithUsernameConfig = (\n loginWithUsername: LoginWithUsernameOptions,\n): LoginWithUsernameOptions =>\n ({\n allowEmailLogin: false,\n requireEmail: false,\n requireUsername: true,\n ...(loginWithUsername || {}),\n }) as LoginWithUsernameOptions\n"],"names":["defaultAccess","defaults","access","create","delete","read","unlock","update","admin","components","custom","enableRichTextLink","enableRichTextRelationship","pagination","defaultLimit","limits","useAsTitle","auth","endpoints","fields","hooks","afterChange","afterDelete","afterForgotPassword","afterLogin","afterLogout","afterMe","afterOperation","afterRead","afterRefresh","beforeChange","beforeDelete","beforeLogin","beforeOperation","beforeRead","beforeValidate","me","refresh","indexes","timestamps","upload","versions","addDefaultsToCollectionConfig","collection","authDefaults","cookies","sameSite","secure","forgotPassword","lockTime","loginWithUsername","maxLoginAttempts","tokenExpiration","verify","addDefaultsToAuthConfig","strategies","disableLocalStrategy","loginWithUsernameDefaults","allowEmailLogin","requireEmail","requireUsername","addDefaultsToLoginWithUsernameConfig"],"mappings":"AAGA,OAAOA,mBAAmB,8BAA6B;AAEvD;;CAEC,GACD,OAAO,MAAMC,WAAsC;IACjDC,QAAQ;QACNC,QAAQH;QACRI,QAAQJ;QACRK,MAAML;QACNM,QAAQN;QACRO,QAAQP;IACV;IACAQ,OAAO;QACLC,YAAY,CAAC;QACbC,QAAQ,CAAC;QACTC,oBAAoB;QACpBC,4BAA4B;QAC5BC,YAAY;YACVC,cAAc;YACdC,QAAQ;gBAAC;gBAAG;gBAAI;gBAAI;gBAAI;aAAI;QAC9B;QACAC,YAAY;IACd;IACAC,MAAM;IACNP,QAAQ,CAAC;IACTQ,WAAW,EAAE;IACbC,QAAQ,EAAE;IACVC,OAAO;QACLC,aAAa,EAAE;QACfC,aAAa,EAAE;QACfC,qBAAqB,EAAE;QACvBC,YAAY,EAAE;QACdC,aAAa,EAAE;QACfC,SAA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C,GACD,OAAO,MAAMwC,4BAAsD;IACjEC,iBAAiB;IACjBC,cAAc;IACdC,iBAAiB;AACnB,EAAC;AAED,OAAO,MAAMC,uCAAuC,CAClDX,oBAEC,CAAA;QACCQ,iBAAiB;QACjBC,cAAc;QACdC,iBAAiB;QACjB,GAAIV,qBAAqB,CAAC,CAAC;IAC7B,CAAA,EAA8B"}
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/collections/config/sanitize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EAG1B,MAAM,YAAY,CAAA;AAoBnB,eAAO,MAAM,kBAAkB,WACrB,MAAM,cACF,gBAAgB,iCAKG,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,wBAC1D,MAAM,EAAE,KAC7B,OAAO,CAAC,yBAAyB,CAmNnC,CAAA"}
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/collections/config/sanitize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EACV,gBAAgB,EAEhB,yBAAyB,EAG1B,MAAM,YAAY,CAAA;AAwBnB,eAAO,MAAM,kBAAkB,WACrB,MAAM,cACF,gBAAgB,iCAKG,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,wBAC1D,MAAM,EAAE,KAC7B,OAAO,CAAC,yBAAyB,CAkNnC,CAAA"}
@@ -7,23 +7,27 @@ import { fieldAffectsData } from '../../fields/config/types.js';
7
7
  import mergeBaseFields from '../../fields/mergeBaseFields.js';
8
8
  import { uploadCollectionEndpoints } from '../../uploads/endpoints/index.js';
9
9
  import { getBaseUploadFields } from '../../uploads/getBaseFields.js';
10
- import { deepMergeWithReactComponents } from '../../utilities/deepMerge.js';
11
10
  import { flattenAllFields } from '../../utilities/flattenAllFields.js';
12
11
  import { formatLabels } from '../../utilities/formatLabels.js';
13
12
  import baseVersionFields from '../../versions/baseFields.js';
14
13
  import { versionDefaults } from '../../versions/defaults.js';
15
14
  import { defaultCollectionEndpoints } from '../endpoints/index.js';
16
- import { authDefaults, defaults, loginWithUsernameDefaults } from './defaults.js';
15
+ import { addDefaultsToAuthConfig, addDefaultsToCollectionConfig, addDefaultsToLoginWithUsernameConfig } from './defaults.js';
17
16
  import { sanitizeAuthFields, sanitizeUploadFields } from './reservedFieldNames.js';
17
+ import { sanitizeCompoundIndexes } from './sanitizeCompoundIndexes.js';
18
18
  import { validateUseAsTitle } from './useAsTitle.js';
19
19
  export const sanitizeCollection = async (config, collection, /**
20
20
  * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises
21
21
  * so that you can sanitize them together, after the config has been sanitized.
22
22
  */ richTextSanitizationPromises, _validRelationships)=>{
23
+ if (collection._sanitized) {
24
+ return collection;
25
+ }
26
+ collection._sanitized = true;
23
27
  // /////////////////////////////////
24
28
  // Make copy of collection config
25
29
  // /////////////////////////////////
26
- const sanitized = deepMergeWithReactComponents(defaults, collection);
30
+ const sanitized = addDefaultsToCollectionConfig(collection);
27
31
  // /////////////////////////////////
28
32
  // Sanitize fields
29
33
  // /////////////////////////////////
@@ -149,23 +153,14 @@ export const sanitizeCollection = async (config, collection, /**
149
153
  if (sanitized.auth) {
150
154
  // sanitize fields for reserved names
151
155
  sanitizeAuthFields(sanitized.fields, sanitized);
152
- sanitized.auth = deepMergeWithReactComponents(authDefaults, typeof sanitized.auth === 'object' ? sanitized.auth : {});
153
- if (!sanitized.auth.disableLocalStrategy && sanitized.auth.verify === true) {
154
- sanitized.auth.verify = {};
155
- }
156
+ sanitized.auth = addDefaultsToAuthConfig(typeof sanitized.auth === 'boolean' ? {} : sanitized.auth);
156
157
  // disable duplicate for auth enabled collections by default
157
158
  sanitized.disableDuplicate = sanitized.disableDuplicate ?? true;
158
- if (!sanitized.auth.strategies) {
159
- sanitized.auth.strategies = [];
160
- }
161
159
  if (sanitized.auth.loginWithUsername) {
162
160
  if (sanitized.auth.loginWithUsername === true) {
163
- sanitized.auth.loginWithUsername = loginWithUsernameDefaults;
161
+ sanitized.auth.loginWithUsername = addDefaultsToLoginWithUsernameConfig({});
164
162
  } else {
165
- const loginWithUsernameWithDefaults = {
166
- ...loginWithUsernameDefaults,
167
- ...sanitized.auth.loginWithUsername
168
- };
163
+ const loginWithUsernameWithDefaults = addDefaultsToLoginWithUsernameConfig(sanitized.auth.loginWithUsername);
169
164
  // if allowEmailLogin is false, requireUsername must be true
170
165
  if (loginWithUsernameWithDefaults.allowEmailLogin === false) {
171
166
  loginWithUsernameWithDefaults.requireUsername = true;
@@ -190,6 +185,10 @@ export const sanitizeCollection = async (config, collection, /**
190
185
  sanitizedConfig.flattenedFields = flattenAllFields({
191
186
  fields: sanitizedConfig.fields
192
187
  });
188
+ sanitizedConfig.sanitizedIndexes = sanitizeCompoundIndexes({
189
+ fields: sanitizedConfig.flattenedFields,
190
+ indexes: sanitizedConfig.indexes
191
+ });
193
192
  return sanitizedConfig;
194
193
  };
195
194