payload 3.0.0-beta.100 → 3.0.0-beta.101

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 (36) hide show
  1. package/dist/auth/operations/auth.d.ts.map +1 -1
  2. package/dist/auth/operations/auth.js +0 -6
  3. package/dist/auth/operations/auth.js.map +1 -1
  4. package/dist/auth/operations/login.d.ts.map +1 -1
  5. package/dist/auth/operations/login.js +0 -9
  6. package/dist/auth/operations/login.js.map +1 -1
  7. package/dist/collections/config/sanitize.d.ts.map +1 -1
  8. package/dist/collections/config/sanitize.js +2 -0
  9. package/dist/collections/config/sanitize.js.map +1 -1
  10. package/dist/collections/config/useAsTitle.d.ts +6 -0
  11. package/dist/collections/config/useAsTitle.d.ts.map +1 -0
  12. package/dist/collections/config/useAsTitle.js +33 -0
  13. package/dist/collections/config/useAsTitle.js.map +1 -0
  14. package/dist/collections/config/useAsTitle.spec.js +186 -0
  15. package/dist/collections/config/useAsTitle.spec.js.map +1 -0
  16. package/dist/collections/dataloader.js +2 -2
  17. package/dist/collections/dataloader.js.map +1 -1
  18. package/dist/preferences/operations/delete.d.ts +1 -2
  19. package/dist/preferences/operations/delete.d.ts.map +1 -1
  20. package/dist/preferences/operations/delete.js +2 -10
  21. package/dist/preferences/operations/delete.js.map +1 -1
  22. package/dist/preferences/operations/findOne.d.ts +1 -2
  23. package/dist/preferences/operations/findOne.d.ts.map +1 -1
  24. package/dist/preferences/operations/findOne.js +6 -3
  25. package/dist/preferences/operations/findOne.js.map +1 -1
  26. package/dist/preferences/operations/update.d.ts +1 -9
  27. package/dist/preferences/operations/update.d.ts.map +1 -1
  28. package/dist/preferences/operations/update.js +25 -24
  29. package/dist/preferences/operations/update.js.map +1 -1
  30. package/dist/preferences/requestHandlers/delete.js +1 -1
  31. package/dist/preferences/requestHandlers/delete.js.map +1 -1
  32. package/dist/preferences/requestHandlers/findOne.js +1 -1
  33. package/dist/preferences/requestHandlers/findOne.js.map +1 -1
  34. package/dist/preferences/requestHandlers/update.js +1 -1
  35. package/dist/preferences/requestHandlers/update.js.map +1 -1
  36. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAQ9C,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IAC3B,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,WAAW,CAAA;IACxB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,IAAI,EAAE,IAAI,GAAG,SAAS,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,IAAI,SAAgB,QAAQ,CAAC,QAAQ,CAAC,KAAG,OAAO,CAAC,UAAU,CAiCvE,CAAA"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAM9C,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IAC3B,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,WAAW,CAAA;IACxB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,IAAI,EAAE,IAAI,GAAG,SAAS,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,IAAI,SAAgB,QAAQ,CAAC,QAAQ,CAAC,KAAG,OAAO,CAAC,UAAU,CA2BvE,CAAA"}
@@ -1,5 +1,3 @@
1
- import { commitTransaction } from '../../utilities/commitTransaction.js';
2
- import { initTransaction } from '../../utilities/initTransaction.js';
3
1
  import { killTransaction } from '../../utilities/killTransaction.js';
4
2
  import { executeAuthStrategies } from '../executeAuthStrategies.js';
5
3
  import { getAccessResults } from '../getAccessResults.js';
@@ -8,7 +6,6 @@ export const auth = async (args)=>{
8
6
  const req = args.req;
9
7
  const { payload } = req;
10
8
  try {
11
- const shouldCommit = await initTransaction(req);
12
9
  const { responseHeaders, user } = await executeAuthStrategies({
13
10
  headers,
14
11
  payload
@@ -18,9 +15,6 @@ export const auth = async (args)=>{
18
15
  const permissions = await getAccessResults({
19
16
  req
20
17
  });
21
- if (shouldCommit) {
22
- await commitTransaction(req);
23
- }
24
18
  return {
25
19
  permissions,
26
20
  responseHeaders,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/operations/auth.ts"],"sourcesContent":["import type { TypedUser } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { Permissions } from '../types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { executeAuthStrategies } from '../executeAuthStrategies.js'\nimport { getAccessResults } from '../getAccessResults.js'\n\nexport type AuthArgs = {\n headers: Request['headers']\n req?: Omit<PayloadRequest, 'user'>\n}\n\nexport type AuthResult = {\n permissions: Permissions\n responseHeaders?: Headers\n user: null | TypedUser\n}\n\nexport const auth = async (args: Required<AuthArgs>): Promise<AuthResult> => {\n const { headers } = args\n const req = args.req as PayloadRequest\n const { payload } = req\n\n try {\n const shouldCommit = await initTransaction(req)\n\n const { responseHeaders, user } = await executeAuthStrategies({\n headers,\n payload,\n })\n\n req.user = user\n req.responseHeaders = responseHeaders\n\n const permissions = await getAccessResults({\n req,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return {\n permissions,\n responseHeaders,\n user,\n }\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","executeAuthStrategies","getAccessResults","auth","args","headers","req","payload","shouldCommit","responseHeaders","user","permissions","error"],"mappings":"AAIA,SAASA,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,qBAAqB,QAAQ,8BAA6B;AACnE,SAASC,gBAAgB,QAAQ,yBAAwB;AAazD,OAAO,MAAMC,OAAO,OAAOC;IACzB,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,MAAME,MAAMF,KAAKE,GAAG;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,IAAI;QACF,MAAME,eAAe,MAAMT,gBAAgBO;QAE3C,MAAM,EAAEG,eAAe,EAAEC,IAAI,EAAE,GAAG,MAAMT,sBAAsB;YAC5DI;YACAE;QACF;QAEAD,IAAII,IAAI,GAAGA;QACXJ,IAAIG,eAAe,GAAGA;QAEtB,MAAME,cAAc,MAAMT,iBAAiB;YACzCI;QACF;QAEA,IAAIE,cAAc;YAChB,MAAMV,kBAAkBQ;QAC1B;QAEA,OAAO;YACLK;YACAF;YACAC;QACF;IACF,EAAE,OAAOE,OAAgB;QACvB,MAAMZ,gBAAgBM;QACtB,MAAMM;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/operations/auth.ts"],"sourcesContent":["import type { TypedUser } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { Permissions } from '../types.js'\n\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { executeAuthStrategies } from '../executeAuthStrategies.js'\nimport { getAccessResults } from '../getAccessResults.js'\n\nexport type AuthArgs = {\n headers: Request['headers']\n req?: Omit<PayloadRequest, 'user'>\n}\n\nexport type AuthResult = {\n permissions: Permissions\n responseHeaders?: Headers\n user: null | TypedUser\n}\n\nexport const auth = async (args: Required<AuthArgs>): Promise<AuthResult> => {\n const { headers } = args\n const req = args.req as PayloadRequest\n const { payload } = req\n\n try {\n const { responseHeaders, user } = await executeAuthStrategies({\n headers,\n payload,\n })\n\n req.user = user\n req.responseHeaders = responseHeaders\n\n const permissions = await getAccessResults({\n req,\n })\n\n return {\n permissions,\n responseHeaders,\n user,\n }\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["killTransaction","executeAuthStrategies","getAccessResults","auth","args","headers","req","payload","responseHeaders","user","permissions","error"],"mappings":"AAIA,SAASA,eAAe,QAAQ,qCAAoC;AACpE,SAASC,qBAAqB,QAAQ,8BAA6B;AACnE,SAASC,gBAAgB,QAAQ,yBAAwB;AAazD,OAAO,MAAMC,OAAO,OAAOC;IACzB,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,MAAME,MAAMF,KAAKE,GAAG;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,IAAI;QACF,MAAM,EAAEE,eAAe,EAAEC,IAAI,EAAE,GAAG,MAAMR,sBAAsB;YAC5DI;YACAE;QACF;QAEAD,IAAIG,IAAI,GAAGA;QACXH,IAAIE,eAAe,GAAGA;QAEtB,MAAME,cAAc,MAAMR,iBAAiB;YACzCI;QACF;QAEA,OAAO;YACLI;YACAF;YACAC;QACF;IACF,EAAE,OAAOE,OAAgB;QACvB,MAAMX,gBAAgBM;QACtB,MAAMK;IACR;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/login.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACV,sBAAsB,EACvB,MAAM,mCAAmC,CAAA;AAC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d,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,gCAAgC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAA;IACtD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,cAAc,GAAU,KAAK,SAAS,cAAc,gBACjD,SAAS,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC;IAAE,IAAI,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAA;CAAE,GAAG,MAAM,CAsS1D,CAAA"}
@@ -2,8 +2,6 @@ import jwt from 'jsonwebtoken';
2
2
  import { buildAfterOperation } from '../../collections/operations/utils.js';
3
3
  import { AuthenticationError, LockedAuth, ValidationError } from '../../errors/index.js';
4
4
  import { afterRead } from '../../fields/hooks/afterRead/index.js';
5
- import { commitTransaction } from '../../utilities/commitTransaction.js';
6
- import { initTransaction } from '../../utilities/initTransaction.js';
7
5
  import { killTransaction } from '../../utilities/killTransaction.js';
8
6
  import sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js';
9
7
  import { getFieldsToSign } from '../getFieldsToSign.js';
@@ -14,7 +12,6 @@ import { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js';
14
12
  export const loginOperation = async (incomingArgs)=>{
15
13
  let args = incomingArgs;
16
14
  try {
17
- const shouldCommit = await initTransaction(args.req);
18
15
  // /////////////////////////////////////
19
16
  // beforeOperation - Collection
20
17
  // /////////////////////////////////////
@@ -157,9 +154,6 @@ export const loginOperation = async (incomingArgs)=>{
157
154
  req
158
155
  });
159
156
  }
160
- if (shouldCommit) {
161
- await commitTransaction(req);
162
- }
163
157
  throw new AuthenticationError(req.t);
164
158
  }
165
159
  if (maxLoginAttemptsEnabled) {
@@ -261,9 +255,6 @@ export const loginOperation = async (incomingArgs)=>{
261
255
  // /////////////////////////////////////
262
256
  // Return results
263
257
  // /////////////////////////////////////
264
- if (shouldCommit) {
265
- await commitTransaction(req);
266
- }
267
258
  return result;
268
259
  } catch (error) {
269
260
  await killTransaction(args.req);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/operations/login.ts"],"sourcesContent":["import jwt from 'jsonwebtoken'\n\nimport type {\n AuthOperationsFromCollectionSlug,\n Collection,\n DataFromCollectionSlug,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\nimport type { User } from '../types.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { AuthenticationError, LockedAuth, ValidationError } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport isLocked from '../isLocked.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { incrementLoginAttempts } from '../strategies/local/incrementLoginAttempts.js'\nimport { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js'\n\nexport type Result = {\n exp?: number\n token?: string\n user?: User\n}\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['login']\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n showHiddenFields?: boolean\n}\n\nexport const loginOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments<TSlug>,\n): Promise<{ user: DataFromCollectionSlug<TSlug> } & Result> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'login',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { secret },\n },\n showHiddenFields,\n } = args\n\n // /////////////////////////////////////\n // Login\n // /////////////////////////////////////\n\n let user\n const { email: unsanitizedEmail, password } = data\n const loginWithUsername = collectionConfig.auth.loginWithUsername\n\n const sanitizedEmail =\n typeof unsanitizedEmail === 'string' ? unsanitizedEmail.toLowerCase().trim() : null\n const sanitizedUsername =\n 'username' in data && typeof data?.username === 'string'\n ? data.username.toLowerCase().trim()\n : null\n\n const canLoginWithUsername = Boolean(loginWithUsername)\n const canLoginWithEmail = !loginWithUsername || loginWithUsername.allowEmailLogin\n\n // cannot login with email, did not provide username\n if (!canLoginWithEmail && !sanitizedUsername) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ field: 'username', message: req.i18n.t('validation:required') }],\n })\n }\n\n // cannot login with username, did not provide email\n if (!canLoginWithUsername && !sanitizedEmail) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ field: 'email', message: req.i18n.t('validation:required') }],\n })\n }\n\n // can login with either email or username, did not provide either\n if (!sanitizedUsername && !sanitizedEmail) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [\n { field: 'email', message: req.i18n.t('validation:required') },\n { field: 'username', message: req.i18n.t('validation:required') },\n ],\n })\n }\n\n // did not provide password for login\n if (typeof password !== 'string' || password.trim() === '') {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ field: 'password', message: req.i18n.t('validation:required') }],\n })\n }\n\n let whereConstraint: Where = {}\n const emailConstraint: Where = {\n email: {\n equals: sanitizedEmail,\n },\n }\n const usernameConstraint: Where = {\n username: {\n equals: sanitizedUsername,\n },\n }\n\n if (canLoginWithEmail && canLoginWithUsername && (sanitizedUsername || sanitizedEmail)) {\n if (sanitizedUsername) {\n whereConstraint = {\n or: [\n usernameConstraint,\n {\n email: {\n equals: sanitizedUsername,\n },\n },\n ],\n }\n } else {\n whereConstraint = {\n or: [\n emailConstraint,\n {\n username: {\n equals: sanitizedEmail,\n },\n },\n ],\n }\n }\n } else if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = emailConstraint\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = usernameConstraint\n }\n\n user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n if (!user || (args.collection.config.auth.verify && user._verified === false)) {\n throw new AuthenticationError(req.t, Boolean(canLoginWithUsername && sanitizedUsername))\n }\n\n if (user && isLocked(new Date(user.lockUntil).getTime())) {\n throw new LockedAuth(req.t)\n }\n\n const authResult = await authenticateLocalStrategy({ doc: user, password })\n\n user = sanitizeInternalFields(user)\n\n const maxLoginAttemptsEnabled = args.collection.config.auth.maxLoginAttempts > 0\n\n if (!authResult) {\n if (maxLoginAttemptsEnabled) {\n await incrementLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n throw new AuthenticationError(req.t)\n }\n\n if (maxLoginAttemptsEnabled) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n const fieldsToSign = getFieldsToSign({\n collectionConfig,\n email: sanitizedEmail,\n user,\n })\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeLogin.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user,\n })) || user\n }, Promise.resolve())\n\n const token = jwt.sign(fieldsToSign, secret, {\n expiresIn: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = user\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterLogin.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n token,\n user,\n })) || user\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n user = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: user,\n draft: undefined,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n doc: user,\n req,\n })) || user\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n doc: user,\n req,\n })) || user\n }, Promise.resolve())\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n exp: (jwt.decode(token) as jwt.JwtPayload).exp,\n token,\n user,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'login',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["jwt","buildAfterOperation","AuthenticationError","LockedAuth","ValidationError","afterRead","commitTransaction","initTransaction","killTransaction","sanitizeInternalFields","getFieldsToSign","isLocked","authenticateLocalStrategy","incrementLoginAttempts","resetLoginAttempts","loginOperation","incomingArgs","args","shouldCommit","req","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","operation","Promise","resolve","collectionConfig","data","depth","overrideAccess","fallbackLocale","locale","payload","secret","showHiddenFields","user","email","unsanitizedEmail","password","loginWithUsername","auth","sanitizedEmail","toLowerCase","trim","sanitizedUsername","username","canLoginWithUsername","Boolean","canLoginWithEmail","allowEmailLogin","slug","errors","field","message","i18n","t","whereConstraint","emailConstraint","equals","usernameConstraint","or","db","findOne","where","verify","_verified","Date","lockUntil","getTime","authResult","doc","maxLoginAttemptsEnabled","maxLoginAttempts","fieldsToSign","beforeLogin","token","sign","expiresIn","tokenExpiration","afterLogin","draft","undefined","global","result","exp","decode","error"],"mappings":"AAAA,OAAOA,SAAS,eAAc;AAW9B,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,mBAAmB,EAAEC,UAAU,EAAEC,eAAe,QAAQ,wBAAuB;AACxF,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,OAAOC,4BAA4B,4CAA2C;AAC9E,SAASC,eAAe,QAAQ,wBAAuB;AACvD,OAAOC,cAAc,iBAAgB;AACrC,SAASC,yBAAyB,QAAQ,sCAAqC;AAC/E,SAASC,sBAAsB,QAAQ,gDAA+C;AACtF,SAASC,kBAAkB,QAAQ,4CAA2C;AAiB9E,OAAO,MAAMC,iBAAiB,OAC5BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,MAAMX,gBAAgBU,KAAKE,GAAG;QAEnD,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExC,MAAMF,KAAKG,UAAU,CAACC,MAAM,CAACC,KAAK,CAACC,eAAe,CAACC,MAAM,CAAC,OAAOC,WAAWC;YAC1E,MAAMD;YAENR,OACE,AAAC,MAAMS,KAAK;gBACVT;gBACAG,YAAYH,KAAKG,UAAU,EAA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AASR,IAAIQ,OAAO;gBACpBgD,KAAKnC;gBACLrB;YACF,MAAOqB;QACX,GAAGX,QAAQC,OAAO;QAElB,IAAI0D,SAA2D;YAC7DC,KAAK,AAACzF,IAAI0F,MAAM,CAACV,OAA0BS,GAAG;YAC9CT;YACAxC;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCgD,SAAS,MAAMvF,oBAAoB;YACjCgB;YACAG,YAAYH,KAAKG,UAAU,EAAEC;YAC7BO,WAAW;YACX4D;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAItE,cAAc;YAChB,MAAMZ,kBAAkBa;QAC1B;QAEA,OAAOqE;IACT,EAAE,OAAOG,OAAgB;QACvB,MAAMnF,gBAAgBS,KAAKE,GAAG;QAC9B,MAAMwE;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/operations/login.ts"],"sourcesContent":["import jwt from 'jsonwebtoken'\n\nimport type {\n AuthOperationsFromCollectionSlug,\n Collection,\n DataFromCollectionSlug,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\nimport type { User } from '../types.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { AuthenticationError, LockedAuth, ValidationError } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport isLocked from '../isLocked.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { incrementLoginAttempts } from '../strategies/local/incrementLoginAttempts.js'\nimport { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js'\n\nexport type Result = {\n exp?: number\n token?: string\n user?: User\n}\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['login']\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n showHiddenFields?: boolean\n}\n\nexport const loginOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments<TSlug>,\n): Promise<{ user: DataFromCollectionSlug<TSlug> } & Result> => {\n let args = incomingArgs\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'login',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { secret },\n },\n showHiddenFields,\n } = args\n\n // /////////////////////////////////////\n // Login\n // /////////////////////////////////////\n\n let user\n const { email: unsanitizedEmail, password } = data\n const loginWithUsername = collectionConfig.auth.loginWithUsername\n\n const sanitizedEmail =\n typeof unsanitizedEmail === 'string' ? unsanitizedEmail.toLowerCase().trim() : null\n const sanitizedUsername =\n 'username' in data && typeof data?.username === 'string'\n ? data.username.toLowerCase().trim()\n : null\n\n const canLoginWithUsername = Boolean(loginWithUsername)\n const canLoginWithEmail = !loginWithUsername || loginWithUsername.allowEmailLogin\n\n // cannot login with email, did not provide username\n if (!canLoginWithEmail && !sanitizedUsername) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ field: 'username', message: req.i18n.t('validation:required') }],\n })\n }\n\n // cannot login with username, did not provide email\n if (!canLoginWithUsername && !sanitizedEmail) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ field: 'email', message: req.i18n.t('validation:required') }],\n })\n }\n\n // can login with either email or username, did not provide either\n if (!sanitizedUsername && !sanitizedEmail) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [\n { field: 'email', message: req.i18n.t('validation:required') },\n { field: 'username', message: req.i18n.t('validation:required') },\n ],\n })\n }\n\n // did not provide password for login\n if (typeof password !== 'string' || password.trim() === '') {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ field: 'password', message: req.i18n.t('validation:required') }],\n })\n }\n\n let whereConstraint: Where = {}\n const emailConstraint: Where = {\n email: {\n equals: sanitizedEmail,\n },\n }\n const usernameConstraint: Where = {\n username: {\n equals: sanitizedUsername,\n },\n }\n\n if (canLoginWithEmail && canLoginWithUsername && (sanitizedUsername || sanitizedEmail)) {\n if (sanitizedUsername) {\n whereConstraint = {\n or: [\n usernameConstraint,\n {\n email: {\n equals: sanitizedUsername,\n },\n },\n ],\n }\n } else {\n whereConstraint = {\n or: [\n emailConstraint,\n {\n username: {\n equals: sanitizedEmail,\n },\n },\n ],\n }\n }\n } else if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = emailConstraint\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = usernameConstraint\n }\n\n user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n if (!user || (args.collection.config.auth.verify && user._verified === false)) {\n throw new AuthenticationError(req.t, Boolean(canLoginWithUsername && sanitizedUsername))\n }\n\n if (user && isLocked(new Date(user.lockUntil).getTime())) {\n throw new LockedAuth(req.t)\n }\n\n const authResult = await authenticateLocalStrategy({ doc: user, password })\n\n user = sanitizeInternalFields(user)\n\n const maxLoginAttemptsEnabled = args.collection.config.auth.maxLoginAttempts > 0\n\n if (!authResult) {\n if (maxLoginAttemptsEnabled) {\n await incrementLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n throw new AuthenticationError(req.t)\n }\n\n if (maxLoginAttemptsEnabled) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n const fieldsToSign = getFieldsToSign({\n collectionConfig,\n email: sanitizedEmail,\n user,\n })\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeLogin.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user,\n })) || user\n }, Promise.resolve())\n\n const token = jwt.sign(fieldsToSign, secret, {\n expiresIn: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = user\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterLogin.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n token,\n user,\n })) || user\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n user = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: user,\n draft: undefined,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n doc: user,\n req,\n })) || user\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n doc: user,\n req,\n })) || user\n }, Promise.resolve())\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n exp: (jwt.decode(token) as jwt.JwtPayload).exp,\n token,\n user,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'login',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["jwt","buildAfterOperation","AuthenticationError","LockedAuth","ValidationError","afterRead","killTransaction","sanitizeInternalFields","getFieldsToSign","isLocked","authenticateLocalStrategy","incrementLoginAttempts","resetLoginAttempts","loginOperation","incomingArgs","args","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","req","operation","Promise","resolve","collectionConfig","data","depth","overrideAccess","fallbackLocale","locale","payload","secret","showHiddenFields","user","email","unsanitizedEmail","password","loginWithUsername","auth","sanitizedEmail","toLowerCase","trim","sanitizedUsername","username","canLoginWithUsername","Boolean","canLoginWithEmail","allowEmailLogin","slug","errors","field","message","i18n","t","whereConstraint","emailConstraint","equals","usernameConstraint","or","db","findOne","where","verify","_verified","Date","lockUntil","getTime","authResult","doc","maxLoginAttemptsEnabled","maxLoginAttempts","fieldsToSign","beforeLogin","token","sign","expiresIn","tokenExpiration","afterLogin","draft","undefined","global","result","exp","decode","error"],"mappings":"AAAA,OAAOA,SAAS,eAAc;AAW9B,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,mBAAmB,EAAEC,UAAU,EAAEC,eAAe,QAAQ,wBAAuB;AACxF,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,OAAOC,4BAA4B,4CAA2C;AAC9E,SAASC,eAAe,QAAQ,wBAAuB;AACvD,OAAOC,cAAc,iBAAgB;AACrC,SAASC,yBAAyB,QAAQ,sCAAqC;AAC/E,SAASC,sBAAsB,QAAQ,gDAA+C;AACtF,SAASC,kBAAkB,QAAQ,4CAA2C;AAiB9E,OAAO,MAAMC,iBAAiB,OAC5BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExC,MAAMC,KAAKC,UAAU,CAACC,MAAM,CAACC,KAAK,CAACC,eAAe,CAACC,MAAM,CAAC,OAAOC,WAAWC;YAC1E,MAAMD;YAENN,OACE,AAAC,MAAMO,KAAK;gBACVP;gBACAC,YAAYD,KAAKC,UAAU,EAAEC;gBAC7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B,IAAI0D,SAA2D;YAC7DC,KAAK,AAACtF,IAAIuF,MAAM,CAACV,OAA0BS,GAAG;YAC9CT;YACAxC;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCgD,SAAS,MAAMpF,oBAAoB;YACjCc;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BQ,WAAW;YACX4D;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOG,OAAgB;QACvB,MAAMlF,gBAAgBS,KAAKS,GAAG;QAC9B,MAAMgE;IACR;AACF,EAAC"}
@@ -1 +1 @@
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,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAe7E,eAAO,MAAM,kBAAkB,WACrB,MAAM,cACF,gBAAgB,iCAKG,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,KAC/E,OAAO,CAAC,yBAAyB,CAwKnC,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,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAgB7E,eAAO,MAAM,kBAAkB,WACrB,MAAM,cACF,gBAAgB,iCAKG,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,KAC/E,OAAO,CAAC,yBAAyB,CA0KnC,CAAA"}
@@ -10,6 +10,7 @@ import baseVersionFields from '../../versions/baseFields.js';
10
10
  import { versionDefaults } from '../../versions/defaults.js';
11
11
  import { authDefaults, defaults, loginWithUsernameDefaults } from './defaults.js';
12
12
  import { sanitizeAuthFields, sanitizeUploadFields } from './reservedFieldNames.js';
13
+ import { validateUseAsTitle } from './useAsTitle.js';
13
14
  export const sanitizeCollection = async (config, collection, /**
14
15
  * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises
15
16
  * so that you can sanitize them together, after the config has been sanitized.
@@ -30,6 +31,7 @@ export const sanitizeCollection = async (config, collection, /**
30
31
  richTextSanitizationPromises,
31
32
  validRelationships
32
33
  });
34
+ validateUseAsTitle(sanitized);
33
35
  if (sanitized.timestamps !== false) {
34
36
  // add default timestamps fields only as needed
35
37
  let hasUpdatedAt = null;
@@ -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 } 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 { 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'\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.map((c) => c.slug) || []\n sanitized.fields = await sanitizeFields({\n collectionConfig: sanitized,\n config,\n fields: sanitized.fields,\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 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 }\n }\n\n if (sanitized.timestamps === false) {\n throw new TimestampsRequired(collection)\n }\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 // disable duplicate for uploads by default\n sanitized.disableDuplicate = sanitized.disableDuplicate || true\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 return sanitized as SanitizedCollectionConfig\n}\n"],"names":["getBaseAuthFields","TimestampsRequired","sanitizeFields","fieldAffectsData","mergeBaseFields","getBaseUploadFields","deepMergeWithReactComponents","formatLabels","baseVersionFields","versionDefaults","authDefaults","defaults","loginWithUsernameDefaults","sanitizeAuthFields","sanitizeUploadFields","sanitizeCollection","config","collection","richTextSanitizationPromises","sanitized","validRelationships","collections","map","c","slug","fields","collectionConfig","parentIsLocalized","timestamps","hasUpdatedAt","hasCreatedAt","some","field","name","push","type","admin","disableBulkEdit","hidden","label","t","index","labels","versions","drafts","autosave","validate","interval","autosaveInterval","undefined","upload","disableDuplicate","bulkUpload","staticDir","useAsTitle","uploadFields","auth","disableLocalStrategy","verify","strategies","loginWithUsername","loginWithUsernameWithDefaults","allowEmailLogin","requireUsername","pagination","limits","length"],"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,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;AAElF,OAAO,MAAMC,qBAAqB,OAChCC,QACAC,YACA;;;GAGC,GACDC;IAEA,oCAAoC;IACpC,iCAAiC;IACjC,oCAAoC;IAEpC,MAAMC,YAA8Bb,6BAA6BK,UAAUM;IAE3E,oCA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D/C,UAAUiB,KAAK,CAAC4B,UAAU,CAACC,MAAM,GAAGhD,WAAWmB,KAAK,CAAC4B,UAAU,CAACC,MAAM;IACxE;IAEA,OAAO9C;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 } 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 { 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.map((c) => c.slug) || []\n sanitized.fields = await sanitizeFields({\n collectionConfig: sanitized,\n config,\n fields: sanitized.fields,\n parentIsLocalized: false,\n richTextSanitizationPromises,\n validRelationships,\n })\n\n validateUseAsTitle(sanitized)\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 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 }\n }\n\n if (sanitized.timestamps === false) {\n throw new TimestampsRequired(collection)\n }\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 // disable duplicate for uploads by default\n sanitized.disableDuplicate = sanitized.disableDuplicate || true\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 return sanitized as SanitizedCollectionConfig\n}\n"],"names":["getBaseAuthFields","TimestampsRequired","sanitizeFields","fieldAffectsData","mergeBaseFields","getBaseUploadFields","deepMergeWithReactComponents","formatLabels","baseVersionFields","versionDefaults","authDefaults","defaults","loginWithUsernameDefaults","sanitizeAuthFields","sanitizeUploadFields","validateUseAsTitle","sanitizeCollection","config","collection","richTextSanitizationPromises","sanitized","validRelationships","collections","map","c","slug","fields","collectionConfig","parentIsLocalized","timestamps","hasUpdatedAt","hasCreatedAt","some","field","name","push","type","admin","disableBulkEdit","hidden","label","t","index","labels","versions","drafts","autosave","validate","interval","autosaveInterval","undefined","upload","disableDuplicate","bulkUpload","staticDir","useAsTitle","uploadFields","auth","disableLocalStrategy","verify","strategies","loginWithUsername","loginWithUsernameWithDefaults","allowEmailLogin","requireUsername","pagination","limits","length"],"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,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,GACDC;IAEA,oCAAoC;IACpC,iCAAiC;IACjC,oCAAoC;IAEpC,MAAMC,YAA8Bd,6BAA6BK,UAAUO;IAE3E,oCAAoC;IACpC,kBAAkB;IAClB,oCAAoC;IAEpC,MAAMG,qBAAqBJ,OAAOK,WAAW,CAACC,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAK,EAAE;IACtEL,UAAUM,MAAM,GAAG,MAAMxB,eAAe;QACtCyB,kBAAkBP;QAClBH;QACAS,QAAQN,UAAUM,MAAM;QACxBE,mBAAmB;QACnBT;QACAE;IACF;IAEAN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I,KAAK,WAAWrC,UAAUqC,IAAI,GAAG,CAAC;QAGzD,IAAI,CAACrC,UAAUqC,IAAI,CAACC,oBAAoB,IAAItC,UAAUqC,IAAI,CAACE,MAAM,KAAK,MAAM;YAC1EvC,UAAUqC,IAAI,CAACE,MAAM,GAAG,CAAC;QAC3B;QAEA,4DAA4D;QAC5DvC,UAAUgC,gBAAgB,GAAGhC,UAAUgC,gBAAgB,IAAI;QAE3D,IAAI,CAAChC,UAAUqC,IAAI,CAACG,UAAU,EAAE;YAC9BxC,UAAUqC,IAAI,CAACG,UAAU,GAAG,EAAE;QAChC;QAEA,IAAIxC,UAAUqC,IAAI,CAACI,iBAAiB,EAAE;YACpC,IAAIzC,UAAUqC,IAAI,CAACI,iBAAiB,KAAK,MAAM;gBAC7CzC,UAAUqC,IAAI,CAACI,iBAAiB,GAAGjD;YACrC,OAAO;gBACL,MAAMkD,gCAAgC;oBACpC,GAAGlD,yBAAyB;oBAC5B,GAAGQ,UAAUqC,IAAI,CAACI,iBAAiB;gBACrC;gBAEA,4DAA4D;gBAC5D,IAAIC,8BAA8BC,eAAe,KAAK,OAAO;oBAC3DD,8BAA8BE,eAAe,GAAG;gBAClD;gBACA5C,UAAUqC,IAAI,CAACI,iBAAiB,GAAGC;YACrC;QACF,OAAO;YACL1C,UAAUqC,IAAI,CAACI,iBAAiB,GAAG;QACrC;QAEAzC,UAAUM,MAAM,GAAGtB,gBAAgBgB,UAAUM,MAAM,EAAE1B,kBAAkBoB,UAAUqC,IAAI;IACvF;IAEA,IAAIvC,YAAYmB,OAAO4B,YAAYC,QAAQC,QAAQ;QACjD/C,UAAUiB,KAAK,CAAC4B,UAAU,CAACC,MAAM,GAAGhD,WAAWmB,KAAK,CAAC4B,UAAU,CAACC,MAAM;IACxE;IAEA,OAAO9C;AACT,EAAC"}
@@ -0,0 +1,6 @@
1
+ import type { CollectionConfig } from '../../index.js';
2
+ /**
3
+ * Validate useAsTitle for collections.
4
+ */
5
+ export declare const validateUseAsTitle: (config: CollectionConfig) => void;
6
+ //# sourceMappingURL=useAsTitle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAsTitle.d.ts","sourceRoot":"","sources":["../../../src/collections/config/useAsTitle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAMtD;;GAEG;AACH,eAAO,MAAM,kBAAkB,WAAY,gBAAgB,SAiC1D,CAAA"}
@@ -0,0 +1,33 @@
1
+ import { InvalidConfiguration } from '../../errors/InvalidConfiguration.js';
2
+ import { fieldAffectsData } from '../../fields/config/types.js';
3
+ import flattenFields from '../../utilities/flattenTopLevelFields.js';
4
+ /**
5
+ * Validate useAsTitle for collections.
6
+ */ export const validateUseAsTitle = (config)=>{
7
+ if (config.admin.useAsTitle.includes('.')) {
8
+ throw new InvalidConfiguration(`"useAsTitle" cannot be a nested field. Please specify a top-level field in the collection "${config.slug}"`);
9
+ }
10
+ if (config?.admin && config.admin?.useAsTitle && config.admin.useAsTitle !== 'id') {
11
+ const fields = flattenFields(config.fields);
12
+ const useAsTitleField = fields.find((field)=>{
13
+ if (fieldAffectsData(field) && config.admin) {
14
+ return field.name === config.admin.useAsTitle;
15
+ }
16
+ return false;
17
+ });
18
+ // If auth is enabled then we don't need to
19
+ if (config.auth) {
20
+ if (config.admin.useAsTitle !== 'email') {
21
+ if (!useAsTitleField) {
22
+ throw new InvalidConfiguration(`The field "${config.admin.useAsTitle}" specified in "admin.useAsTitle" does not exist in the collection "${config.slug}"`);
23
+ }
24
+ }
25
+ } else {
26
+ if (!useAsTitleField) {
27
+ throw new InvalidConfiguration(`The field "${config.admin.useAsTitle}" specified in "admin.useAsTitle" does not exist in the collection "${config.slug}"`);
28
+ }
29
+ }
30
+ }
31
+ };
32
+
33
+ //# sourceMappingURL=useAsTitle.js.map
@@ -0,0 +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 } 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) {\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","flattenFields","validateUseAsTitle","config","admin","useAsTitle","includes","slug","fields","useAsTitleField","find","field","name","auth"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,OAAOC,mBAAmB,2CAA0C;AAEpE;;CAEC,GACD,OAAO,MAAMC,qBAAqB,CAACC;IACjC,IAAIA,OAAOC,KAAK,CAACC,UAAU,CAACC,QAAQ,CAAC,MAAM;QACzC,MAAM,IAAIP,qBACR,CAAC,2FAA2F,EAAEI,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,IAAIX,iBAAiBW,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,IAAIV,qBACR,CAAC,WAAW,EAAEI,OAAOC,KAAK,CAACC,UAAU,CAAC,oEAAoE,EAAEF,OAAOI,IAAI,CAAC,CAAC,CAAC;gBAE9H;YACF;QACF,OAAO;YACL,IAAI,CAACE,iBAAiB;gBACpB,MAAM,IAAIV,qBACR,CAAC,WAAW,EAAEI,OAAOC,KAAK,CAACC,UAAU,CAAC,oEAAoE,EAAEF,OAAOI,IAAI,CAAC,CAAC,CAAC;YAE9H;QACF;IACF;AACF,EAAC"}
@@ -0,0 +1,186 @@
1
+ import { InvalidConfiguration } from '../../errors/InvalidConfiguration.js';
2
+ import { sanitizeCollection } from './sanitize.js';
3
+ describe('sanitize - collections -', ()=>{
4
+ const config = {
5
+ collections: [],
6
+ globals: []
7
+ };
8
+ describe('validate useAsTitle -', ()=>{
9
+ const defaultCollection = {
10
+ slug: 'collection-with-defaults',
11
+ fields: [
12
+ {
13
+ name: 'title',
14
+ type: 'text'
15
+ }
16
+ ]
17
+ };
18
+ it('should throw on invalid field', async ()=>{
19
+ const collectionConfig = {
20
+ ...defaultCollection,
21
+ admin: {
22
+ useAsTitle: 'invalidField'
23
+ }
24
+ };
25
+ await expect(async ()=>{
26
+ await sanitizeCollection(// @ts-expect-error
27
+ {
28
+ ...config,
29
+ collections: [
30
+ collectionConfig
31
+ ]
32
+ }, collectionConfig);
33
+ }).rejects.toThrow(InvalidConfiguration);
34
+ });
35
+ it('should not throw on valid field', async ()=>{
36
+ const collectionConfig = {
37
+ ...defaultCollection,
38
+ admin: {
39
+ useAsTitle: 'title'
40
+ }
41
+ };
42
+ await expect(async ()=>{
43
+ await sanitizeCollection(// @ts-expect-error
44
+ {
45
+ ...config,
46
+ collections: [
47
+ collectionConfig
48
+ ]
49
+ }, collectionConfig);
50
+ }).not.toThrow();
51
+ });
52
+ it('should not throw on valid field inside tabs', async ()=>{
53
+ const collectionConfig = {
54
+ ...defaultCollection,
55
+ admin: {
56
+ useAsTitle: 'title'
57
+ },
58
+ fields: [
59
+ {
60
+ type: 'tabs',
61
+ tabs: [
62
+ {
63
+ label: 'General',
64
+ fields: [
65
+ {
66
+ name: 'title',
67
+ type: 'text'
68
+ }
69
+ ]
70
+ }
71
+ ]
72
+ }
73
+ ]
74
+ };
75
+ await expect(async ()=>{
76
+ await sanitizeCollection(// @ts-expect-error
77
+ {
78
+ ...config,
79
+ collections: [
80
+ collectionConfig
81
+ ]
82
+ }, collectionConfig);
83
+ }).not.toThrow();
84
+ });
85
+ it('should not throw on valid field inside collapsibles', async ()=>{
86
+ const collectionConfig = {
87
+ ...defaultCollection,
88
+ admin: {
89
+ useAsTitle: 'title'
90
+ },
91
+ fields: [
92
+ {
93
+ type: 'collapsible',
94
+ label: 'Collapsible',
95
+ fields: [
96
+ {
97
+ name: 'title',
98
+ type: 'text'
99
+ }
100
+ ]
101
+ }
102
+ ]
103
+ };
104
+ await expect(async ()=>{
105
+ await sanitizeCollection(// @ts-expect-error
106
+ {
107
+ ...config,
108
+ collections: [
109
+ collectionConfig
110
+ ]
111
+ }, collectionConfig);
112
+ }).not.toThrow();
113
+ });
114
+ it('should throw on nested useAsTitle', async ()=>{
115
+ const collectionConfig = {
116
+ ...defaultCollection,
117
+ admin: {
118
+ useAsTitle: 'content.title'
119
+ }
120
+ };
121
+ await expect(async ()=>{
122
+ await sanitizeCollection(// @ts-expect-error
123
+ {
124
+ ...config,
125
+ collections: [
126
+ collectionConfig
127
+ ]
128
+ }, collectionConfig);
129
+ }).rejects.toThrow(InvalidConfiguration);
130
+ });
131
+ it('should not throw on default field: id', async ()=>{
132
+ const collectionConfig = {
133
+ ...defaultCollection,
134
+ admin: {
135
+ useAsTitle: 'id'
136
+ }
137
+ };
138
+ await expect(async ()=>{
139
+ await sanitizeCollection(// @ts-expect-error
140
+ {
141
+ ...config,
142
+ collections: [
143
+ collectionConfig
144
+ ]
145
+ }, collectionConfig);
146
+ }).not.toThrow();
147
+ });
148
+ it('should not throw on default field: email if auth is enabled', async ()=>{
149
+ const collectionConfig = {
150
+ ...defaultCollection,
151
+ auth: true,
152
+ admin: {
153
+ useAsTitle: 'email'
154
+ }
155
+ };
156
+ await expect(async ()=>{
157
+ await sanitizeCollection(// @ts-expect-error
158
+ {
159
+ ...config,
160
+ collections: [
161
+ collectionConfig
162
+ ]
163
+ }, collectionConfig);
164
+ }).not.toThrow();
165
+ });
166
+ it('should throw on default field: email if auth is not enabled', async ()=>{
167
+ const collectionConfig = {
168
+ ...defaultCollection,
169
+ admin: {
170
+ useAsTitle: 'email'
171
+ }
172
+ };
173
+ await expect(async ()=>{
174
+ await sanitizeCollection(// @ts-expect-error
175
+ {
176
+ ...config,
177
+ collections: [
178
+ collectionConfig
179
+ ]
180
+ }, collectionConfig);
181
+ }).rejects.toThrow(InvalidConfiguration);
182
+ });
183
+ });
184
+ });
185
+
186
+ //# sourceMappingURL=useAsTitle.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/collections/config/useAsTitle.spec.ts"],"sourcesContent":["import type { Config } from '../../config/types.js'\nimport type { CollectionConfig } from '../../index.js'\n\nimport { InvalidConfiguration } from '../../errors/InvalidConfiguration.js'\nimport { sanitizeCollection } from './sanitize.js'\n\ndescribe('sanitize - collections -', () => {\n const config = {\n collections: [],\n globals: [],\n } as Partial<Config>\n\n describe('validate useAsTitle -', () => {\n const defaultCollection: CollectionConfig = {\n slug: 'collection-with-defaults',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n }\n\n it('should throw on invalid field', async () => {\n const collectionConfig: CollectionConfig = {\n ...defaultCollection,\n admin: {\n useAsTitle: 'invalidField',\n },\n }\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [collectionConfig],\n },\n collectionConfig,\n )\n }).rejects.toThrow(InvalidConfiguration)\n })\n\n it('should not throw on valid field', async () => {\n const collectionConfig: CollectionConfig = {\n ...defaultCollection,\n admin: {\n useAsTitle: 'title',\n },\n }\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [collectionConfig],\n },\n collectionConfig,\n )\n }).not.toThrow()\n })\n\n it('should not throw on valid field inside tabs', async () => {\n const collectionConfig: CollectionConfig = {\n ...defaultCollection,\n admin: {\n useAsTitle: 'title',\n },\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n label: 'General',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n },\n ],\n },\n ],\n }\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [collectionConfig],\n },\n collectionConfig,\n )\n }).not.toThrow()\n })\n\n it('should not throw on valid field inside collapsibles', async () => {\n const collectionConfig: CollectionConfig = {\n ...defaultCollection,\n admin: {\n useAsTitle: 'title',\n },\n fields: [\n {\n type: 'collapsible',\n label: 'Collapsible',\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n },\n ],\n }\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [collectionConfig],\n },\n collectionConfig,\n )\n }).not.toThrow()\n })\n\n it('should throw on nested useAsTitle', async () => {\n const collectionConfig: CollectionConfig = {\n ...defaultCollection,\n admin: {\n useAsTitle: 'content.title',\n },\n }\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [collectionConfig],\n },\n collectionConfig,\n )\n }).rejects.toThrow(InvalidConfiguration)\n })\n\n it('should not throw on default field: id', async () => {\n const collectionConfig: CollectionConfig = {\n ...defaultCollection,\n admin: {\n useAsTitle: 'id',\n },\n }\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [collectionConfig],\n },\n collectionConfig,\n )\n }).not.toThrow()\n })\n\n it('should not throw on default field: email if auth is enabled', async () => {\n const collectionConfig: CollectionConfig = {\n ...defaultCollection,\n auth: true,\n admin: {\n useAsTitle: 'email',\n },\n }\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [collectionConfig],\n },\n collectionConfig,\n )\n }).not.toThrow()\n })\n it('should throw on default field: email if auth is not enabled', async () => {\n const collectionConfig: CollectionConfig = {\n ...defaultCollection,\n admin: {\n useAsTitle: 'email',\n },\n }\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [collectionConfig],\n },\n collectionConfig,\n )\n }).rejects.toThrow(InvalidConfiguration)\n })\n })\n})\n"],"names":["InvalidConfiguration","sanitizeCollection","describe","config","collections","globals","defaultCollection","slug","fields","name","type","it","collectionConfig","admin","useAsTitle","expect","rejects","toThrow","not","tabs","label","auth"],"mappings":"AAGA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,kBAAkB,QAAQ,gBAAe;AAElDC,SAAS,4BAA4B;IACnC,MAAMC,SAAS;QACbC,aAAa,EAAE;QACfC,SAAS,EAAE;IACb;IAEAH,SAAS,yBAAyB;QAChC,MAAMI,oBAAsC;YAC1CC,MAAM;YACNC,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;QACH;QAEAC,GAAG,iCAAiC;YAClC,MAAMC,mBAAqC;gBACzC,GAAGN,iBAAiB;gBACpBO,OAAO;oBACLC,YAAY;gBACd;YACF;YACA,MAAMC,OAAO;gBACX,MAAMd,mBACJ,mBAAmB;gBACnB;oBACE,GAAGE,MAAM;oBACTC,aAAa;wBAACQ;qBAAiB;gBACjC,GACAA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,mBACJ,mBAAmB;gBACnB;oBACE,GAAGE,MAAM;oBACTC,aAAa;wBAACQ;qBAAiB;gBACjC,GACAA;YAEJ,GAAGI,OAAO,CAACC,OAAO,CAACjB;QACrB;QAEAW,GAAG,yCAAyC;YAC1C,MAAMC,mBAAqC;gBACzC,GAAGN,iBAAiB;gBACpBO,OAAO;oBACLC,YAAY;gBACd;YACF;YACA,MAAMC,OAAO;gBACX,MAAMd,mBACJ,mBAAmB;gBACnB;oBACE,GAAGE,MAAM;oBACTC,aAAa;wBAACQ;qBAAiB;gBACjC,GACAA;YAEJ,GAAGM,GAAG,CAACD,OAAO;QAChB;QAEAN,GAAG,+DAA+D;YAChE,MAAMC,mBAAqC;gBACzC,GAAGN,iBAAiB;gBACpBe,MAAM;gBACNR,OAAO;oBACLC,YAAY;gBACd;YACF;YACA,MAAMC,OAAO;gBACX,MAAMd,mBACJ,mBAAmB;gBACnB;oBACE,GAAGE,MAAM;oBACTC,aAAa;wBAACQ;qBAAiB;gBACjC,GACAA;YAEJ,GAAGM,GAAG,CAACD,OAAO;QAChB;QACAN,GAAG,+DAA+D;YAChE,MAAMC,mBAAqC;gBACzC,GAAGN,iBAAiB;gBACpBO,OAAO;oBACLC,YAAY;gBACd;YACF;YACA,MAAMC,OAAO;gBACX,MAAMd,mBACJ,mBAAmB;gBACnB;oBACE,GAAGE,MAAM;oBACTC,aAAa;wBAACQ;qBAAiB;gBACjC,GACAA;YAEJ,GAAGI,OAAO,CAACC,OAAO,CAACjB;QACrB;IACF;AACF"}
@@ -89,8 +89,8 @@ const batchAndLoadDocs = (req)=>async (keys)=>{
89
89
  depth,
90
90
  docID: doc.id,
91
91
  draft,
92
- fallbackLocale: req.fallbackLocale,
93
- locale: req.locale,
92
+ fallbackLocale,
93
+ locale,
94
94
  overrideAccess,
95
95
  showHiddenFields,
96
96
  transactionID: req.transactionID
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/collections/dataloader.ts"],"sourcesContent":["import type { BatchLoadFn } from 'dataloader'\n\nimport DataLoader from 'dataloader'\n\nimport type { PayloadRequest } from '../types/index.js'\nimport type { TypeWithID } from './config/types.js'\n\nimport { isValidID } from '../utilities/isValidID.js'\n\n// Payload uses `dataloader` to solve the classic GraphQL N+1 problem.\n\n// We keep a list of all documents requested to be populated for any given request\n// and then batch together documents within the same collection,\n// making only 1 find per each collection, rather than `findByID` per each requested doc.\n\n// This dramatically improves performance for REST and Local API `depth` populations,\n// and also ensures complex GraphQL queries perform lightning-fast.\n\nconst batchAndLoadDocs =\n (req: PayloadRequest): BatchLoadFn<string, TypeWithID> =>\n async (keys: string[]): Promise<TypeWithID[]> => {\n const { payload } = req\n\n // Create docs array of same length as keys, using null as value\n // We will replace nulls with injected docs as they are retrieved\n const docs: (null | TypeWithID)[] = keys.map(() => null)\n\n /**\n * Batch IDs by their `find` args\n * so we can make one find query per combination of collection, depth, locale, and fallbackLocale.\n *\n * Resulting shape will be as follows:\n {\n // key is stringified set of find args\n '[null,\"pages\",2,0,\"es\",\"en\",false,false]': [\n // value is array of IDs to find with these args\n 'q34tl23462346234524',\n '435523540194324280',\n '2346245j35l3j5234532li',\n ],\n // etc\n };\n *\n **/\n\n const batchByFindArgs = keys.reduce((batches, key) => {\n const [\n transactionID,\n collection,\n id,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n ] = JSON.parse(key)\n\n const batchKeyArray = [\n transactionID,\n collection,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n ]\n\n const batchKey = JSON.stringify(batchKeyArray)\n\n const idType = payload.collections?.[collection].customIDType || payload.db.defaultIDType\n\n let sanitizedID: number | string = id\n\n if (idType === 'number') {\n sanitizedID = parseFloat(id)\n }\n\n if (isValidID(sanitizedID, idType)) {\n return {\n ...batches,\n [batchKey]: [...(batches[batchKey] || []), sanitizedID],\n }\n }\n return batches\n }, {})\n\n // Run find requests one after another, so as to not hang transactions\n\n await Object.entries(batchByFindArgs).reduce(async (priorFind, [batchKey, ids]) => {\n await priorFind\n\n const [\n transactionID,\n collection,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n ] = JSON.parse(batchKey)\n\n req.transactionID = transactionID\n\n const result = await payload.find({\n collection,\n currentDepth,\n depth,\n disableErrors: true,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: Boolean(overrideAccess),\n pagination: false,\n req,\n showHiddenFields: Boolean(showHiddenFields),\n where: {\n id: {\n in: ids,\n },\n },\n })\n\n // For each returned doc, find index in original keys\n // Inject doc within docs array if index exists\n\n result.docs.forEach((doc) => {\n const docKey = createDataloaderCacheKey({\n collectionSlug: collection,\n currentDepth,\n depth,\n docID: doc.id,\n draft,\n fallbackLocale: req.fallbackLocale,\n locale: req.locale,\n overrideAccess,\n showHiddenFields,\n transactionID: req.transactionID,\n })\n const docsIndex = keys.findIndex((key) => key === docKey)\n\n if (docsIndex > -1) {\n docs[docsIndex] = doc\n }\n })\n }, Promise.resolve())\n\n // Return docs array,\n // which has now been injected with all fetched docs\n // and should match the length of the incoming keys arg\n return docs\n }\n\nexport const getDataLoader = (req: PayloadRequest) => new DataLoader(batchAndLoadDocs(req))\n\ntype CreateCacheKeyArgs = {\n collectionSlug: string\n currentDepth: number\n depth: number\n docID: number | string\n draft: boolean\n fallbackLocale: string\n locale: string\n overrideAccess: boolean\n showHiddenFields: boolean\n transactionID: number | Promise<number | string> | string\n}\nexport const createDataloaderCacheKey = ({\n collectionSlug,\n currentDepth,\n depth,\n docID,\n draft,\n fallbackLocale,\n locale,\n overrideAccess,\n showHiddenFields,\n transactionID,\n}: CreateCacheKeyArgs): string =>\n JSON.stringify([\n transactionID,\n collectionSlug,\n docID,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n ])\n"],"names":["DataLoader","isValidID","batchAndLoadDocs","req","keys","payload","docs","map","batchByFindArgs","reduce","batches","key","transactionID","collection","id","depth","currentDepth","locale","fallbackLocale","overrideAccess","showHiddenFields","draft","JSON","parse","batchKeyArray","batchKey","stringify","idType","collections","customIDType","db","defaultIDType","sanitizedID","parseFloat","Object","entries","priorFind","ids","result","find","disableErrors","Boolean","pagination","where","in","forEach","doc","docKey","createDataloaderCacheKey","collectionSlug","docID","docsIndex","findIndex","Promise","resolve","getDataLoader"],"mappings":"AAEA,OAAOA,gBAAgB,aAAY;AAKnC,SAASC,SAAS,QAAQ,4BAA2B;AAErD,sEAAsE;AAEtE,kFAAkF;AAClF,gEAAgE;AAChE,yFAAyF;AAEzF,qFAAqF;AACrF,mEAAmE;AAEnE,MAAMC,mBACJ,CAACC,MACD,OAAOC;QACL,MAAM,EAAEC,OAAO,EAAE,GAAGF;QAEpB,gEAAgE;QAChE,iEAAiE;QACjE,MAAMG,OAA8BF,KAAKG,GAAG,CAAC,IAAM;QAEnD;;;;;;;;;;;;;;;;KAgBC,GAED,MAAMC,kBAAkBJ,KAAKK,MAAM,CAAC,CAACC,SAASC;YAC5C,MAAM,CACJC,eACAC,YACAC,IACAC,OACAC,cACAC,QACAC,gBACAC,gBACAC,kBACAC,MACD,GAAGC,KAAKC,KAAK,CAACZ;YAEf,MAAMa,gBAAgB;gBACpBZ;gBACAC;gBACAE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;aACD;YAED,MAAMI,WAAWH,KAAKI,SAAS,CAACF;YAEhC,MAAMG,SAAStB,QAAQuB,WAAW,EAAE,CAACf,WAAW,CAACgB,gBAAgBxB,QAAQyB,EAAE,CAACC,aAAa;YAEzF,IAAIC,cAA+BlB;YAEnC,IAAIa,WAAW,UAAU;gBACvBK,cAAcC,WAAWnB;YAC3B;YAEA,IAAIb,UAAU+B,aAAaL,SAAS;gBAClC,OAAO;oBACL,GAAGjB,OAAO;oBACV,CAACe,SAAS,EAAE;2BAAKf,OAAO,CAACe,SAAS,IAAI,EAAE;wBAAGO;qBAAY;gBACzD;YACF;YACA,OAAOtB;QAC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ACdD,MAAM,EACNE,cAAc,EACdC,gBAAgB,EAChBR,aAAa,EACM,GACnBU,KAAKI,SAAS,CAAC;QACbd;QACAqC;QACAC;QACAnC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACD,EAAC"}
1
+ {"version":3,"sources":["../../src/collections/dataloader.ts"],"sourcesContent":["import type { BatchLoadFn } from 'dataloader'\n\nimport DataLoader from 'dataloader'\n\nimport type { PayloadRequest } from '../types/index.js'\nimport type { TypeWithID } from './config/types.js'\n\nimport { isValidID } from '../utilities/isValidID.js'\n\n// Payload uses `dataloader` to solve the classic GraphQL N+1 problem.\n\n// We keep a list of all documents requested to be populated for any given request\n// and then batch together documents within the same collection,\n// making only 1 find per each collection, rather than `findByID` per each requested doc.\n\n// This dramatically improves performance for REST and Local API `depth` populations,\n// and also ensures complex GraphQL queries perform lightning-fast.\n\nconst batchAndLoadDocs =\n (req: PayloadRequest): BatchLoadFn<string, TypeWithID> =>\n async (keys: string[]): Promise<TypeWithID[]> => {\n const { payload } = req\n\n // Create docs array of same length as keys, using null as value\n // We will replace nulls with injected docs as they are retrieved\n const docs: (null | TypeWithID)[] = keys.map(() => null)\n\n /**\n * Batch IDs by their `find` args\n * so we can make one find query per combination of collection, depth, locale, and fallbackLocale.\n *\n * Resulting shape will be as follows:\n {\n // key is stringified set of find args\n '[null,\"pages\",2,0,\"es\",\"en\",false,false]': [\n // value is array of IDs to find with these args\n 'q34tl23462346234524',\n '435523540194324280',\n '2346245j35l3j5234532li',\n ],\n // etc\n };\n *\n **/\n\n const batchByFindArgs = keys.reduce((batches, key) => {\n const [\n transactionID,\n collection,\n id,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n ] = JSON.parse(key)\n\n const batchKeyArray = [\n transactionID,\n collection,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n ]\n\n const batchKey = JSON.stringify(batchKeyArray)\n\n const idType = payload.collections?.[collection].customIDType || payload.db.defaultIDType\n\n let sanitizedID: number | string = id\n\n if (idType === 'number') {\n sanitizedID = parseFloat(id)\n }\n\n if (isValidID(sanitizedID, idType)) {\n return {\n ...batches,\n [batchKey]: [...(batches[batchKey] || []), sanitizedID],\n }\n }\n return batches\n }, {})\n\n // Run find requests one after another, so as to not hang transactions\n\n await Object.entries(batchByFindArgs).reduce(async (priorFind, [batchKey, ids]) => {\n await priorFind\n\n const [\n transactionID,\n collection,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n ] = JSON.parse(batchKey)\n\n req.transactionID = transactionID\n\n const result = await payload.find({\n collection,\n currentDepth,\n depth,\n disableErrors: true,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: Boolean(overrideAccess),\n pagination: false,\n req,\n showHiddenFields: Boolean(showHiddenFields),\n where: {\n id: {\n in: ids,\n },\n },\n })\n\n // For each returned doc, find index in original keys\n // Inject doc within docs array if index exists\n\n result.docs.forEach((doc) => {\n const docKey = createDataloaderCacheKey({\n collectionSlug: collection,\n currentDepth,\n depth,\n docID: doc.id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess,\n showHiddenFields,\n transactionID: req.transactionID,\n })\n const docsIndex = keys.findIndex((key) => key === docKey)\n\n if (docsIndex > -1) {\n docs[docsIndex] = doc\n }\n })\n }, Promise.resolve())\n\n // Return docs array,\n // which has now been injected with all fetched docs\n // and should match the length of the incoming keys arg\n return docs\n }\n\nexport const getDataLoader = (req: PayloadRequest) => new DataLoader(batchAndLoadDocs(req))\n\ntype CreateCacheKeyArgs = {\n collectionSlug: string\n currentDepth: number\n depth: number\n docID: number | string\n draft: boolean\n fallbackLocale: string\n locale: string\n overrideAccess: boolean\n showHiddenFields: boolean\n transactionID: number | Promise<number | string> | string\n}\nexport const createDataloaderCacheKey = ({\n collectionSlug,\n currentDepth,\n depth,\n docID,\n draft,\n fallbackLocale,\n locale,\n overrideAccess,\n showHiddenFields,\n transactionID,\n}: CreateCacheKeyArgs): string =>\n JSON.stringify([\n transactionID,\n collectionSlug,\n docID,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n ])\n"],"names":["DataLoader","isValidID","batchAndLoadDocs","req","keys","payload","docs","map","batchByFindArgs","reduce","batches","key","transactionID","collection","id","depth","currentDepth","locale","fallbackLocale","overrideAccess","showHiddenFields","draft","JSON","parse","batchKeyArray","batchKey","stringify","idType","collections","customIDType","db","defaultIDType","sanitizedID","parseFloat","Object","entries","priorFind","ids","result","find","disableErrors","Boolean","pagination","where","in","forEach","doc","docKey","createDataloaderCacheKey","collectionSlug","docID","docsIndex","findIndex","Promise","resolve","getDataLoader"],"mappings":"AAEA,OAAOA,gBAAgB,aAAY;AAKnC,SAASC,SAAS,QAAQ,4BAA2B;AAErD,sEAAsE;AAEtE,kFAAkF;AAClF,gEAAgE;AAChE,yFAAyF;AAEzF,qFAAqF;AACrF,mEAAmE;AAEnE,MAAMC,mBACJ,CAACC,MACD,OAAOC;QACL,MAAM,EAAEC,OAAO,EAAE,GAAGF;QAEpB,gEAAgE;QAChE,iEAAiE;QACjE,MAAMG,OAA8BF,KAAKG,GAAG,CAAC,IAAM;QAEnD;;;;;;;;;;;;;;;;KAgBC,GAED,MAAMC,kBAAkBJ,KAAKK,MAAM,CAAC,CAACC,SAASC;YAC5C,MAAM,CACJC,eACAC,YACAC,IACAC,OACAC,cACAC,QACAC,gBACAC,gBACAC,kBACAC,MACD,GAAGC,KAAKC,KAAK,CAACZ;YAEf,MAAMa,gBAAgB;gBACpBZ;gBACAC;gBACAE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;aACD;YAED,MAAMI,WAAWH,KAAKI,SAAS,CAACF;YAEhC,MAAMG,SAAStB,QAAQuB,WAAW,EAAE,CAACf,WAAW,CAACgB,gBAAgBxB,QAAQyB,EAAE,CAACC,aAAa;YAEzF,IAAIC,cAA+BlB;YAEnC,IAAIa,WAAW,UAAU;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,CAACpD,MAAwB,IAAIH,WAAWE,iBAAiBC,MAAK;AAc3F,OAAO,MAAM6C,2BAA2B,CAAC,EACvCC,cAAc,EACdjC,YAAY,EACZD,KAAK,EACLmC,KAAK,EACL7B,KAAK,EACLH,cAAc,EACdD,MAAM,EACNE,cAAc,EACdC,gBAAgB,EAChBR,aAAa,EACM,GACnBU,KAAKI,SAAS,CAAC;QACbd;QACAqC;QACAC;QACAnC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACD,EAAC"}
@@ -1,5 +1,4 @@
1
1
  import type { Document } from '../../types/index.js';
2
2
  import type { PreferenceRequest } from '../types.js';
3
- declare function deleteOperation(args: PreferenceRequest): Promise<Document>;
4
- export default deleteOperation;
3
+ export declare function deleteOperation(args: PreferenceRequest): Promise<Document>;
5
4
  //# sourceMappingURL=delete.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/preferences/operations/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAS,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAOpD,iBAAe,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmCzE;AAED,eAAe,eAAe,CAAA"}
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/preferences/operations/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAS,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAKpD,wBAAsB,eAAe,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8BhF"}
@@ -1,17 +1,10 @@
1
- import defaultAccess from '../../auth/defaultAccess.js';
2
- import executeAccess from '../../auth/executeAccess.js';
3
1
  import { NotFound } from '../../errors/NotFound.js';
4
2
  import { UnauthorizedError } from '../../errors/UnathorizedError.js';
5
- async function deleteOperation(args) {
6
- const { key, overrideAccess, req: { payload }, req, user } = args;
3
+ export async function deleteOperation(args) {
4
+ const { key, req: { payload }, req, user } = args;
7
5
  if (!user) {
8
6
  throw new UnauthorizedError(req.t);
9
7
  }
10
- if (!overrideAccess) {
11
- await executeAccess({
12
- req
13
- }, defaultAccess);
14
- }
15
8
  const where = {
16
9
  and: [
17
10
  {
@@ -41,6 +34,5 @@ async function deleteOperation(args) {
41
34
  }
42
35
  throw new NotFound(req.t);
43
36
  }
44
- export default deleteOperation;
45
37
 
46
38
  //# sourceMappingURL=delete.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/preferences/operations/delete.ts"],"sourcesContent":["import type { Document, Where } from '../../types/index.js'\nimport type { PreferenceRequest } from '../types.js'\n\nimport defaultAccess from '../../auth/defaultAccess.js'\nimport executeAccess from '../../auth/executeAccess.js'\nimport { NotFound } from '../../errors/NotFound.js'\nimport { UnauthorizedError } from '../../errors/UnathorizedError.js'\n\nasync function deleteOperation(args: PreferenceRequest): Promise<Document> {\n const {\n key,\n overrideAccess,\n req: { payload },\n req,\n user,\n } = args\n\n if (!user) {\n throw new UnauthorizedError(req.t)\n }\n\n if (!overrideAccess) {\n await executeAccess({ req }, defaultAccess)\n }\n\n const where: Where = {\n and: [\n { key: { equals: key } },\n { 'user.value': { equals: user.id } },\n { 'user.relationTo': { equals: user.collection } },\n ],\n }\n\n const result = await payload.db.deleteOne({\n collection: 'payload-preferences',\n req,\n where,\n })\n\n if (result) {\n return result\n }\n throw new NotFound(req.t)\n}\n\nexport default deleteOperation\n"],"names":["defaultAccess","executeAccess","NotFound","UnauthorizedError","deleteOperation","args","key","overrideAccess","req","payload","user","t","where","and","equals","id","collection","result","db","deleteOne"],"mappings":"AAGA,OAAOA,mBAAmB,8BAA6B;AACvD,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,iBAAiB,QAAQ,mCAAkC;AAEpE,eAAeC,gBAAgBC,IAAuB;IACpD,MAAM,EACJC,GAAG,EACHC,cAAc,EACdC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACHE,IAAI,EACL,GAAGL;IAEJ,IAAI,CAACK,MAAM;QACT,MAAM,IAAIP,kBAAkBK,IAAIG,CAAC;IACnC;IAEA,IAAI,CAACJ,gBAAgB;QACnB,MAAMN,cAAc;YAAEO;QAAI,GAAGR;IAC/B;IAEA,MAAMY,QAAe;QACnBC,KAAK;YACH;gBAAEP,KAAK;oBAAEQ,QAAQR;gBAAI;YAAE;YACvB;gBAAE,cAAc;oBAAEQ,QAAQJ,KAAKK,EAAE;gBAAC;YAAE;YACpC;gBAAE,mBAAmB;oBAAED,QAAQJ,KAAKM,UAAU;gBAAC;YAAE;SAClD;IACH;IAEA,MAAMC,SAAS,MAAMR,QAAQS,EAAE,CAACC,SAAS,CAAC;QACxCH,YAAY;QACZR;QACAI;IACF;IAEA,IAAIK,QAAQ;QACV,OAAOA;IACT;IACA,MAAM,IAAIf,SAASM,IAAIG,CAAC;AAC1B;AAEA,eAAeP,gBAAe"}
1
+ {"version":3,"sources":["../../../src/preferences/operations/delete.ts"],"sourcesContent":["import type { Document, Where } from '../../types/index.js'\nimport type { PreferenceRequest } from '../types.js'\n\nimport { NotFound } from '../../errors/NotFound.js'\nimport { UnauthorizedError } from '../../errors/UnathorizedError.js'\n\nexport async function deleteOperation(args: PreferenceRequest): Promise<Document> {\n const {\n key,\n req: { payload },\n req,\n user,\n } = args\n\n if (!user) {\n throw new UnauthorizedError(req.t)\n }\n\n const where: Where = {\n and: [\n { key: { equals: key } },\n { 'user.value': { equals: user.id } },\n { 'user.relationTo': { equals: user.collection } },\n ],\n }\n\n const result = await payload.db.deleteOne({\n collection: 'payload-preferences',\n req,\n where,\n })\n\n if (result) {\n return result\n }\n throw new NotFound(req.t)\n}\n"],"names":["NotFound","UnauthorizedError","deleteOperation","args","key","req","payload","user","t","where","and","equals","id","collection","result","db","deleteOne"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,iBAAiB,QAAQ,mCAAkC;AAEpE,OAAO,eAAeC,gBAAgBC,IAAuB;IAC3D,MAAM,EACJC,GAAG,EACHC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACHE,IAAI,EACL,GAAGJ;IAEJ,IAAI,CAACI,MAAM;QACT,MAAM,IAAIN,kBAAkBI,IAAIG,CAAC;IACnC;IAEA,MAAMC,QAAe;QACnBC,KAAK;YACH;gBAAEN,KAAK;oBAAEO,QAAQP;gBAAI;YAAE;YACvB;gBAAE,cAAc;oBAAEO,QAAQJ,KAAKK,EAAE;gBAAC;YAAE;YACpC;gBAAE,mBAAmB;oBAAED,QAAQJ,KAAKM,UAAU;gBAAC;YAAE;SAClD;IACH;IAEA,MAAMC,SAAS,MAAMR,QAAQS,EAAE,CAACC,SAAS,CAAC;QACxCH,YAAY;QACZR;QACAI;IACF;IAEA,IAAIK,QAAQ;QACV,OAAOA;IACT;IACA,MAAM,IAAId,SAASK,IAAIG,CAAC;AAC1B"}
@@ -1,5 +1,4 @@
1
1
  import type { TypedCollection } from '../../index.js';
2
2
  import type { PreferenceRequest } from '../types.js';
3
- declare function findOne(args: PreferenceRequest): Promise<TypedCollection['_preference']>;
4
- export default findOne;
3
+ export declare function findOne(args: PreferenceRequest): Promise<TypedCollection['_preference']>;
5
4
  //# sourceMappingURL=findOne.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../src/preferences/operations/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD,iBAAe,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAyBvF;AAED,eAAe,OAAO,CAAA"}
1
+ {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../../../src/preferences/operations/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAErD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD,wBAAsB,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CA8B9F"}
@@ -1,4 +1,4 @@
1
- async function findOne(args) {
1
+ export async function findOne(args) {
2
2
  const { key, req: { payload }, req, user } = args;
3
3
  if (!user) {
4
4
  return null;
@@ -22,12 +22,15 @@ async function findOne(args) {
22
22
  }
23
23
  ]
24
24
  };
25
- return await payload.db.findOne({
25
+ const { docs } = await payload.db.find({
26
26
  collection: 'payload-preferences',
27
+ limit: 1,
28
+ pagination: false,
27
29
  req,
30
+ sort: '-updatedAt',
28
31
  where
29
32
  });
33
+ return docs?.[0] || null;
30
34
  }
31
- export default findOne;
32
35
 
33
36
  //# sourceMappingURL=findOne.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/preferences/operations/findOne.ts"],"sourcesContent":["import type { TypedCollection } from '../../index.js'\nimport type { Where } from '../../types/index.js'\nimport type { PreferenceRequest } from '../types.js'\n\nasync function findOne(args: PreferenceRequest): Promise<TypedCollection['_preference']> {\n const {\n key,\n req: { payload },\n req,\n user,\n } = args\n\n if (!user) {\n return null\n }\n\n const where: Where = {\n and: [\n { key: { equals: key } },\n { 'user.value': { equals: user.id } },\n { 'user.relationTo': { equals: user.collection } },\n ],\n }\n\n return await payload.db.findOne({\n collection: 'payload-preferences',\n req,\n where,\n })\n}\n\nexport default findOne\n"],"names":["findOne","args","key","req","payload","user","where","and","equals","id","collection","db"],"mappings":"AAIA,eAAeA,QAAQC,IAAuB;IAC5C,MAAM,EACJC,GAAG,EACHC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACHE,IAAI,EACL,GAAGJ;IAEJ,IAAI,CAACI,MAAM;QACT,OAAO;IACT;IAEA,MAAMC,QAAe;QACnBC,KAAK;YACH;gBAAEL,KAAK;oBAAEM,QAAQN;gBAAI;YAAE;YACvB;gBAAE,cAAc;oBAAEM,QAAQH,KAAKI,EAAE;gBAAC;YAAE;YACpC;gBAAE,mBAAmB;oBAAED,QAAQH,KAAKK,UAAU;gBAAC;YAAE;SAClD;IACH;IAEA,OAAO,MAAMN,QAAQO,EAAE,CAACX,OAAO,CAAC;QAC9BU,YAAY;QACZP;QACAG;IACF;AACF;AAEA,eAAeN,QAAO"}
1
+ {"version":3,"sources":["../../../src/preferences/operations/findOne.ts"],"sourcesContent":["import type { TypedCollection } from '../../index.js'\nimport type { Where } from '../../types/index.js'\nimport type { PreferenceRequest } from '../types.js'\n\nexport async function findOne(args: PreferenceRequest): Promise<TypedCollection['_preference']> {\n const {\n key,\n req: { payload },\n req,\n user,\n } = args\n\n if (!user) {\n return null\n }\n\n const where: Where = {\n and: [\n { key: { equals: key } },\n { 'user.value': { equals: user.id } },\n { 'user.relationTo': { equals: user.collection } },\n ],\n }\n\n const { docs } = await payload.db.find({\n collection: 'payload-preferences',\n limit: 1,\n pagination: false,\n req,\n sort: '-updatedAt',\n where,\n })\n\n return docs?.[0] || null\n}\n"],"names":["findOne","args","key","req","payload","user","where","and","equals","id","collection","docs","db","find","limit","pagination","sort"],"mappings":"AAIA,OAAO,eAAeA,QAAQC,IAAuB;IACnD,MAAM,EACJC,GAAG,EACHC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACHE,IAAI,EACL,GAAGJ;IAEJ,IAAI,CAACI,MAAM;QACT,OAAO;IACT;IAEA,MAAMC,QAAe;QACnBC,KAAK;YACH;gBAAEL,KAAK;oBAAEM,QAAQN;gBAAI;YAAE;YACvB;gBAAE,cAAc;oBAAEM,QAAQH,KAAKI,EAAE;gBAAC;YAAE;YACpC;gBAAE,mBAAmB;oBAAED,QAAQH,KAAKK,UAAU;gBAAC;YAAE;SAClD;IACH;IAEA,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMP,QAAQQ,EAAE,CAACC,IAAI,CAAC;QACrCH,YAAY;QACZI,OAAO;QACPC,YAAY;QACZZ;QACAa,MAAM;QACNV;IACF;IAEA,OAAOK,MAAM,CAAC,EAAE,IAAI;AACtB"}
@@ -1,11 +1,3 @@
1
1
  import type { PreferenceUpdateRequest } from '../types.js';
2
- declare function update(args: PreferenceUpdateRequest): Promise<{
3
- key: string;
4
- user: {
5
- relationTo: string;
6
- value: string | number;
7
- };
8
- value: unknown;
9
- }>;
10
- export default update;
2
+ export declare function update(args: PreferenceUpdateRequest): Promise<any>;
11
3
  //# sourceMappingURL=update.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/preferences/operations/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAM1D,iBAAe,MAAM,CAAC,IAAI,EAAE,uBAAuB;;;;;;;GAoDlD;AAED,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/preferences/operations/update.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAI1D,wBAAsB,MAAM,CAAC,IAAI,EAAE,uBAAuB,gBAmDzD"}
@@ -1,22 +1,28 @@
1
- import defaultAccess from '../../auth/defaultAccess.js';
2
- import executeAccess from '../../auth/executeAccess.js';
3
1
  import { UnauthorizedError } from '../../errors/UnathorizedError.js';
4
- async function update(args) {
5
- const { key, overrideAccess, req: { payload }, req, user, value } = args;
2
+ export async function update(args) {
3
+ const { key, req: { payload }, req, user, value } = args;
6
4
  if (!user) {
7
5
  throw new UnauthorizedError(req.t);
8
6
  }
9
7
  const collection = 'payload-preferences';
10
- const filter = {
11
- key: {
12
- equals: key
13
- },
14
- 'user.relationTo': {
15
- equals: user.collection
16
- },
17
- 'user.value': {
18
- equals: user.id
19
- }
8
+ const where = {
9
+ and: [
10
+ {
11
+ key: {
12
+ equals: key
13
+ }
14
+ },
15
+ {
16
+ 'user.value': {
17
+ equals: user.id
18
+ }
19
+ },
20
+ {
21
+ 'user.relationTo': {
22
+ equals: user.collection
23
+ }
24
+ }
25
+ ]
20
26
  };
21
27
  const preference = {
22
28
  key,
@@ -26,28 +32,23 @@ async function update(args) {
26
32
  },
27
33
  value
28
34
  };
29
- if (!overrideAccess) {
30
- await executeAccess({
31
- req
32
- }, defaultAccess);
33
- }
35
+ let result;
34
36
  try {
35
37
  // try/catch because we attempt to update without first reading to check if it exists first to save on db calls
36
- await payload.db.updateOne({
38
+ result = await payload.db.updateOne({
37
39
  collection,
38
40
  data: preference,
39
41
  req,
40
- where: filter
42
+ where
41
43
  });
42
44
  } catch (err) {
43
- await payload.db.create({
45
+ result = await payload.db.create({
44
46
  collection,
45
47
  data: preference,
46
48
  req
47
49
  });
48
50
  }
49
- return preference;
51
+ return result;
50
52
  }
51
- export default update;
52
53
 
53
54
  //# sourceMappingURL=update.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/preferences/operations/update.ts"],"sourcesContent":["import type { PreferenceUpdateRequest } from '../types.js'\n\nimport defaultAccess from '../../auth/defaultAccess.js'\nimport executeAccess from '../../auth/executeAccess.js'\nimport { UnauthorizedError } from '../../errors/UnathorizedError.js'\n\nasync function update(args: PreferenceUpdateRequest) {\n const {\n key,\n overrideAccess,\n req: { payload },\n req,\n user,\n value,\n } = args\n\n if (!user) {\n throw new UnauthorizedError(req.t)\n }\n\n const collection = 'payload-preferences'\n\n const filter = {\n key: { equals: key },\n 'user.relationTo': { equals: user.collection },\n 'user.value': { equals: user.id },\n }\n\n const preference = {\n key,\n user: {\n relationTo: user.collection,\n value: user.id,\n },\n value,\n }\n\n if (!overrideAccess) {\n await executeAccess({ req }, defaultAccess)\n }\n\n try {\n // try/catch because we attempt to update without first reading to check if it exists first to save on db calls\n await payload.db.updateOne({\n collection,\n data: preference,\n req,\n where: filter,\n })\n } catch (err: unknown) {\n await payload.db.create({\n collection,\n data: preference,\n req,\n })\n }\n\n return preference\n}\n\nexport default update\n"],"names":["defaultAccess","executeAccess","UnauthorizedError","update","args","key","overrideAccess","req","payload","user","value","t","collection","filter","equals","id","preference","relationTo","db","updateOne","data","where","err","create"],"mappings":"AAEA,OAAOA,mBAAmB,8BAA6B;AACvD,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,iBAAiB,QAAQ,mCAAkC;AAEpE,eAAeC,OAAOC,IAA6B;IACjD,MAAM,EACJC,GAAG,EACHC,cAAc,EACdC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACHE,IAAI,EACJC,KAAK,EACN,GAAGN;IAEJ,IAAI,CAACK,MAAM;QACT,MAAM,IAAIP,kBAAkBK,IAAII,CAAC;IACnC;IAEA,MAAMC,aAAa;IAEnB,MAAMC,SAAS;QACbR,KAAK;YAAES,QAAQT;QAAI;QACnB,mBAAmB;YAAES,QAAQL,KAAKG,UAAU;QAAC;QAC7C,cAAc;YAAEE,QAAQL,KAAKM,EAAE;QAAC;IAClC;IAEA,MAAMC,aAAa;QACjBX;QACAI,MAAM;YACJQ,YAAYR,KAAKG,UAAU;YAC3BF,OAAOD,KAAKM,EAAE;QAChB;QACAL;IACF;IAEA,IAAI,CAACJ,gBAAgB;QACnB,MAAML,cAAc;YAAEM;QAAI,GAAGP;IAC/B;IAEA,IAAI;QACF,+GAA+G;QAC/G,MAAMQ,QAAQU,EAAE,CAACC,SAAS,CAAC;YACzBP;YACAQ,MAAMJ;YACNT;YACAc,OAAOR;QACT;IACF,EAAE,OAAOS,KAAc;QACrB,MAAMd,QAAQU,EAAE,CAACK,MAAM,CAAC;YACtBX;YACAQ,MAAMJ;YACNT;QACF;IACF;IAEA,OAAOS;AACT;AAEA,eAAeb,OAAM"}
1
+ {"version":3,"sources":["../../../src/preferences/operations/update.ts"],"sourcesContent":["import type { Where } from '../../types/index.js'\nimport type { PreferenceUpdateRequest } from '../types.js'\n\nimport { UnauthorizedError } from '../../errors/UnathorizedError.js'\n\nexport async function update(args: PreferenceUpdateRequest) {\n const {\n key,\n req: { payload },\n req,\n user,\n value,\n } = args\n\n if (!user) {\n throw new UnauthorizedError(req.t)\n }\n\n const collection = 'payload-preferences'\n\n const where: Where = {\n and: [\n { key: { equals: key } },\n { 'user.value': { equals: user.id } },\n { 'user.relationTo': { equals: user.collection } },\n ],\n }\n\n const preference = {\n key,\n user: {\n relationTo: user.collection,\n value: user.id,\n },\n value,\n }\n\n let result\n\n try {\n // try/catch because we attempt to update without first reading to check if it exists first to save on db calls\n result = await payload.db.updateOne({\n collection,\n data: preference,\n req,\n where,\n })\n } catch (err: unknown) {\n result = await payload.db.create({\n collection,\n data: preference,\n req,\n })\n }\n\n return result\n}\n"],"names":["UnauthorizedError","update","args","key","req","payload","user","value","t","collection","where","and","equals","id","preference","relationTo","result","db","updateOne","data","err","create"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,mCAAkC;AAEpE,OAAO,eAAeC,OAAOC,IAA6B;IACxD,MAAM,EACJC,GAAG,EACHC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACHE,IAAI,EACJC,KAAK,EACN,GAAGL;IAEJ,IAAI,CAACI,MAAM;QACT,MAAM,IAAIN,kBAAkBI,IAAII,CAAC;IACnC;IAEA,MAAMC,aAAa;IAEnB,MAAMC,QAAe;QACnBC,KAAK;YACH;gBAAER,KAAK;oBAAES,QAAQT;gBAAI;YAAE;YACvB;gBAAE,cAAc;oBAAES,QAAQN,KAAKO,EAAE;gBAAC;YAAE;YACpC;gBAAE,mBAAmB;oBAAED,QAAQN,KAAKG,UAAU;gBAAC;YAAE;SAClD;IACH;IAEA,MAAMK,aAAa;QACjBX;QACAG,MAAM;YACJS,YAAYT,KAAKG,UAAU;YAC3BF,OAAOD,KAAKO,EAAE;QAChB;QACAN;IACF;IAEA,IAAIS;IAEJ,IAAI;QACF,+GAA+G;QAC/GA,SAAS,MAAMX,QAAQY,EAAE,CAACC,SAAS,CAAC;YAClCT;YACAU,MAAML;YACNV;YACAM;QACF;IACF,EAAE,OAAOU,KAAc;QACrBJ,SAAS,MAAMX,QAAQY,EAAE,CAACI,MAAM,CAAC;YAC/BZ;YACAU,MAAML;YACNV;QACF;IACF;IAEA,OAAOY;AACT"}
@@ -1,5 +1,5 @@
1
1
  import httpStatus from 'http-status';
2
- import deleteOperation from '../operations/delete.js';
2
+ import { deleteOperation } from '../operations/delete.js';
3
3
  export const deleteHandler = async (incomingReq)=>{
4
4
  // We cannot import the addDataAndFileToRequest utility here from the 'next' package because of dependency issues
5
5
  // However that utility should be used where possible instead of manually appending the data
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/preferences/requestHandlers/delete.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport deleteOperation from '../operations/delete.js'\n\nexport const deleteHandler: PayloadHandler = async (incomingReq): Promise<Response> => {\n // We cannot import the addDataAndFileToRequest utility here from the 'next' package because of dependency issues\n // However that utility should be used where possible instead of manually appending the data\n let data\n\n try {\n data = await incomingReq.json()\n } catch (error) {\n data = {}\n }\n\n const reqWithData: PayloadRequest = incomingReq\n\n if (data) {\n reqWithData.data = data\n reqWithData.json = () => Promise.resolve(data)\n }\n\n const result = await deleteOperation({\n key: reqWithData.routeParams?.key as string,\n req: reqWithData,\n user: reqWithData.user,\n })\n\n return Response.json(\n {\n ...result,\n message: reqWithData.t('general:deletedSuccessfully'),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","deleteOperation","deleteHandler","incomingReq","data","json","error","reqWithData","Promise","resolve","result","key","routeParams","req","user","Response","message","t","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAKpC,OAAOC,qBAAqB,0BAAyB;AAErD,OAAO,MAAMC,gBAAgC,OAAOC;IAClD,iHAAiH;IACjH,4FAA4F;IAC5F,IAAIC;IAEJ,IAAI;QACFA,OAAO,MAAMD,YAAYE,IAAI;IAC/B,EAAE,OAAOC,OAAO;QACdF,OAAO,CAAC;IACV;IAEA,MAAMG,cAA8BJ;IAEpC,IAAIC,MAAM;QACRG,YAAYH,IAAI,GAAGA;QACnBG,YAAYF,IAAI,GAAG,IAAMG,QAAQC,OAAO,CAACL;IAC3C;IAEA,MAAMM,SAAS,MAAMT,gBAAgB;QACnCU,KAAKJ,YAAYK,WAAW,EAAED;QAC9BE,KAAKN;QACLO,MAAMP,YAAYO,IAAI;IACxB;IAEA,OAAOC,SAASV,IAAI,CAClB;QACE,GAAGK,MAAM;QACTM,SAAST,YAAYU,CAAC,CAAC;IACzB,GACA;QACEC,QAAQlB,WAAWmB,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../src/preferences/requestHandlers/delete.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { deleteOperation } from '../operations/delete.js'\n\nexport const deleteHandler: PayloadHandler = async (incomingReq): Promise<Response> => {\n // We cannot import the addDataAndFileToRequest utility here from the 'next' package because of dependency issues\n // However that utility should be used where possible instead of manually appending the data\n let data\n\n try {\n data = await incomingReq.json()\n } catch (error) {\n data = {}\n }\n\n const reqWithData: PayloadRequest = incomingReq\n\n if (data) {\n reqWithData.data = data\n reqWithData.json = () => Promise.resolve(data)\n }\n\n const result = await deleteOperation({\n key: reqWithData.routeParams?.key as string,\n req: reqWithData,\n user: reqWithData.user,\n })\n\n return Response.json(\n {\n ...result,\n message: reqWithData.t('general:deletedSuccessfully'),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","deleteOperation","deleteHandler","incomingReq","data","json","error","reqWithData","Promise","resolve","result","key","routeParams","req","user","Response","message","t","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAKpC,SAASC,eAAe,QAAQ,0BAAyB;AAEzD,OAAO,MAAMC,gBAAgC,OAAOC;IAClD,iHAAiH;IACjH,4FAA4F;IAC5F,IAAIC;IAEJ,IAAI;QACFA,OAAO,MAAMD,YAAYE,IAAI;IAC/B,EAAE,OAAOC,OAAO;QACdF,OAAO,CAAC;IACV;IAEA,MAAMG,cAA8BJ;IAEpC,IAAIC,MAAM;QACRG,YAAYH,IAAI,GAAGA;QACnBG,YAAYF,IAAI,GAAG,IAAMG,QAAQC,OAAO,CAACL;IAC3C;IAEA,MAAMM,SAAS,MAAMT,gBAAgB;QACnCU,KAAKJ,YAAYK,WAAW,EAAED;QAC9BE,KAAKN;QACLO,MAAMP,YAAYO,IAAI;IACxB;IAEA,OAAOC,SAASV,IAAI,CAClB;QACE,GAAGK,MAAM;QACTM,SAAST,YAAYU,CAAC,CAAC;IACzB,GACA;QACEC,QAAQlB,WAAWmB,EAAE;IACvB;AAEJ,EAAC"}
@@ -1,5 +1,5 @@
1
1
  import httpStatus from 'http-status';
2
- import findOne from '../operations/findOne.js';
2
+ import { findOne } from '../operations/findOne.js';
3
3
  export const findByIDHandler = async (incomingReq)=>{
4
4
  // We cannot import the addDataAndFileToRequest utility here from the 'next' package because of dependency issues
5
5
  // However that utility should be used where possible instead of manually appending the data
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/preferences/requestHandlers/findOne.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport findOne from '../operations/findOne.js'\n\nexport const findByIDHandler: PayloadHandler = async (incomingReq): Promise<Response> => {\n // We cannot import the addDataAndFileToRequest utility here from the 'next' package because of dependency issues\n // However that utility should be used where possible instead of manually appending the data\n let data\n\n try {\n data = await incomingReq.json()\n } catch (error) {\n data = {}\n }\n\n const reqWithData: PayloadRequest = incomingReq\n\n if (data) {\n reqWithData.data = data\n reqWithData.json = () => Promise.resolve(data)\n }\n\n const result = await findOne({\n key: reqWithData.routeParams?.key as string,\n req: reqWithData,\n user: reqWithData.user,\n })\n\n return Response.json(\n {\n ...(result\n ? result\n : {\n message: reqWithData.t('general:notFound'),\n value: null,\n }),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","findOne","findByIDHandler","incomingReq","data","json","error","reqWithData","Promise","resolve","result","key","routeParams","req","user","Response","message","t","value","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAKpC,OAAOC,aAAa,2BAA0B;AAE9C,OAAO,MAAMC,kBAAkC,OAAOC;IACpD,iHAAiH;IACjH,4FAA4F;IAC5F,IAAIC;IAEJ,IAAI;QACFA,OAAO,MAAMD,YAAYE,IAAI;IAC/B,EAAE,OAAOC,OAAO;QACdF,OAAO,CAAC;IACV;IAEA,MAAMG,cAA8BJ;IAEpC,IAAIC,MAAM;QACRG,YAAYH,IAAI,GAAGA;QACnBG,YAAYF,IAAI,GAAG,IAAMG,QAAQC,OAAO,CAACL;IAC3C;IAEA,MAAMM,SAAS,MAAMT,QAAQ;QAC3BU,KAAKJ,YAAYK,WAAW,EAAED;QAC9BE,KAAKN;QACLO,MAAMP,YAAYO,IAAI;IACxB;IAEA,OAAOC,SAASV,IAAI,CAClB;QACE,GAAIK,SACAA,SACA;YACEM,SAAST,YAAYU,CAAC,CAAC;YACvBC,OAAO;QACT,CAAC;IACP,GACA;QACEC,QAAQnB,WAAWoB,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../src/preferences/requestHandlers/findOne.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { findOne } from '../operations/findOne.js'\n\nexport const findByIDHandler: PayloadHandler = async (incomingReq): Promise<Response> => {\n // We cannot import the addDataAndFileToRequest utility here from the 'next' package because of dependency issues\n // However that utility should be used where possible instead of manually appending the data\n let data\n\n try {\n data = await incomingReq.json()\n } catch (error) {\n data = {}\n }\n\n const reqWithData: PayloadRequest = incomingReq\n\n if (data) {\n reqWithData.data = data\n reqWithData.json = () => Promise.resolve(data)\n }\n\n const result = await findOne({\n key: reqWithData.routeParams?.key as string,\n req: reqWithData,\n user: reqWithData.user,\n })\n\n return Response.json(\n {\n ...(result\n ? result\n : {\n message: reqWithData.t('general:notFound'),\n value: null,\n }),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","findOne","findByIDHandler","incomingReq","data","json","error","reqWithData","Promise","resolve","result","key","routeParams","req","user","Response","message","t","value","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAKpC,SAASC,OAAO,QAAQ,2BAA0B;AAElD,OAAO,MAAMC,kBAAkC,OAAOC;IACpD,iHAAiH;IACjH,4FAA4F;IAC5F,IAAIC;IAEJ,IAAI;QACFA,OAAO,MAAMD,YAAYE,IAAI;IAC/B,EAAE,OAAOC,OAAO;QACdF,OAAO,CAAC;IACV;IAEA,MAAMG,cAA8BJ;IAEpC,IAAIC,MAAM;QACRG,YAAYH,IAAI,GAAGA;QACnBG,YAAYF,IAAI,GAAG,IAAMG,QAAQC,OAAO,CAACL;IAC3C;IAEA,MAAMM,SAAS,MAAMT,QAAQ;QAC3BU,KAAKJ,YAAYK,WAAW,EAAED;QAC9BE,KAAKN;QACLO,MAAMP,YAAYO,IAAI;IACxB;IAEA,OAAOC,SAASV,IAAI,CAClB;QACE,GAAIK,SACAA,SACA;YACEM,SAAST,YAAYU,CAAC,CAAC;YACvBC,OAAO;QACT,CAAC;IACP,GACA;QACEC,QAAQnB,WAAWoB,EAAE;IACvB;AAEJ,EAAC"}
@@ -1,5 +1,5 @@
1
1
  import httpStatus from 'http-status';
2
- import update from '../operations/update.js';
2
+ import { update } from '../operations/update.js';
3
3
  export const updateHandler = async (incomingReq)=>{
4
4
  // We cannot import the addDataAndFileToRequest utility here from the 'next' package because of dependency issues
5
5
  // However that utility should be used where possible instead of manually appending the data
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/preferences/requestHandlers/update.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport update from '../operations/update.js'\n\nexport const updateHandler: PayloadHandler = async (incomingReq) => {\n // We cannot import the addDataAndFileToRequest utility here from the 'next' package because of dependency issues\n // However that utility should be used where possible instead of manually appending the data\n let data\n\n try {\n data = await incomingReq.json()\n } catch (error) {\n data = {}\n }\n\n const reqWithData: PayloadRequest = incomingReq\n\n if (data) {\n reqWithData.data = data\n reqWithData.json = () => Promise.resolve(data)\n }\n\n const doc = await update({\n key: reqWithData.routeParams?.key as string,\n req: reqWithData,\n user: reqWithData?.user,\n value: reqWithData.data.value || reqWithData.data,\n })\n\n return Response.json(\n {\n doc,\n message: reqWithData.t('general:updatedSuccessfully'),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","update","updateHandler","incomingReq","data","json","error","reqWithData","Promise","resolve","doc","key","routeParams","req","user","value","Response","message","t","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAKpC,OAAOC,YAAY,0BAAyB;AAE5C,OAAO,MAAMC,gBAAgC,OAAOC;IAClD,iHAAiH;IACjH,4FAA4F;IAC5F,IAAIC;IAEJ,IAAI;QACFA,OAAO,MAAMD,YAAYE,IAAI;IAC/B,EAAE,OAAOC,OAAO;QACdF,OAAO,CAAC;IACV;IAEA,MAAMG,cAA8BJ;IAEpC,IAAIC,MAAM;QACRG,YAAYH,IAAI,GAAGA;QACnBG,YAAYF,IAAI,GAAG,IAAMG,QAAQC,OAAO,CAACL;IAC3C;IAEA,MAAMM,MAAM,MAAMT,OAAO;QACvBU,KAAKJ,YAAYK,WAAW,EAAED;QAC9BE,KAAKN;QACLO,MAAMP,aAAaO;QACnBC,OAAOR,YAAYH,IAAI,CAACW,KAAK,IAAIR,YAAYH,IAAI;IACnD;IAEA,OAAOY,SAASX,IAAI,CAClB;QACEK;QACAO,SAASV,YAAYW,CAAC,CAAC;IACzB,GACA;QACEC,QAAQnB,WAAWoB,EAAE;IACvB;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../src/preferences/requestHandlers/update.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { update } from '../operations/update.js'\n\nexport const updateHandler: PayloadHandler = async (incomingReq) => {\n // We cannot import the addDataAndFileToRequest utility here from the 'next' package because of dependency issues\n // However that utility should be used where possible instead of manually appending the data\n let data\n\n try {\n data = await incomingReq.json()\n } catch (error) {\n data = {}\n }\n\n const reqWithData: PayloadRequest = incomingReq\n\n if (data) {\n reqWithData.data = data\n reqWithData.json = () => Promise.resolve(data)\n }\n\n const doc = await update({\n key: reqWithData.routeParams?.key as string,\n req: reqWithData,\n user: reqWithData?.user,\n value: reqWithData.data.value || reqWithData.data,\n })\n\n return Response.json(\n {\n doc,\n message: reqWithData.t('general:updatedSuccessfully'),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","update","updateHandler","incomingReq","data","json","error","reqWithData","Promise","resolve","doc","key","routeParams","req","user","value","Response","message","t","status","OK"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAKpC,SAASC,MAAM,QAAQ,0BAAyB;AAEhD,OAAO,MAAMC,gBAAgC,OAAOC;IAClD,iHAAiH;IACjH,4FAA4F;IAC5F,IAAIC;IAEJ,IAAI;QACFA,OAAO,MAAMD,YAAYE,IAAI;IAC/B,EAAE,OAAOC,OAAO;QACdF,OAAO,CAAC;IACV;IAEA,MAAMG,cAA8BJ;IAEpC,IAAIC,MAAM;QACRG,YAAYH,IAAI,GAAGA;QACnBG,YAAYF,IAAI,GAAG,IAAMG,QAAQC,OAAO,CAACL;IAC3C;IAEA,MAAMM,MAAM,MAAMT,OAAO;QACvBU,KAAKJ,YAAYK,WAAW,EAAED;QAC9BE,KAAKN;QACLO,MAAMP,aAAaO;QACnBC,OAAOR,YAAYH,IAAI,CAACW,KAAK,IAAIR,YAAYH,IAAI;IACnD;IAEA,OAAOY,SAASX,IAAI,CAClB;QACEK;QACAO,SAASV,YAAYW,CAAC,CAAC;IACzB,GACA;QACEC,QAAQnB,WAAWoB,EAAE;IACvB;AAEJ,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "3.0.0-beta.100",
3
+ "version": "3.0.0-beta.101",
4
4
  "description": "Node, React, Headless CMS and Application Framework built on Next.js",
5
5
  "keywords": [
6
6
  "admin panel",
@@ -96,7 +96,7 @@
96
96
  "ts-essentials": "7.0.3",
97
97
  "tsx": "4.17.0",
98
98
  "uuid": "10.0.0",
99
- "@payloadcms/translations": "3.0.0-beta.100"
99
+ "@payloadcms/translations": "3.0.0-beta.101"
100
100
  },
101
101
  "devDependencies": {
102
102
  "@hyrious/esbuild-plugin-commonjs": "^0.2.4",