payload 3.44.0 → 3.45.0-canary.1

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.
@@ -38,7 +38,7 @@ export type DocumentViewClientProps = {
38
38
  /**
39
39
  * @todo: This should be renamed to `DocumentSubViewType` (singular)
40
40
  */
41
- export type DocumentSubViewTypes = 'api' | 'default' | 'livePreview' | 'version' | 'versions';
41
+ export type DocumentSubViewTypes = 'api' | 'default' | 'version' | 'versions';
42
42
  export type DocumentTabServerPropsOnly = {
43
43
  readonly apiURL?: string;
44
44
  readonly collectionConfig?: SanitizedCollectionConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../src/admin/views/document.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAC3F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3D,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B,CAAA;AACD;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;OAGG;IACH,6BAA6B,CAAC,EAAE,OAAO,CAAA;CACxC,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,GAAG,E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AAO,CAAA;IACzB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,gBAAgB,CAAA;CACjC,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;IAClD,IAAI,EAAE,MAAM,CAAA;CACb,CAAC,CAAA;AAIF,MAAM,MAAM,iCAAiC,GAAG,EAAE,CAAA;AAClD,MAAM,MAAM,qCAAqC,GAAG,EAAE,GAAG,WAAW,CAAA;AACpE,MAAM,MAAM,iCAAiC,GAAG,iCAAiC,GAC/E,qCAAqC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/views/document.ts"],"sourcesContent":["import type { SanitizedPermissions } from '../../auth/types.js'\nimport type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { PayloadComponent, SanitizedConfig, ServerProps } from '../../config/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { Data, DocumentSlots, FormState } from '../types.js'\nimport type { InitPageResult, ViewTypes } from './index.js'\n\nexport type EditViewProps = {\n readonly collectionSlug?: string\n readonly globalSlug?: string\n}\n/**\n * Properties specific to the versions view\n */\nexport type RenderDocumentVersionsProperties = {\n /**\n * @default false\n */\n disableGutter?: boolean\n /**\n * Use createdAt cell that appends params to the url on version selection instead of redirecting user\n * @default false\n */\n useVersionDrawerCreatedAtCell?: boolean\n}\n\nexport type DocumentViewServerPropsOnly = {\n doc: Data\n hasPublishedDoc: boolean\n initPageResult: InitPageResult\n routeSegments: string[]\n versions?: RenderDocumentVersionsProperties\n} & ServerProps\n\nexport type DocumentViewServerProps = DocumentViewClientProps & DocumentViewServerPropsOnly\n\nexport type DocumentViewClientProps = {\n documentSubViewType: DocumentSubViewTypes\n formState: FormState\n viewType: ViewTypes\n} & DocumentSlots\n\n/**\n * @todo: This should be renamed to `DocumentSubViewType` (singular)\n */\nexport type DocumentSubViewTypes = 'api' | 'default' | 'livePreview' | 'version' | 'versions'\n\nexport type DocumentTabServerPropsOnly = {\n readonly apiURL?: string\n readonly collectionConfig?: SanitizedCollectionConfig\n readonly globalConfig?: SanitizedGlobalConfig\n readonly permissions: SanitizedPermissions\n} & ServerProps\n\nexport type DocumentTabClientProps = {\n path: string\n}\n\nexport type DocumentTabServerProps = DocumentTabClientProps & DocumentTabServerPropsOnly\n\nexport type DocumentTabCondition = (args: {\n collectionConfig: SanitizedCollectionConfig\n config: SanitizedConfig\n globalConfig: SanitizedGlobalConfig\n permissions: SanitizedPermissions\n}) => boolean\n\n// Everything is optional because we merge in the defaults\n// i.e. the config may override the `Default` view with a `label` but not an `href`\nexport type DocumentTabConfig = {\n readonly Component?: DocumentTabComponent\n readonly condition?: DocumentTabCondition\n readonly href?:\n | ((args: {\n apiURL: string\n collection: SanitizedCollectionConfig\n global: SanitizedGlobalConfig\n id?: string\n routes: SanitizedConfig['routes']\n }) => string)\n | string\n readonly isActive?: ((args: { href: string }) => boolean) | boolean\n readonly label?: ((args: { t: (key: string) => string }) => string) | string\n readonly newTab?: boolean\n /**\n * Sets the order to render the tab in the admin panel\n * Recommended to use increments of 100 (e.g. 0, 100, 200)\n */\n readonly order?: number\n readonly Pill?: PayloadComponent\n}\n\n/**\n * @todo: Remove this type as it's only used internally for the config (above)\n */\nexport type DocumentTabComponent = PayloadComponent<{\n path: string\n}>\n\n// BeforeDocumentControls\n\nexport type BeforeDocumentControlsClientProps = {}\nexport type BeforeDocumentControlsServerPropsOnly = {} & ServerProps\nexport type BeforeDocumentControlsServerProps = BeforeDocumentControlsClientProps &\n BeforeDocumentControlsServerPropsOnly\n"],"names":[],"mappings":"AAuGA,WACuC"}
1
+ {"version":3,"sources":["../../../src/admin/views/document.ts"],"sourcesContent":["import type { SanitizedPermissions } from '../../auth/types.js'\nimport type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { PayloadComponent, SanitizedConfig, ServerProps } from '../../config/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { Data, DocumentSlots, FormState } from '../types.js'\nimport type { InitPageResult, ViewTypes } from './index.js'\n\nexport type EditViewProps = {\n readonly collectionSlug?: string\n readonly globalSlug?: string\n}\n/**\n * Properties specific to the versions view\n */\nexport type RenderDocumentVersionsProperties = {\n /**\n * @default false\n */\n disableGutter?: boolean\n /**\n * Use createdAt cell that appends params to the url on version selection instead of redirecting user\n * @default false\n */\n useVersionDrawerCreatedAtCell?: boolean\n}\n\nexport type DocumentViewServerPropsOnly = {\n doc: Data\n hasPublishedDoc: boolean\n initPageResult: InitPageResult\n routeSegments: string[]\n versions?: RenderDocumentVersionsProperties\n} & ServerProps\n\nexport type DocumentViewServerProps = DocumentViewClientProps & DocumentViewServerPropsOnly\n\nexport type DocumentViewClientProps = {\n documentSubViewType: DocumentSubViewTypes\n formState: FormState\n viewType: ViewTypes\n} & DocumentSlots\n\n/**\n * @todo: This should be renamed to `DocumentSubViewType` (singular)\n */\nexport type DocumentSubViewTypes = 'api' | 'default' | 'version' | 'versions'\n\nexport type DocumentTabServerPropsOnly = {\n readonly apiURL?: string\n readonly collectionConfig?: SanitizedCollectionConfig\n readonly globalConfig?: SanitizedGlobalConfig\n readonly permissions: SanitizedPermissions\n} & ServerProps\n\nexport type DocumentTabClientProps = {\n path: string\n}\n\nexport type DocumentTabServerProps = DocumentTabClientProps & DocumentTabServerPropsOnly\n\nexport type DocumentTabCondition = (args: {\n collectionConfig: SanitizedCollectionConfig\n config: SanitizedConfig\n globalConfig: SanitizedGlobalConfig\n permissions: SanitizedPermissions\n}) => boolean\n\n// Everything is optional because we merge in the defaults\n// i.e. the config may override the `Default` view with a `label` but not an `href`\nexport type DocumentTabConfig = {\n readonly Component?: DocumentTabComponent\n readonly condition?: DocumentTabCondition\n readonly href?:\n | ((args: {\n apiURL: string\n collection: SanitizedCollectionConfig\n global: SanitizedGlobalConfig\n id?: string\n routes: SanitizedConfig['routes']\n }) => string)\n | string\n readonly isActive?: ((args: { href: string }) => boolean) | boolean\n readonly label?: ((args: { t: (key: string) => string }) => string) | string\n readonly newTab?: boolean\n /**\n * Sets the order to render the tab in the admin panel\n * Recommended to use increments of 100 (e.g. 0, 100, 200)\n */\n readonly order?: number\n readonly Pill?: PayloadComponent\n}\n\n/**\n * @todo: Remove this type as it's only used internally for the config (above)\n */\nexport type DocumentTabComponent = PayloadComponent<{\n path: string\n}>\n\n// BeforeDocumentControls\n\nexport type BeforeDocumentControlsClientProps = {}\nexport type BeforeDocumentControlsServerPropsOnly = {} & ServerProps\nexport type BeforeDocumentControlsServerProps = BeforeDocumentControlsClientProps &\n BeforeDocumentControlsServerPropsOnly\n"],"names":[],"mappings":"AAuGA,WACuC"}
@@ -1,4 +1,4 @@
1
- import type { AuthOperationsFromCollectionSlug, Collection, DataFromCollectionSlug, SanitizedCollectionConfig } from '../../collections/config/types.js';
1
+ import type { AuthOperationsFromCollectionSlug, Collection, DataFromCollectionSlug } from '../../collections/config/types.js';
2
2
  import type { CollectionSlug } from '../../index.js';
3
3
  import type { PayloadRequest } from '../../types/index.js';
4
4
  import type { User } from '../types.js';
@@ -16,12 +16,11 @@ export type Arguments<TSlug extends CollectionSlug> = {
16
16
  showHiddenFields?: boolean;
17
17
  };
18
18
  type CheckLoginPermissionArgs = {
19
- collection: SanitizedCollectionConfig;
20
19
  loggingInWithUsername?: boolean;
21
20
  req: PayloadRequest;
22
21
  user: any;
23
22
  };
24
- export declare const checkLoginPermission: ({ collection, loggingInWithUsername, req, user, }: CheckLoginPermissionArgs) => void;
23
+ export declare const checkLoginPermission: ({ loggingInWithUsername, req, user, }: CheckLoginPermissionArgs) => void;
25
24
  export declare const loginOperation: <TSlug extends CollectionSlug>(incomingArgs: Arguments<TSlug>) => Promise<{
26
25
  user: DataFromCollectionSlug<TSlug>;
27
26
  } & Result>;
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/login.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,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ACV,sBAAsB,EACvB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAsBvC,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,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,KAAK,wBAAwB,GAAG;IAC9B,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,GAAG,EAAE,cAAc,CAAA;IACnB,IAAI,EAAE,GAAG,CAAA;CACV,CAAA;AAED,eAAO,MAAM,oBAAoB,0CAI9B,wBAAwB,SAQ1B,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,CA6T1D,CAAA"}
@@ -13,15 +13,10 @@ import { removeExpiredSessions } from '../removeExpiredSessions.js';
13
13
  import { authenticateLocalStrategy } from '../strategies/local/authenticate.js';
14
14
  import { incrementLoginAttempts } from '../strategies/local/incrementLoginAttempts.js';
15
15
  import { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js';
16
- export const checkLoginPermission = ({ collection, loggingInWithUsername, req, user })=>{
16
+ export const checkLoginPermission = ({ loggingInWithUsername, req, user })=>{
17
17
  if (!user) {
18
18
  throw new AuthenticationError(req.t, Boolean(loggingInWithUsername));
19
19
  }
20
- if (collection.auth.verify && user._verified === false) {
21
- throw new UnverifiedEmail({
22
- t: req.t
23
- });
24
- }
25
20
  if (isUserLocked(new Date(user.lockUntil).getTime())) {
26
21
  throw new LockedAuth(req.t);
27
22
  }
@@ -153,7 +148,6 @@ export const loginOperation = async (incomingArgs)=>{
153
148
  where: whereConstraint
154
149
  });
155
150
  checkLoginPermission({
156
- collection: collectionConfig,
157
151
  loggingInWithUsername: Boolean(canLoginWithUsername && sanitizedUsername),
158
152
  req,
159
153
  user
@@ -177,6 +171,11 @@ export const loginOperation = async (incomingArgs)=>{
177
171
  }
178
172
  throw new AuthenticationError(req.t);
179
173
  }
174
+ if (collectionConfig.auth.verify && user._verified === false) {
175
+ throw new UnverifiedEmail({
176
+ t: req.t
177
+ });
178
+ }
180
179
  const fieldsToSignArgs = {
181
180
  collectionConfig,
182
181
  email: sanitizedEmail,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/operations/login.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid'\n\nimport type {\n AuthOperationsFromCollectionSlug,\n Collection,\n DataFromCollectionSlug,\n SanitizedCollectionConfig,\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 {\n AuthenticationError,\n LockedAuth,\n UnverifiedEmail,\n ValidationError,\n} from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { Forbidden } from '../../index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { getLoginOptions } from '../getLoginOptions.js'\nimport { isUserLocked } from '../isUserLocked.js'\nimport { jwtSign } from '../jwt.js'\nimport { removeExpiredSessions } from '../removeExpiredSessions.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\ntype CheckLoginPermissionArgs = {\n collection: SanitizedCollectionConfig\n loggingInWithUsername?: boolean\n req: PayloadRequest\n user: any\n}\n\nexport const checkLoginPermission = ({\n collection,\n loggingInWithUsername,\n req,\n user,\n}: CheckLoginPermissionArgs) => {\n if (!user) {\n throw new AuthenticationError(req.t, Boolean(loggingInWithUsername))\n }\n\n if (collection.auth.verify && user._verified === false) {\n throw new UnverifiedEmail({ t: req.t })\n }\n\n if (isUserLocked(new Date(user.lockUntil).getTime())) {\n throw new LockedAuth(req.t)\n }\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 if (args.collection.config.auth.disableLocalStrategy) {\n throw new Forbidden(args.req.t)\n }\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'login',\n req: args.req,\n })) || args\n }\n }\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 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 { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n // cannot login with email, did not provide username\n if (!canLoginWithEmail && !sanitizedUsername) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ message: req.i18n.t('validation:required'), path: 'username' }],\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: [{ message: req.i18n.t('validation:required'), path: 'email' }],\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 { message: req.i18n.t('validation:required'), path: 'email' },\n { message: req.i18n.t('validation:required'), path: 'username' },\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: [{ message: req.i18n.t('validation:required'), path: 'password' }],\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 let user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n checkLoginPermission({\n collection: collectionConfig,\n loggingInWithUsername: Boolean(canLoginWithUsername && sanitizedUsername),\n req,\n user,\n })\n\n user.collection = collectionConfig.slug\n user._strategy = 'local-jwt'\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 const fieldsToSignArgs: Parameters<typeof getFieldsToSign>[0] = {\n collectionConfig,\n email: sanitizedEmail!,\n user,\n }\n\n if (collectionConfig.auth.useSessions) {\n // Add session to user\n const newSessionID = uuid()\n const now = new Date()\n const tokenExpInMs = collectionConfig.auth.tokenExpiration * 1000\n const expiresAt = new Date(now.getTime() + tokenExpInMs)\n\n const session = { id: newSessionID, createdAt: now, expiresAt }\n\n if (!user.sessions?.length) {\n user.sessions = [session]\n } else {\n user.sessions = removeExpiredSessions(user.sessions)\n user.sessions.push(session)\n }\n\n await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n returning: false,\n })\n\n fieldsToSignArgs.sid = newSessionID\n }\n\n const fieldsToSign = getFieldsToSign(fieldsToSignArgs)\n\n if (maxLoginAttemptsEnabled) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeLogin?.length) {\n for (const hook of collectionConfig.hooks.beforeLogin) {\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user,\n })) || user\n }\n }\n\n const { exp, token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = user\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterLogin?.length) {\n for (const hook of collectionConfig.hooks.afterLogin) {\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 }\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n user = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: user,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n draft: undefined,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n req,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n user =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n doc: user,\n req,\n })) || user\n }\n }\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n 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":["v4","uuid","buildAfterOperation","AuthenticationError","LockedAuth","UnverifiedEmail","ValidationError","afterRead","Forbidden","killTransaction","sanitizeInternalFields","getFieldsToSign","getLoginOptions","isUserLocked","jwtSign","removeExpiredSessions","authenticateLocalStrategy","incrementLoginAttempts","resetLoginAttempts","checkLoginPermission","collection","loggingInWithUsername","req","user","t","Boolean","auth","verify","_verified","Date","lockUntil","getTime","loginOperation","incomingArgs","args","config","disableLocalStrategy","hooks","beforeOperation","length","hook","context","operation","collectionConfig","data","depth","overrideAccess","fallbackLocale","locale","payload","secret","showHiddenFields","email","unsanitizedEmail","password","loginWithUsername","sanitizedEmail","toLowerCase","trim","sanitizedUsername","username","canLoginWithEmail","canLoginWithUsername","slug","errors","message","i18n","path","whereConstraint","emailConstraint","equals","usernameConstraint","or","db","findOne","where","_strategy","authResult","doc","maxLoginAttemptsEnabled","maxLoginAttempts","fieldsToSignArgs","useSessions","newSessionID","now","tokenExpInMs","tokenExpiration","expiresAt","session","id","createdAt","sessions","push","updateOne","returning","sid","fieldsToSign","beforeLogin","exp","token","afterLogin","draft","undefined","global","result","error"],"mappings":"AAAA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAYjC,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SACEC,mBAAmB,EACnBC,UAAU,EACVC,eAAe,EACfC,eAAe,QACV,wBAAuB;AAC9B,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,YAAY,QAAQ,qBAAoB;AACjD,SAASC,OAAO,QAAQ,YAAW;AACnC,SAASC,qBAAqB,QAAQ,8BAA6B;AACnE,SAASC,yBAAyB,QAAQ,sCAAqC;AAC/E,SAASC,sBAAsB,QAAQ,gDAA+C;AACtF,SAASC,kBAAkB,QAAQ,4CAA2C;AAwB9E,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,UAAU,EACVC,qBAAqB,EACrBC,GAAG,EACHC,IAAI,EACqB;IACzB,IAAI,CAACA,MAAM;QACT,MAAM,IAAIpB,oBAAoBmB,IAAIE,CAAC,EAAEC,QAAQJ;IAC/C;IAEA,IAAID,WAAWM,IAAI,CAACC,MAAM,IAAIJ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ACxC,8BAA8B;QAC9B,wCAAwC;QAExCiF,SAAS,MAAMtG,oBAAoB;YACjCgC;YACAd,YAAYc,KAAKd,UAAU,EAAEe;YAC7BO,WAAW;YACX8D;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,MAAMhG,gBAAgByB,KAAKZ,GAAG;QAC9B,MAAMmF;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/operations/login.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid'\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 {\n AuthenticationError,\n LockedAuth,\n UnverifiedEmail,\n ValidationError,\n} from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { Forbidden } from '../../index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { getLoginOptions } from '../getLoginOptions.js'\nimport { isUserLocked } from '../isUserLocked.js'\nimport { jwtSign } from '../jwt.js'\nimport { removeExpiredSessions } from '../removeExpiredSessions.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\ntype CheckLoginPermissionArgs = {\n loggingInWithUsername?: boolean\n req: PayloadRequest\n user: any\n}\n\nexport const checkLoginPermission = ({\n loggingInWithUsername,\n req,\n user,\n}: CheckLoginPermissionArgs) => {\n if (!user) {\n throw new AuthenticationError(req.t, Boolean(loggingInWithUsername))\n }\n\n if (isUserLocked(new Date(user.lockUntil).getTime())) {\n throw new LockedAuth(req.t)\n }\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 if (args.collection.config.auth.disableLocalStrategy) {\n throw new Forbidden(args.req.t)\n }\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'login',\n req: args.req,\n })) || args\n }\n }\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 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 { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n // cannot login with email, did not provide username\n if (!canLoginWithEmail && !sanitizedUsername) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ message: req.i18n.t('validation:required'), path: 'username' }],\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: [{ message: req.i18n.t('validation:required'), path: 'email' }],\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 { message: req.i18n.t('validation:required'), path: 'email' },\n { message: req.i18n.t('validation:required'), path: 'username' },\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: [{ message: req.i18n.t('validation:required'), path: 'password' }],\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 let user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n checkLoginPermission({\n loggingInWithUsername: Boolean(canLoginWithUsername && sanitizedUsername),\n req,\n user,\n })\n\n user.collection = collectionConfig.slug\n user._strategy = 'local-jwt'\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 (collectionConfig.auth.verify && user._verified === false) {\n throw new UnverifiedEmail({ t: req.t })\n }\n\n const fieldsToSignArgs: Parameters<typeof getFieldsToSign>[0] = {\n collectionConfig,\n email: sanitizedEmail!,\n user,\n }\n\n if (collectionConfig.auth.useSessions) {\n // Add session to user\n const newSessionID = uuid()\n const now = new Date()\n const tokenExpInMs = collectionConfig.auth.tokenExpiration * 1000\n const expiresAt = new Date(now.getTime() + tokenExpInMs)\n\n const session = { id: newSessionID, createdAt: now, expiresAt }\n\n if (!user.sessions?.length) {\n user.sessions = [session]\n } else {\n user.sessions = removeExpiredSessions(user.sessions)\n user.sessions.push(session)\n }\n\n await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n returning: false,\n })\n\n fieldsToSignArgs.sid = newSessionID\n }\n\n const fieldsToSign = getFieldsToSign(fieldsToSignArgs)\n\n if (maxLoginAttemptsEnabled) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeLogin?.length) {\n for (const hook of collectionConfig.hooks.beforeLogin) {\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user,\n })) || user\n }\n }\n\n const { exp, token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = user\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterLogin?.length) {\n for (const hook of collectionConfig.hooks.afterLogin) {\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 }\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n user = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: user,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n draft: undefined,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n req,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n user =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n doc: user,\n req,\n })) || user\n }\n }\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n 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":["v4","uuid","buildAfterOperation","AuthenticationError","LockedAuth","UnverifiedEmail","ValidationError","afterRead","Forbidden","killTransaction","sanitizeInternalFields","getFieldsToSign","getLoginOptions","isUserLocked","jwtSign","removeExpiredSessions","authenticateLocalStrategy","incrementLoginAttempts","resetLoginAttempts","checkLoginPermission","loggingInWithUsername","req","user","t","Boolean","Date","lockUntil","getTime","loginOperation","incomingArgs","args","collection","config","auth","disableLocalStrategy","hooks","beforeOperation","length","hook","context","operation","collectionConfig","data","depth","overrideAccess","fallbackLocale","locale","payload","secret","showHiddenFields","email","unsanitizedEmail","password","loginWithUsername","sanitizedEmail","toLowerCase","trim","sanitizedUsername","username","canLoginWithEmail","canLoginWithUsername","slug","errors","message","i18n","path","whereConstraint","emailConstraint","equals","usernameConstraint","or","db","findOne","where","_strategy","authResult","doc","maxLoginAttemptsEnabled","maxLoginAttempts","verify","_verified","fieldsToSignArgs","useSessions","newSessionID","now","tokenExpInMs","tokenExpiration","expiresAt","session","id","createdAt","sessions","push","updateOne","returning","sid","fieldsToSign","beforeLogin","exp","token","afterLogin","draft","undefined","global","result","error"],"mappings":"AAAA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAWj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AAKT,GAAG;oBACb8E;oBACA7E;gBACF,MAAOA;YACX;QACF;QAEA,wCAAwC;QACxC,qBAAqB;QACrB,wCAAwC;QAExCA,OAAO,MAAMf,UAAU;YACrBwB,YAAYU;YACZF,SAASlB,IAAIkB,OAAO;YACpBI,OAAOA;YACPiC,KAAKtD;YACL,oFAAoF;YACpF+E,OAAOC;YACPzD,gBAAgBA;YAChB0D,QAAQ;YACRzD,QAAQA;YACRF,gBAAgBA;YAChBvB;YACA4B,kBAAkBA;QACpB;QAEA,wCAAwC;QACxC,yBAAyB;QACzB,wCAAwC;QAExC,IAAIR,iBAAiBN,KAAK,EAAE5B,WAAW8B,QAAQ;YAC7C,KAAK,MAAMC,QAAQG,iBAAiBN,KAAK,CAAC5B,SAAS,CAAE;gBACnDe,OACE,AAAC,MAAMgB,KAAK;oBACVP,YAAYD,KAAKC,UAAU,EAAEC;oBAC7BO,SAASlB,IAAIkB,OAAO;oBACpBqC,KAAKtD;oBACLD;gBACF,MAAOC;YACX;QACF;QAEA,IAAIkF,SAA2D;YAC7DN;YACAC;YACA7E;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCkF,SAAS,MAAMtG,oBAAoB;YACjC4B;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BQ,WAAW;YACXgE;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,MAAMhG,gBAAgBqB,KAAKT,GAAG;QAC9B,MAAMoF;IACR;AACF,EAAC"}
@@ -29,6 +29,7 @@ export type ColumnPreference = {
29
29
  };
30
30
  export type CollectionPreferences = {
31
31
  columns?: ColumnPreference[];
32
+ editViewType?: 'default' | 'live-preview';
32
33
  limit?: number;
33
34
  preset?: DefaultDocumentIDType;
34
35
  sort?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/preferences/types.ts"],"names":[],"mappings":"AAAA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ultDocumentIDType } from '../index.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nexport type PreferenceRequest = {\n key: string\n overrideAccess?: boolean\n req: PayloadRequest\n user: PayloadRequest['user']\n}\n\nexport type PreferenceUpdateRequest = { value: unknown } & PreferenceRequest\n\nexport type CollapsedPreferences = string[]\n\nexport type TabsPreferences = Array<{\n [path: string]: number\n}>\n\nexport type InsideFieldsPreferences = {\n collapsed: CollapsedPreferences\n tabIndex: number\n}\n\nexport type FieldsPreferences = {\n [key: string]: InsideFieldsPreferences\n}\n\nexport type DocumentPreferences = {\n fields: FieldsPreferences\n}\n\nexport type ColumnPreference = {\n accessor: string\n active: boolean\n}\n\nexport type CollectionPreferences = {\n columns?: ColumnPreference[]\n limit?: number\n preset?: DefaultDocumentIDType\n sort?: string\n}\n"],"names":[],"mappings":"AAoCA,WAKC"}
1
+ {"version":3,"sources":["../../src/preferences/types.ts"],"sourcesContent":["import type { DefaultDocumentIDType } from '../index.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nexport type PreferenceRequest = {\n key: string\n overrideAccess?: boolean\n req: PayloadRequest\n user: PayloadRequest['user']\n}\n\nexport type PreferenceUpdateRequest = { value: unknown } & PreferenceRequest\n\nexport type CollapsedPreferences = string[]\n\nexport type TabsPreferences = Array<{\n [path: string]: number\n}>\n\nexport type InsideFieldsPreferences = {\n collapsed: CollapsedPreferences\n tabIndex: number\n}\n\nexport type FieldsPreferences = {\n [key: string]: InsideFieldsPreferences\n}\n\nexport type DocumentPreferences = {\n fields: FieldsPreferences\n}\n\nexport type ColumnPreference = {\n accessor: string\n active: boolean\n}\n\nexport type CollectionPreferences = {\n columns?: ColumnPreference[]\n editViewType?: 'default' | 'live-preview'\n limit?: number\n preset?: DefaultDocumentIDType\n sort?: string\n}\n"],"names":[],"mappings":"AAoCA,WAMC"}
@@ -1,6 +1,6 @@
1
1
  import type { ClientConfig } from '../config/client.js';
2
2
  import type { ClientField } from '../fields/config/client.js';
3
- import { type FieldTypes } from '../fields/config/types.js';
3
+ import type { Field, FieldTypes } from '../fields/config/types.js';
4
4
  export type FieldSchemaJSON = {
5
5
  blocks?: FieldSchemaJSON;
6
6
  fields?: FieldSchemaJSON;
@@ -10,5 +10,5 @@ export type FieldSchemaJSON = {
10
10
  slug?: string;
11
11
  type: FieldTypes;
12
12
  }[];
13
- export declare const fieldSchemaToJSON: (fields: ClientField[], config: ClientConfig) => FieldSchemaJSON;
13
+ export declare const fieldSchemaToJSON: (fields: (ClientField | Field)[], config: ClientConfig) => FieldSchemaJSON;
14
14
  //# sourceMappingURL=fieldSchemaToJSON.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fieldSchemaToJSON.d.ts","sourceRoot":"","sources":["../../src/utilities/fieldSchemaToJSON.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAE7E,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,UAAU,CAAA;CACjB,EAAE,CAAA;AAEH,eAAO,MAAM,iBAAiB,WAAY,WAAW,EAAE,UAAU,YAAY,KAAG,eA6G/E,CAAA"}
1
+ {"version":3,"file":"fieldSchemaToJSON.d.ts","sourceRoot":"","sources":["../../src/utilities/fieldSchemaToJSON.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAIlE,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,UAAU,CAAA;CACjB,EAAE,CAAA;AAEH,eAAO,MAAM,iBAAiB,WACpB,CAAC,WAAW,GAAG,KAAK,CAAC,EAAE,UACvB,YAAY,KACnB,eA6GF,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/fieldSchemaToJSON.ts"],"sourcesContent":["import type { ClientConfig } from '../config/client.js'\nimport type { ClientField } from '../fields/config/client.js'\n\nimport { fieldAffectsData, type FieldTypes } from '../fields/config/types.js'\n\nexport type FieldSchemaJSON = {\n blocks?: FieldSchemaJSON // TODO: conditionally add based on `type`\n fields?: FieldSchemaJSON // TODO: conditionally add based on `type`\n hasMany?: boolean // TODO: conditionally add based on `type`\n name: string\n relationTo?: string // TODO: conditionally add based on `type`\n slug?: string // TODO: conditionally add based on `type`\n type: FieldTypes\n}[]\n\nexport const fieldSchemaToJSON = (fields: ClientField[], config: ClientConfig): FieldSchemaJSON => {\n return fields.reduce((acc, field) => {\n let result = acc\n\n switch (field.type) {\n case 'array':\n acc.push({\n name: field.name,\n type: field.type,\n fields: fieldSchemaToJSON(\n [\n ...field.fields,\n {\n name: 'id',\n type: 'text',\n },\n ],\n config,\n ),\n })\n\n break\n\n case 'blocks':\n acc.push({\n name: field.name,\n type: field.type,\n blocks: (field.blockReferences ?? field.blocks).reduce((acc, _block) => {\n const block = typeof _block === 'string' ? config.blocksMap[_block]! : _block\n ;(acc as any)[block.slug] = {\n fields: fieldSchemaToJSON(\n [\n ...block.fields,\n {\n name: 'id',\n type: 'text',\n },\n ],\n config,\n ),\n }\n\n return acc\n }, {} as FieldSchemaJSON),\n })\n\n break\n\n case 'collapsible': // eslint-disable no-fallthrough\n case 'row':\n result = result.concat(fieldSchemaToJSON(field.fields, config))\n break\n\n case 'group':\n if (fieldAffectsData(field)) {\n acc.push({\n name: field.name,\n type: field.type,\n fields: fieldSchemaToJSON(field.fields, config),\n })\n } else {\n result = result.concat(fieldSchemaToJSON(field.fields, config))\n }\n\n break\n\n case 'relationship': // eslint-disable no-fallthrough\n case 'upload':\n acc.push({\n name: field.name,\n type: field.type,\n hasMany: 'hasMany' in field ? Boolean(field.hasMany) : false, // TODO: type this\n relationTo: field.relationTo as string,\n })\n\n break\n\n case 'tabs': {\n let tabFields: FieldSchemaJSON = []\n\n field.tabs.forEach((tab) => {\n if ('name' in tab) {\n tabFields.push({\n name: tab.name,\n type: field.type,\n fields: fieldSchemaToJSON(tab.fields, config),\n })\n return\n }\n\n tabFields = tabFields.concat(fieldSchemaToJSON(tab.fields, config))\n })\n\n result = result.concat(tabFields)\n\n break\n }\n\n default:\n if ('name' in field) {\n acc.push({\n name: field.name,\n type: field.type,\n })\n }\n }\n\n return result\n }, [] as FieldSchemaJSON)\n}\n"],"names":["fieldAffectsData","fieldSchemaToJSON","fields","config","reduce","acc","field","result","type","push","name","blocks","blockReferences","_block","block","blocksMap","slug","concat","hasMany","Boolean","relationTo","tabFields","tabs","forEach","tab"],"mappings":"AAGA,SAASA,gBAAgB,QAAyB,4BAA2B;AAY7E,OAAO,MAAMC,oBAAoB,CAACC,QAAuBC;IACvD,OAAOD,OAAOE,MAAM,CAAC,CAACC,KAAKC;QACzB,IAAIC,SAASF;QAEb,OAAQC,MAAME,IAAI;YAChB,KAAK;gBACHH,IAAII,IAAI,CAAC;oBACPC,MAAMJ,MAAMI,IAAI;oBAChBF,MAAMF,MAAME,IAAI;oBAChBN,QAAQD,kBACN;2BACKK,MAAMJ,MAAM;wBACf;4BACEQ,MA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AI,CAAC;gCACbC,MAAMc,IAAId,IAAI;gCACdF,MAAMF,MAAME,IAAI;gCAChBN,QAAQD,kBAAkBuB,IAAItB,MAAM,EAAEC;4BACxC;4BACA;wBACF;wBAEAkB,YAAYA,UAAUJ,MAAM,CAAChB,kBAAkBuB,IAAItB,MAAM,EAAEC;oBAC7D;oBAEAI,SAASA,OAAOU,MAAM,CAACI;oBAEvB;gBACF;YAEA;gBACE,IAAI,UAAUf,OAAO;oBACnBD,IAAII,IAAI,CAAC;wBACPC,MAAMJ,MAAMI,IAAI;wBAChBF,MAAMF,MAAME,IAAI;oBAClB;gBACF;QACJ;QAEA,OAAOD;IACT,GAAG,EAAE;AACP,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/fieldSchemaToJSON.ts"],"sourcesContent":["import type { ClientConfig } from '../config/client.js'\nimport type { ClientField } from '../fields/config/client.js'\nimport type { Field, FieldTypes } from '../fields/config/types.js'\n\nimport { fieldAffectsData } from '../fields/config/types.js'\n\nexport type FieldSchemaJSON = {\n blocks?: FieldSchemaJSON // TODO: conditionally add based on `type`\n fields?: FieldSchemaJSON // TODO: conditionally add based on `type`\n hasMany?: boolean // TODO: conditionally add based on `type`\n name: string\n relationTo?: string // TODO: conditionally add based on `type`\n slug?: string // TODO: conditionally add based on `type`\n type: FieldTypes\n}[]\n\nexport const fieldSchemaToJSON = (\n fields: (ClientField | Field)[],\n config: ClientConfig,\n): FieldSchemaJSON => {\n return fields.reduce((acc, field) => {\n let result = acc\n\n switch (field.type) {\n case 'array':\n acc.push({\n name: field.name,\n type: field.type,\n fields: fieldSchemaToJSON(\n [\n ...field.fields,\n {\n name: 'id',\n type: 'text',\n },\n ],\n config,\n ),\n })\n\n break\n\n case 'blocks':\n acc.push({\n name: field.name,\n type: field.type,\n blocks: (field.blockReferences ?? field.blocks).reduce((acc, _block) => {\n const block = typeof _block === 'string' ? config.blocksMap[_block]! : _block\n ;(acc as any)[block.slug] = {\n fields: fieldSchemaToJSON(\n [\n ...block.fields,\n {\n name: 'id',\n type: 'text',\n },\n ],\n config,\n ),\n }\n\n return acc\n }, {} as FieldSchemaJSON),\n })\n\n break\n\n case 'collapsible': // eslint-disable no-fallthrough\n case 'row':\n result = result.concat(fieldSchemaToJSON(field.fields, config))\n break\n\n case 'group':\n if (fieldAffectsData(field)) {\n acc.push({\n name: field.name,\n type: field.type,\n fields: fieldSchemaToJSON(field.fields, config),\n })\n } else {\n result = result.concat(fieldSchemaToJSON(field.fields, config))\n }\n\n break\n\n case 'relationship': // eslint-disable no-fallthrough\n case 'upload':\n acc.push({\n name: field.name,\n type: field.type,\n hasMany: 'hasMany' in field ? Boolean(field.hasMany) : false, // TODO: type this\n relationTo: field.relationTo as string,\n })\n\n break\n\n case 'tabs': {\n let tabFields: FieldSchemaJSON = []\n\n field.tabs.forEach((tab) => {\n if ('name' in tab) {\n tabFields.push({\n name: tab.name,\n type: field.type,\n fields: fieldSchemaToJSON(tab.fields, config),\n })\n return\n }\n\n tabFields = tabFields.concat(fieldSchemaToJSON(tab.fields, config))\n })\n\n result = result.concat(tabFields)\n\n break\n }\n\n default:\n if ('name' in field) {\n acc.push({\n name: field.name,\n type: field.type,\n })\n }\n }\n\n return result\n }, [] as FieldSchemaJSON)\n}\n"],"names":["fieldAffectsData","fieldSchemaToJSON","fields","config","reduce","acc","field","result","type","push","name","blocks","blockReferences","_block","block","blocksMap","slug","concat","hasMany","Boolean","relationTo","tabFields","tabs","forEach","tab"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,4BAA2B;AAY5D,OAAO,MAAMC,oBAAoB,CAC/BC,QACAC;IAEA,OAAOD,OAAOE,MAAM,CAAC,CAACC,KAAKC;QACzB,IAAIC,SAASF;QAEb,OAAQC,MAAME,IAAI;YAChB,KAAK;gBACHH,IAAII,IAAI,CAAC;oBACPC,MAAMJ,MAAMI,IAAI;oBAChBF,MAAMF,MAAME,IAAI;oBAChBN,QAAQD,kBACN;2BACKK,MAAMJ,MAAM;wBACf;4BACEQ,MAAM;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CAAC;gCACbC,MAAMc,IAAId,IAAI;gCACdF,MAAMF,MAAME,IAAI;gCAChBN,QAAQD,kBAAkBuB,IAAItB,MAAM,EAAEC;4BACxC;4BACA;wBACF;wBAEAkB,YAAYA,UAAUJ,MAAM,CAAChB,kBAAkBuB,IAAItB,MAAM,EAAEC;oBAC7D;oBAEAI,SAASA,OAAOU,MAAM,CAACI;oBAEvB;gBACF;YAEA;gBACE,IAAI,UAAUf,OAAO;oBACnBD,IAAII,IAAI,CAAC;wBACPC,MAAMJ,MAAMI,IAAI;wBAChBF,MAAMF,MAAME,IAAI;oBAClB;gBACF;QACJ;QAEA,OAAOD;IACT,GAAG,EAAE;AACP,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "3.44.0",
3
+ "version": "3.45.0-canary.1",
4
4
  "description": "Node, React, Headless CMS and Application Framework built on Next.js",
5
5
  "keywords": [
6
6
  "admin panel",
@@ -101,7 +101,7 @@
101
101
  "undici": "7.10.0",
102
102
  "uuid": "10.0.0",
103
103
  "ws": "^8.16.0",
104
- "@payloadcms/translations": "3.44.0"
104
+ "@payloadcms/translations": "3.45.0-canary.1"
105
105
  },
106
106
  "devDependencies": {
107
107
  "@hyrious/esbuild-plugin-commonjs": "0.2.6",