payload 3.0.0-beta.31 → 3.0.0-beta.33

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 (68) hide show
  1. package/dist/admin/RichText.d.ts +3 -3
  2. package/dist/admin/RichText.d.ts.map +1 -1
  3. package/dist/admin/RichText.js.map +1 -1
  4. package/dist/admin/elements/WithServerSideProps.d.ts +6 -3
  5. package/dist/admin/elements/WithServerSideProps.d.ts.map +1 -1
  6. package/dist/admin/elements/WithServerSideProps.js.map +1 -1
  7. package/dist/admin/types.d.ts +1 -1
  8. package/dist/admin/types.d.ts.map +1 -1
  9. package/dist/admin/types.js.map +1 -1
  10. package/dist/auth/types.d.ts +1 -1
  11. package/dist/auth/types.d.ts.map +1 -1
  12. package/dist/auth/types.js.map +1 -1
  13. package/dist/bin/loader/ignores.d.ts +2 -0
  14. package/dist/bin/loader/ignores.d.ts.map +1 -0
  15. package/dist/bin/loader/ignores.js +5 -0
  16. package/dist/bin/loader/ignores.js.map +1 -0
  17. package/dist/bin/loader/index.d.ts.map +1 -1
  18. package/dist/bin/loader/index.js +10 -6
  19. package/dist/bin/loader/index.js.map +1 -1
  20. package/dist/collections/config/client.d.ts +21 -0
  21. package/dist/collections/config/client.d.ts.map +1 -1
  22. package/dist/collections/config/schema.d.ts.map +1 -1
  23. package/dist/collections/config/schema.js +5 -1
  24. package/dist/collections/config/schema.js.map +1 -1
  25. package/dist/collections/config/types.d.ts +5 -1
  26. package/dist/collections/config/types.d.ts.map +1 -1
  27. package/dist/collections/config/types.js.map +1 -1
  28. package/dist/config/defaults.d.ts.map +1 -1
  29. package/dist/config/defaults.js +10 -2
  30. package/dist/config/defaults.js.map +1 -1
  31. package/dist/config/schema.d.ts.map +1 -1
  32. package/dist/config/schema.js +14 -4
  33. package/dist/config/schema.js.map +1 -1
  34. package/dist/config/shared/openGraphSchema.d.ts +3 -0
  35. package/dist/config/shared/openGraphSchema.d.ts.map +1 -0
  36. package/dist/config/shared/openGraphSchema.js +16 -0
  37. package/dist/config/shared/openGraphSchema.js.map +1 -0
  38. package/dist/config/types.d.ts +105 -35
  39. package/dist/config/types.d.ts.map +1 -1
  40. package/dist/config/types.js +7 -1
  41. package/dist/config/types.js.map +1 -1
  42. package/dist/exports/types.d.ts.map +1 -1
  43. package/dist/exports/types.js.map +1 -1
  44. package/dist/fields/config/client.d.ts +78 -78
  45. package/dist/fields/config/types.d.ts +24 -24
  46. package/dist/fields/config/types.d.ts.map +1 -1
  47. package/dist/fields/config/types.js.map +1 -1
  48. package/dist/globals/config/schema.d.ts.map +1 -1
  49. package/dist/globals/config/schema.js +5 -0
  50. package/dist/globals/config/schema.js.map +1 -1
  51. package/dist/globals/config/types.d.ts +5 -1
  52. package/dist/globals/config/types.d.ts.map +1 -1
  53. package/dist/globals/config/types.js.map +1 -1
  54. package/dist/index.d.ts +2 -4
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js.map +1 -1
  57. package/dist/types/index.d.ts +5 -5
  58. package/dist/types/index.d.ts.map +1 -1
  59. package/dist/types/index.js.map +1 -1
  60. package/dist/uploads/getExternalFile.js +1 -1
  61. package/dist/uploads/getExternalFile.js.map +1 -1
  62. package/dist/uploads/types.d.ts +0 -3
  63. package/dist/uploads/types.d.ts.map +1 -1
  64. package/dist/uploads/types.js.map +1 -1
  65. package/dist/utilities/isReactComponent.d.ts.map +1 -1
  66. package/dist/utilities/isReactComponent.js +23 -4
  67. package/dist/utilities/isReactComponent.js.map +1 -1
  68. package/package.json +3 -7
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ExecutionResult, GraphQLSchema, ValidationRule } from 'graphql'\nimport type { OperationArgs, Request as graphQLRequest } from 'graphql-http'\nimport type pino from 'pino'\n\nimport crypto from 'crypto'\n\nimport type { AuthArgs } from './auth/operations/auth.js'\nimport type { Result as ForgotPasswordResult } from './auth/operations/forgotPassword.js'\nimport type { Options as ForgotPasswordOptions } from './auth/operations/local/forgotPassword.js'\nimport type { Options as LoginOptions } from './auth/operations/local/login.js'\nimport type { Options as ResetPasswordOptions } from './auth/operations/local/resetPassword.js'\nimport type { Options as UnlockOptions } from './auth/operations/local/unlock.js'\nimport type { Options as VerifyEmailOptions } from './auth/operations/local/verifyEmail.js'\nimport type { Result as LoginResult } from './auth/operations/login.js'\nimport type { Result as ResetPasswordResult } from './auth/operations/resetPassword.js'\nimport type { AuthStrategy } from './auth/types.js'\nimport type { BulkOperationResult, Collection, TypeWithID } from './collections/config/types.js'\nimport type { Options as CountOptions } from './collections/operations/local/count.js'\nimport type { Options as CreateOptions } from './collections/operations/local/create.js'\nimport type {\n ByIDOptions as DeleteByIDOptions,\n ManyOptions as DeleteManyOptions,\n Options as DeleteOptions,\n} from './collections/operations/local/delete.js'\nimport type { Options as DuplicateOptions } from './collections/operations/local/duplicate.js'\nimport type { Options as FindOptions } from './collections/operations/local/find.js'\nimport type { Options as FindByIDOptions } from './collections/operations/local/findByID.js'\nimport type { Options as FindVersionByIDOptions } from './collections/operations/local/findVersionByID.js'\nimport type { Options as FindVersionsOptions } from './collections/operations/local/findVersions.js'\nimport type { Options as RestoreVersionOptions } from './collections/operations/local/restoreVersion.js'\nimport type {\n ByIDOptions as UpdateByIDOptions,\n ManyOptions as UpdateManyOptions,\n Options as UpdateOptions,\n} from './collections/operations/local/update.js'\nimport type { InitOptions, SanitizedConfig } from './config/types.js'\nimport type { BaseDatabaseAdapter, PaginatedDocs } from './database/types.js'\nimport type { InitializedEmailAdapter } from './email/types.js'\nimport type { TypeWithID as GlobalTypeWithID, Globals } from './globals/config/types.js'\nimport type { Options as FindGlobalOptions } from './globals/operations/local/findOne.js'\nimport type { Options as FindGlobalVersionByIDOptions } from './globals/operations/local/findVersionByID.js'\nimport type { Options as FindGlobalVersionsOptions } from './globals/operations/local/findVersions.js'\nimport type { Options as RestoreGlobalVersionOptions } from './globals/operations/local/restoreVersion.js'\nimport type { Options as UpdateGlobalOptions } from './globals/operations/local/update.js'\nimport type { TypeWithVersion } from './versions/types.js'\n\nimport { decrypt, encrypt } from './auth/crypto.js'\nimport { APIKeyAuthentication } from './auth/strategies/apiKey.js'\nimport { JWTAuthentication } from './auth/strategies/jwt.js'\nimport localOperations from './collections/operations/local/index.js'\nimport { validateSchema } from './config/validate.js'\nimport { consoleEmailAdapter } from './email/consoleEmailAdapter.js'\nimport { fieldAffectsData } from './fields/config/types.js'\nimport localGlobalOperations from './globals/operations/local/index.js'\nimport flattenFields from './utilities/flattenTopLevelFields.js'\nimport Logger from './utilities/logger.js'\nimport { serverInit as serverInitTelemetry } from './utilities/telemetry/events/serverInit.js'\n\n/**\n * @description Payload\n */\nexport class BasePayload<TGeneratedTypes extends GeneratedTypes> {\n /**\n * @description Authorization and Authentication using headers and cookies to run auth user strategies\n * @returns cookies: Map<string, string>\n * @returns permissions: Permissions\n * @returns user: User\n */\n auth = async (options: AuthArgs) => {\n const { auth } = localOperations.auth\n return auth(this, options)\n }\n\n authStrategies: AuthStrategy[]\n\n collections: {\n [slug: number | string | symbol]: Collection\n } = {}\n\n config: SanitizedConfig\n\n /**\n * @description Performs count operation\n * @param options\n * @returns count of documents satisfying query\n */\n count = async <T extends keyof TGeneratedTypes['collections']>(\n options: CountOptions<T>,\n ): Promise<{ totalDocs: number }> => {\n const { count } = localOperations\n return count(this, options)\n }\n\n /**\n * @description Performs create operation\n * @param options\n * @returns created document\n */\n create = async <T extends keyof TGeneratedTypes['collections']>(\n options: CreateOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]> => {\n const { create } = localOperations\n return create<T>(this, options)\n }\n db: DatabaseAdapter\n\n decrypt = decrypt\n\n duplicate = async <T extends keyof TGeneratedTypes['collections']>(\n options: DuplicateOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]> => {\n const { duplicate } = localOperations\n return duplicate<T>(this, options)\n }\n\n email: InitializedEmailAdapter\n\n // TODO: re-implement or remove?\n // errorHandler: ErrorHandler\n\n encrypt = encrypt\n\n extensions: (args: {\n args: OperationArgs<any>\n req: graphQLRequest<unknown, unknown>\n result: ExecutionResult\n }) => Promise<any>\n\n /**\n * @description Find documents with criteria\n * @param options\n * @returns documents satisfying query\n */\n find = async <T extends keyof TGeneratedTypes['collections']>(\n options: FindOptions<T>,\n ): Promise<PaginatedDocs<TGeneratedTypes['collections'][T]>> => {\n const { find } = localOperations\n return find<T>(this, options)\n }\n\n /**\n * @description Find document by ID\n * @param options\n * @returns document with specified ID\n */\n findByID = async <T extends keyof TGeneratedTypes['collections']>(\n options: FindByIDOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]> => {\n const { findByID } = localOperations\n return findByID<T>(this, options)\n }\n\n findGlobal = async <T extends keyof TGeneratedTypes['globals']>(\n options: FindGlobalOptions<T>,\n ): Promise<TGeneratedTypes['globals'][T]> => {\n const { findOne } = localGlobalOperations\n return findOne<T>(this, options)\n }\n\n /**\n * @description Find global version by ID\n * @param options\n * @returns global version with specified ID\n */\n findGlobalVersionByID = async <T extends keyof TGeneratedTypes['globals']>(\n options: FindGlobalVersionByIDOptions<T>,\n ): Promise<TypeWithVersion<TGeneratedTypes['globals'][T]>> => {\n const { findVersionByID } = localGlobalOperations\n return findVersionByID<T>(this, options)\n }\n\n /**\n * @description Find global versions with criteria\n * @param options\n * @returns versions satisfying query\n */\n findGlobalVersions = async <T extends keyof TGeneratedTypes['globals']>(\n options: FindGlobalVersionsOptions<T>,\n ): Promise<PaginatedDocs<TypeWithVersion<TGeneratedTypes['globals'][T]>>> => {\n const { findVersions } = localGlobalOperations\n return findVersions<T>(this, options)\n }\n\n /**\n * @description Find version by ID\n * @param options\n * @returns version with specified ID\n */\n findVersionByID = async <T extends keyof TGeneratedTypes['collections']>(\n options: FindVersionByIDOptions<T>,\n ): Promise<TypeWithVersion<TGeneratedTypes['collections'][T]>> => {\n const { findVersionByID } = localOperations\n return findVersionByID<T>(this, options)\n }\n\n /**\n * @description Find versions with criteria\n * @param options\n * @returns versions satisfying query\n */\n findVersions = async <T extends keyof TGeneratedTypes['collections']>(\n options: FindVersionsOptions<T>,\n ): Promise<PaginatedDocs<TypeWithVersion<TGeneratedTypes['collections'][T]>>> => {\n const { findVersions } = localOperations\n return findVersions<T>(this, options)\n }\n\n forgotPassword = async <T extends keyof TGeneratedTypes['collections']>(\n options: ForgotPasswordOptions<T>,\n ): Promise<ForgotPasswordResult> => {\n const { forgotPassword } = localOperations.auth\n return forgotPassword<T>(this, options)\n }\n\n getAPIURL = (): string => `${this.config.serverURL}${this.config.routes.api}`\n\n getAdminURL = (): string => `${this.config.serverURL}${this.config.routes.admin}`\n\n globals: Globals\n\n logger: pino.Logger\n\n login = async <T extends keyof TGeneratedTypes['collections']>(\n options: LoginOptions<T>,\n ): Promise<LoginResult & { user: TGeneratedTypes['collections'][T] }> => {\n const { login } = localOperations.auth\n return login<T>(this, options)\n }\n\n resetPassword = async <T extends keyof TGeneratedTypes['collections']>(\n options: ResetPasswordOptions<T>,\n ): Promise<ResetPasswordResult> => {\n const { resetPassword } = localOperations.auth\n return resetPassword<T>(this, options)\n }\n\n /**\n * @description Restore global version by ID\n * @param options\n * @returns version with specified ID\n */\n restoreGlobalVersion = async <T extends keyof TGeneratedTypes['globals']>(\n options: RestoreGlobalVersionOptions<T>,\n ): Promise<TGeneratedTypes['globals'][T]> => {\n const { restoreVersion } = localGlobalOperations\n return restoreVersion<T>(this, options)\n }\n\n /**\n * @description Restore version by ID\n * @param options\n * @returns version with specified ID\n */\n restoreVersion = async <T extends keyof TGeneratedTypes['collections']>(\n options: RestoreVersionOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]> => {\n const { restoreVersion } = localOperations\n return restoreVersion<T>(this, options)\n }\n\n schema: GraphQLSchema\n\n secret: string\n\n sendEmail: InitializedEmailAdapter['sendEmail']\n\n types: {\n arrayTypes: any\n blockInputTypes: any\n blockTypes: any\n fallbackLocaleInputType?: any\n groupTypes: any\n localeInputType?: any\n tabTypes: any\n }\n\n unlock = async <T extends keyof TGeneratedTypes['collections']>(\n options: UnlockOptions<T>,\n ): Promise<boolean> => {\n const { unlock } = localOperations.auth\n return unlock(this, options)\n }\n\n updateGlobal = async <T extends keyof TGeneratedTypes['globals']>(\n options: UpdateGlobalOptions<T>,\n ): Promise<TGeneratedTypes['globals'][T]> => {\n const { update } = localGlobalOperations\n return update<T>(this, options)\n }\n\n validationRules: (args: OperationArgs<any>) => ValidationRule[]\n\n verifyEmail = async <T extends keyof TGeneratedTypes['collections']>(\n options: VerifyEmailOptions<T>,\n ): Promise<boolean> => {\n const { verifyEmail } = localOperations.auth\n return verifyEmail(this, options)\n }\n\n versions: {\n [slug: string]: any // TODO: Type this\n } = {}\n\n /**\n * @description delete one or more documents\n * @param options\n * @returns Updated document(s)\n */\n delete<T extends keyof TGeneratedTypes['collections']>(\n options: DeleteByIDOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]>\n\n delete<T extends keyof TGeneratedTypes['collections']>(\n options: DeleteManyOptions<T>,\n ): Promise<BulkOperationResult<T>>\n\n delete<T extends keyof TGeneratedTypes['collections']>(\n options: DeleteOptions<T>,\n ): Promise<BulkOperationResult<T> | TGeneratedTypes['collections'][T]> {\n const { deleteLocal } = localOperations\n return deleteLocal<T>(this, options)\n }\n\n /**\n * @description Initializes Payload\n * @param options\n */\n async init(options: InitOptions): Promise<Payload> {\n if (!options?.config) {\n throw new Error('Error: the payload config is required to initialize payload.')\n }\n\n this.logger = Logger('payload', options.loggerOptions, options.loggerDestination)\n\n this.config = await options.config\n\n if (process.env.NODE_ENV !== 'production') {\n validateSchema(this.config, this.logger)\n }\n\n if (!this.config.secret) {\n throw new Error('Error: missing secret key. A secret key is needed to secure Payload.')\n }\n\n this.secret = crypto.createHash('sha256').update(this.config.secret).digest('hex').slice(0, 32)\n\n this.globals = {\n config: this.config.globals,\n }\n\n this.config.collections.forEach((collection) => {\n const customID = flattenFields(collection.fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n let customIDType\n\n if (customID?.type === 'number' || customID?.type === 'text') customIDType = customID.type\n\n this.collections[collection.slug] = {\n config: collection,\n customIDType,\n }\n })\n\n this.db = this.config.db.init({ payload: this })\n this.db.payload = this\n\n if (this.db?.init) {\n await this.db.init()\n }\n\n if (!options.disableDBConnect && this.db.connect) {\n await this.db.connect()\n }\n\n // Load email adapter\n if (this.config.email instanceof Promise) {\n const awaitedAdapter = await this.config.email\n this.email = awaitedAdapter({ payload: this })\n } else if (this.config.email) {\n this.email = this.config.email({ payload: this })\n } else {\n this.logger.warn(\n `No email adapter provided. Email will be written to console. More info at https://payloadcms.com/docs/email/overview.`,\n )\n\n this.email = consoleEmailAdapter({ payload: this })\n }\n\n this.sendEmail = this.email['sendEmail']\n\n serverInitTelemetry(this)\n\n // 1. loop over collections, if collection has auth strategy, initialize and push to array\n let jwtStrategyEnabled = false\n this.authStrategies = this.config.collections.reduce((authStrategies, collection) => {\n if (collection?.auth) {\n if (collection.auth.strategies.length > 0) {\n authStrategies.push(...collection.auth.strategies)\n }\n\n // 2. if api key enabled, push api key strategy into the array\n if (collection.auth?.useAPIKey) {\n authStrategies.push({\n name: `${collection.slug}-api-key`,\n authenticate: APIKeyAuthentication(collection),\n })\n }\n\n // 3. if localStrategy flag is true\n if (!collection.auth.disableLocalStrategy && !jwtStrategyEnabled) {\n jwtStrategyEnabled = true\n }\n }\n\n return authStrategies\n }, [] as AuthStrategy[])\n\n // 4. if enabled, push jwt strategy into authStrategies last\n if (jwtStrategyEnabled) {\n this.authStrategies.push({\n name: 'local-jwt',\n authenticate: JWTAuthentication,\n })\n }\n\n if (!options.disableOnInit) {\n if (typeof options.onInit === 'function') await options.onInit(this)\n if (typeof this.config.onInit === 'function') await this.config.onInit(this)\n }\n\n return this\n }\n\n update<T extends keyof TGeneratedTypes['collections']>(\n options: UpdateManyOptions<T>,\n ): Promise<BulkOperationResult<T>>\n\n /**\n * @description Update one or more documents\n * @param options\n * @returns Updated document(s)\n */\n update<T extends keyof TGeneratedTypes['collections']>(\n options: UpdateByIDOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]>\n\n update<T extends keyof TGeneratedTypes['collections']>(\n options: UpdateOptions<T>,\n ): Promise<BulkOperationResult<T> | TGeneratedTypes['collections'][T]> {\n const { update } = localOperations\n return update<T>(this, options)\n }\n}\n\nconst initialized = new BasePayload()\n\nexport default initialized\n\nlet cached = global._payload\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload = { payload: null, promise: null }\n}\n\nexport const getPayload = async (options: InitOptions): Promise<BasePayload<GeneratedTypes>> => {\n if (!options?.config) {\n throw new Error('Error: the payload config is required for getPayload to work.')\n }\n\n if (cached.payload) {\n return cached.payload\n }\n\n if (!cached.promise) {\n cached.promise = new BasePayload<GeneratedTypes>().init(options)\n }\n\n try {\n cached.payload = await cached.promise\n } catch (e) {\n cached.promise = null\n throw e\n }\n\n return cached.payload\n}\n\ntype GeneratedTypes = {\n collections: {\n [slug: number | string | symbol]: TypeWithID & Record<string, unknown>\n }\n globals: {\n [slug: number | string | symbol]: GlobalTypeWithID & Record<string, unknown>\n }\n locale: null | string\n user: TypeWithID & Record<string, unknown> & { collection: string }\n}\n\ntype Payload = BasePayload<GeneratedTypes>\n\ninterface RequestContext {\n [key: string]: unknown\n}\n\ntype DatabaseAdapter = BaseDatabaseAdapter\n\nexport type { DatabaseAdapter, GeneratedTypes, Payload, RequestContext }\n"],"names":["crypto","decrypt","encrypt","APIKeyAuthentication","JWTAuthentication","localOperations","validateSchema","consoleEmailAdapter","fieldAffectsData","localGlobalOperations","flattenFields","Logger","serverInit","serverInitTelemetry","BasePayload","auth","options","authStrategies","collections","config","count","create","db","duplicate","email","extensions","find","findByID","findGlobal","findOne","findGlobalVersionByID","findVersionByID","findGlobalVersions","findVersions","forgotPassword","getAPIURL","serverURL","routes","api","getAdminURL","admin","globals","logger","login","resetPassword","restoreGlobalVersion","restoreVersion","schema","secret","sendEmail","types","unlock","updateGlobal","update","validationRules","verifyEmail","versions","delete","deleteLocal","init","Error","loggerOptions","loggerDestination","process","env","NODE_ENV","createHash","digest","slice","forEach","collection","customID","fields","field","name","customIDType","type","slug","payload","disableDBConnect","connect","Promise","awaitedAdapter","warn","jwtStrategyEnabled","reduce","strategies","length","push","useAPIKey","authenticate","disableLocalStrategy","disableOnInit","onInit","initialized","cached","global","_payload","promise","getPayload","e"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,OAAOA,YAAY,SAAQ;AA0C3B,SAASC,OAAO,EAAEC,OAAO,QAAQ,mBAAkB;AACnD,SAASC,oBAAoB,QAAQ,8BAA6B;AAClE,SAASC,iBAAiB,QAAQ,2BAA0B;AAC5D,OAAOC,qBAAqB,0CAAyC;AACrE,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,mBAAmB,QAAQ,iCAAgC;AACpE,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,OAAOC,2BAA2B,sCAAqC;AACvE,OAAOC,mBAAmB,uCAAsC;AAChE,OAAOC,YAAY,wBAAuB;AAC1C,SAASC,cAAcC,mBAAmB,QAAQ,6CAA4C;AAE9F;;CAEC,GACD,OAAO,MAAMC;IACX;;;;;GAKC,GACDC,OAAO,OAAOC;QACZ,MAAM,EAAED,IAAI,EAAE,GAAGV,gBAAgBU,IAAI;QACrC,OAAOA,KAAK,IAAI,EAAEC;IACpB,EAAC;IAEDC,eAA8B;IAE9BC,cAEI,CAAC,EAAC;IAENC,OAAuB;IAEvB;;;;GAIC,GACDC,QAAQ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AOC,QAAQ,GAAG;QAAEnB,SAAS;QAAMoB,SAAS;IAAK;AAC5D;AAEA,OAAO,MAAMC,aAAa,OAAOnF;IAC/B,IAAI,CAACA,SAASG,QAAQ;QACpB,MAAM,IAAIyC,MAAM;IAClB;IAEA,IAAImC,OAAOjB,OAAO,EAAE;QAClB,OAAOiB,OAAOjB,OAAO;IACvB;IAEA,IAAI,CAACiB,OAAOG,OAAO,EAAE;QACnBH,OAAOG,OAAO,GAAG,IAAIpF,cAA8B6C,IAAI,CAAC3C;IAC1D;IAEA,IAAI;QACF+E,OAAOjB,OAAO,GAAG,MAAMiB,OAAOG,OAAO;IACvC,EAAE,OAAOE,GAAG;QACVL,OAAOG,OAAO,GAAG;QACjB,MAAME;IACR;IAEA,OAAOL,OAAOjB,OAAO;AACvB,EAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ExecutionResult, GraphQLSchema, ValidationRule } from 'graphql'\nimport type { OperationArgs, Request as graphQLRequest } from 'graphql-http'\nimport type pino from 'pino'\n\nimport crypto from 'crypto'\n\nimport type { AuthArgs } from './auth/operations/auth.js'\nimport type { Result as ForgotPasswordResult } from './auth/operations/forgotPassword.js'\nimport type { Options as ForgotPasswordOptions } from './auth/operations/local/forgotPassword.js'\nimport type { Options as LoginOptions } from './auth/operations/local/login.js'\nimport type { Options as ResetPasswordOptions } from './auth/operations/local/resetPassword.js'\nimport type { Options as UnlockOptions } from './auth/operations/local/unlock.js'\nimport type { Options as VerifyEmailOptions } from './auth/operations/local/verifyEmail.js'\nimport type { Result as LoginResult } from './auth/operations/login.js'\nimport type { Result as ResetPasswordResult } from './auth/operations/resetPassword.js'\nimport type { AuthStrategy, User } from './auth/types.js'\nimport type { BulkOperationResult, Collection, TypeWithID } from './collections/config/types.js'\nimport type { Options as CountOptions } from './collections/operations/local/count.js'\nimport type { Options as CreateOptions } from './collections/operations/local/create.js'\nimport type {\n ByIDOptions as DeleteByIDOptions,\n ManyOptions as DeleteManyOptions,\n Options as DeleteOptions,\n} from './collections/operations/local/delete.js'\nimport type { Options as DuplicateOptions } from './collections/operations/local/duplicate.js'\nimport type { Options as FindOptions } from './collections/operations/local/find.js'\nimport type { Options as FindByIDOptions } from './collections/operations/local/findByID.js'\nimport type { Options as FindVersionByIDOptions } from './collections/operations/local/findVersionByID.js'\nimport type { Options as FindVersionsOptions } from './collections/operations/local/findVersions.js'\nimport type { Options as RestoreVersionOptions } from './collections/operations/local/restoreVersion.js'\nimport type {\n ByIDOptions as UpdateByIDOptions,\n ManyOptions as UpdateManyOptions,\n Options as UpdateOptions,\n} from './collections/operations/local/update.js'\nimport type { InitOptions, SanitizedConfig } from './config/types.js'\nimport type { BaseDatabaseAdapter, PaginatedDocs } from './database/types.js'\nimport type { InitializedEmailAdapter } from './email/types.js'\nimport type { TypeWithID as GlobalTypeWithID, Globals } from './globals/config/types.js'\nimport type { Options as FindGlobalOptions } from './globals/operations/local/findOne.js'\nimport type { Options as FindGlobalVersionByIDOptions } from './globals/operations/local/findVersionByID.js'\nimport type { Options as FindGlobalVersionsOptions } from './globals/operations/local/findVersions.js'\nimport type { Options as RestoreGlobalVersionOptions } from './globals/operations/local/restoreVersion.js'\nimport type { Options as UpdateGlobalOptions } from './globals/operations/local/update.js'\nimport type { TypeWithVersion } from './versions/types.js'\n\nimport { decrypt, encrypt } from './auth/crypto.js'\nimport { APIKeyAuthentication } from './auth/strategies/apiKey.js'\nimport { JWTAuthentication } from './auth/strategies/jwt.js'\nimport localOperations from './collections/operations/local/index.js'\nimport { validateSchema } from './config/validate.js'\nimport { consoleEmailAdapter } from './email/consoleEmailAdapter.js'\nimport { fieldAffectsData } from './fields/config/types.js'\nimport localGlobalOperations from './globals/operations/local/index.js'\nimport flattenFields from './utilities/flattenTopLevelFields.js'\nimport Logger from './utilities/logger.js'\nimport { serverInit as serverInitTelemetry } from './utilities/telemetry/events/serverInit.js'\n\n/**\n * @description Payload\n */\nexport class BasePayload<TGeneratedTypes extends GeneratedTypes> {\n /**\n * @description Authorization and Authentication using headers and cookies to run auth user strategies\n * @returns cookies: Map<string, string>\n * @returns permissions: Permissions\n * @returns user: User\n */\n auth = async (options: AuthArgs) => {\n const { auth } = localOperations.auth\n return auth(this, options)\n }\n\n authStrategies: AuthStrategy[]\n\n collections: {\n [slug: number | string | symbol]: Collection\n } = {}\n\n config: SanitizedConfig\n\n /**\n * @description Performs count operation\n * @param options\n * @returns count of documents satisfying query\n */\n count = async <T extends keyof TGeneratedTypes['collections']>(\n options: CountOptions<T>,\n ): Promise<{ totalDocs: number }> => {\n const { count } = localOperations\n return count(this, options)\n }\n\n /**\n * @description Performs create operation\n * @param options\n * @returns created document\n */\n create = async <T extends keyof TGeneratedTypes['collections']>(\n options: CreateOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]> => {\n const { create } = localOperations\n return create<T>(this, options)\n }\n db: DatabaseAdapter\n\n decrypt = decrypt\n\n duplicate = async <T extends keyof TGeneratedTypes['collections']>(\n options: DuplicateOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]> => {\n const { duplicate } = localOperations\n return duplicate<T>(this, options)\n }\n\n email: InitializedEmailAdapter\n\n // TODO: re-implement or remove?\n // errorHandler: ErrorHandler\n\n encrypt = encrypt\n\n extensions: (args: {\n args: OperationArgs<any>\n req: graphQLRequest<unknown, unknown>\n result: ExecutionResult\n }) => Promise<any>\n\n /**\n * @description Find documents with criteria\n * @param options\n * @returns documents satisfying query\n */\n find = async <T extends keyof TGeneratedTypes['collections']>(\n options: FindOptions<T>,\n ): Promise<PaginatedDocs<TGeneratedTypes['collections'][T]>> => {\n const { find } = localOperations\n return find<T>(this, options)\n }\n\n /**\n * @description Find document by ID\n * @param options\n * @returns document with specified ID\n */\n findByID = async <T extends keyof TGeneratedTypes['collections']>(\n options: FindByIDOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]> => {\n const { findByID } = localOperations\n return findByID<T>(this, options)\n }\n\n findGlobal = async <T extends keyof TGeneratedTypes['globals']>(\n options: FindGlobalOptions<T>,\n ): Promise<TGeneratedTypes['globals'][T]> => {\n const { findOne } = localGlobalOperations\n return findOne<T>(this, options)\n }\n\n /**\n * @description Find global version by ID\n * @param options\n * @returns global version with specified ID\n */\n findGlobalVersionByID = async <T extends keyof TGeneratedTypes['globals']>(\n options: FindGlobalVersionByIDOptions<T>,\n ): Promise<TypeWithVersion<TGeneratedTypes['globals'][T]>> => {\n const { findVersionByID } = localGlobalOperations\n return findVersionByID<T>(this, options)\n }\n\n /**\n * @description Find global versions with criteria\n * @param options\n * @returns versions satisfying query\n */\n findGlobalVersions = async <T extends keyof TGeneratedTypes['globals']>(\n options: FindGlobalVersionsOptions<T>,\n ): Promise<PaginatedDocs<TypeWithVersion<TGeneratedTypes['globals'][T]>>> => {\n const { findVersions } = localGlobalOperations\n return findVersions<T>(this, options)\n }\n\n /**\n * @description Find version by ID\n * @param options\n * @returns version with specified ID\n */\n findVersionByID = async <T extends keyof TGeneratedTypes['collections']>(\n options: FindVersionByIDOptions<T>,\n ): Promise<TypeWithVersion<TGeneratedTypes['collections'][T]>> => {\n const { findVersionByID } = localOperations\n return findVersionByID<T>(this, options)\n }\n\n /**\n * @description Find versions with criteria\n * @param options\n * @returns versions satisfying query\n */\n findVersions = async <T extends keyof TGeneratedTypes['collections']>(\n options: FindVersionsOptions<T>,\n ): Promise<PaginatedDocs<TypeWithVersion<TGeneratedTypes['collections'][T]>>> => {\n const { findVersions } = localOperations\n return findVersions<T>(this, options)\n }\n\n forgotPassword = async <T extends keyof TGeneratedTypes['collections']>(\n options: ForgotPasswordOptions<T>,\n ): Promise<ForgotPasswordResult> => {\n const { forgotPassword } = localOperations.auth\n return forgotPassword<T>(this, options)\n }\n\n getAPIURL = (): string => `${this.config.serverURL}${this.config.routes.api}`\n\n getAdminURL = (): string => `${this.config.serverURL}${this.config.routes.admin}`\n\n globals: Globals\n\n logger: pino.Logger\n\n login = async <T extends keyof TGeneratedTypes['collections']>(\n options: LoginOptions<T>,\n ): Promise<LoginResult & { user: TGeneratedTypes['collections'][T] }> => {\n const { login } = localOperations.auth\n return login<T>(this, options)\n }\n\n resetPassword = async <T extends keyof TGeneratedTypes['collections']>(\n options: ResetPasswordOptions<T>,\n ): Promise<ResetPasswordResult> => {\n const { resetPassword } = localOperations.auth\n return resetPassword<T>(this, options)\n }\n\n /**\n * @description Restore global version by ID\n * @param options\n * @returns version with specified ID\n */\n restoreGlobalVersion = async <T extends keyof TGeneratedTypes['globals']>(\n options: RestoreGlobalVersionOptions<T>,\n ): Promise<TGeneratedTypes['globals'][T]> => {\n const { restoreVersion } = localGlobalOperations\n return restoreVersion<T>(this, options)\n }\n\n /**\n * @description Restore version by ID\n * @param options\n * @returns version with specified ID\n */\n restoreVersion = async <T extends keyof TGeneratedTypes['collections']>(\n options: RestoreVersionOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]> => {\n const { restoreVersion } = localOperations\n return restoreVersion<T>(this, options)\n }\n\n schema: GraphQLSchema\n\n secret: string\n\n sendEmail: InitializedEmailAdapter['sendEmail']\n\n types: {\n arrayTypes: any\n blockInputTypes: any\n blockTypes: any\n fallbackLocaleInputType?: any\n groupTypes: any\n localeInputType?: any\n tabTypes: any\n }\n\n unlock = async <T extends keyof TGeneratedTypes['collections']>(\n options: UnlockOptions<T>,\n ): Promise<boolean> => {\n const { unlock } = localOperations.auth\n return unlock(this, options)\n }\n\n updateGlobal = async <T extends keyof TGeneratedTypes['globals']>(\n options: UpdateGlobalOptions<T>,\n ): Promise<TGeneratedTypes['globals'][T]> => {\n const { update } = localGlobalOperations\n return update<T>(this, options)\n }\n\n validationRules: (args: OperationArgs<any>) => ValidationRule[]\n\n verifyEmail = async <T extends keyof TGeneratedTypes['collections']>(\n options: VerifyEmailOptions<T>,\n ): Promise<boolean> => {\n const { verifyEmail } = localOperations.auth\n return verifyEmail(this, options)\n }\n\n versions: {\n [slug: string]: any // TODO: Type this\n } = {}\n\n /**\n * @description delete one or more documents\n * @param options\n * @returns Updated document(s)\n */\n delete<T extends keyof TGeneratedTypes['collections']>(\n options: DeleteByIDOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]>\n\n delete<T extends keyof TGeneratedTypes['collections']>(\n options: DeleteManyOptions<T>,\n ): Promise<BulkOperationResult<T>>\n\n delete<T extends keyof TGeneratedTypes['collections']>(\n options: DeleteOptions<T>,\n ): Promise<BulkOperationResult<T> | TGeneratedTypes['collections'][T]> {\n const { deleteLocal } = localOperations\n return deleteLocal<T>(this, options)\n }\n\n /**\n * @description Initializes Payload\n * @param options\n */\n async init(options: InitOptions): Promise<Payload> {\n if (!options?.config) {\n throw new Error('Error: the payload config is required to initialize payload.')\n }\n\n this.logger = Logger('payload', options.loggerOptions, options.loggerDestination)\n\n this.config = await options.config\n\n if (process.env.NODE_ENV !== 'production') {\n validateSchema(this.config, this.logger)\n }\n\n if (!this.config.secret) {\n throw new Error('Error: missing secret key. A secret key is needed to secure Payload.')\n }\n\n this.secret = crypto.createHash('sha256').update(this.config.secret).digest('hex').slice(0, 32)\n\n this.globals = {\n config: this.config.globals,\n }\n\n this.config.collections.forEach((collection) => {\n const customID = flattenFields(collection.fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n\n let customIDType\n\n if (customID?.type === 'number' || customID?.type === 'text') customIDType = customID.type\n\n this.collections[collection.slug] = {\n config: collection,\n customIDType,\n }\n })\n\n this.db = this.config.db.init({ payload: this })\n this.db.payload = this\n\n if (this.db?.init) {\n await this.db.init()\n }\n\n if (!options.disableDBConnect && this.db.connect) {\n await this.db.connect()\n }\n\n // Load email adapter\n if (this.config.email instanceof Promise) {\n const awaitedAdapter = await this.config.email\n this.email = awaitedAdapter({ payload: this })\n } else if (this.config.email) {\n this.email = this.config.email({ payload: this })\n } else {\n this.logger.warn(\n `No email adapter provided. Email will be written to console. More info at https://payloadcms.com/docs/email/overview.`,\n )\n\n this.email = consoleEmailAdapter({ payload: this })\n }\n\n this.sendEmail = this.email['sendEmail']\n\n serverInitTelemetry(this)\n\n // 1. loop over collections, if collection has auth strategy, initialize and push to array\n let jwtStrategyEnabled = false\n this.authStrategies = this.config.collections.reduce((authStrategies, collection) => {\n if (collection?.auth) {\n if (collection.auth.strategies.length > 0) {\n authStrategies.push(...collection.auth.strategies)\n }\n\n // 2. if api key enabled, push api key strategy into the array\n if (collection.auth?.useAPIKey) {\n authStrategies.push({\n name: `${collection.slug}-api-key`,\n authenticate: APIKeyAuthentication(collection),\n })\n }\n\n // 3. if localStrategy flag is true\n if (!collection.auth.disableLocalStrategy && !jwtStrategyEnabled) {\n jwtStrategyEnabled = true\n }\n }\n\n return authStrategies\n }, [] as AuthStrategy[])\n\n // 4. if enabled, push jwt strategy into authStrategies last\n if (jwtStrategyEnabled) {\n this.authStrategies.push({\n name: 'local-jwt',\n authenticate: JWTAuthentication,\n })\n }\n\n if (!options.disableOnInit) {\n if (typeof options.onInit === 'function') await options.onInit(this)\n if (typeof this.config.onInit === 'function') await this.config.onInit(this)\n }\n\n return this\n }\n\n update<T extends keyof TGeneratedTypes['collections']>(\n options: UpdateManyOptions<T>,\n ): Promise<BulkOperationResult<T>>\n\n /**\n * @description Update one or more documents\n * @param options\n * @returns Updated document(s)\n */\n update<T extends keyof TGeneratedTypes['collections']>(\n options: UpdateByIDOptions<T>,\n ): Promise<TGeneratedTypes['collections'][T]>\n\n update<T extends keyof TGeneratedTypes['collections']>(\n options: UpdateOptions<T>,\n ): Promise<BulkOperationResult<T> | TGeneratedTypes['collections'][T]> {\n const { update } = localOperations\n return update<T>(this, options)\n }\n}\n\nconst initialized = new BasePayload()\n\nexport default initialized\n\nlet cached = global._payload\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload = { payload: null, promise: null }\n}\n\nexport const getPayload = async (options: InitOptions): Promise<BasePayload<GeneratedTypes>> => {\n if (!options?.config) {\n throw new Error('Error: the payload config is required for getPayload to work.')\n }\n\n if (cached.payload) {\n return cached.payload\n }\n\n if (!cached.promise) {\n cached.promise = new BasePayload<GeneratedTypes>().init(options)\n }\n\n try {\n cached.payload = await cached.promise\n } catch (e) {\n cached.promise = null\n throw e\n }\n\n return cached.payload\n}\n\ntype GeneratedTypes = {\n collections: {\n [slug: number | string | symbol]: TypeWithID & Record<string, unknown>\n }\n globals: {\n [slug: number | string | symbol]: GlobalTypeWithID & Record<string, unknown>\n }\n locale: null | string\n user: User\n}\n\ntype Payload = BasePayload<GeneratedTypes>\n\ninterface RequestContext {\n [key: string]: unknown\n}\n\ntype DatabaseAdapter = BaseDatabaseAdapter\n\nexport type { DatabaseAdapter, GeneratedTypes, Payload, RequestContext }\n"],"names":["crypto","decrypt","encrypt","APIKeyAuthentication","JWTAuthentication","localOperations","validateSchema","consoleEmailAdapter","fieldAffectsData","localGlobalOperations","flattenFields","Logger","serverInit","serverInitTelemetry","BasePayload","auth","options","authStrategies","collections","config","count","create","db","duplicate","email","extensions","find","findByID","findGlobal","findOne","findGlobalVersionByID","findVersionByID","findGlobalVersions","findVersions","forgotPassword","getAPIURL","serverURL","routes","api","getAdminURL","admin","globals","logger","login","resetPassword","restoreGlobalVersion","restoreVersion","schema","secret","sendEmail","types","unlock","updateGlobal","update","validationRules","verifyEmail","versions","delete","deleteLocal","init","Error","loggerOptions","loggerDestination","process","env","NODE_ENV","createHash","digest","slice","forEach","collection","customID","fields","field","name","customIDType","type","slug","payload","disableDBConnect","connect","Promise","awaitedAdapter","warn","jwtStrategyEnabled","reduce","strategies","length","push","useAPIKey","authenticate","disableLocalStrategy","disableOnInit","onInit","initialized","cached","global","_payload","promise","getPayload","e"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
@@ -18,7 +18,7 @@ export type UploadEdits = {
18
18
  y?: number;
19
19
  };
20
20
  };
21
- export type CustomPayloadRequestProperties<U = unknown> = {
21
+ export type CustomPayloadRequestProperties = {
22
22
  context: RequestContext;
23
23
  /** The locale that should be used for a field when it is not translated to the requested locale */
24
24
  fallbackLocale?: string;
@@ -58,8 +58,8 @@ export type CustomPayloadRequestProperties<U = unknown> = {
58
58
  * Used to ensure consistency when multiple operations try to create a transaction concurrently on the same request
59
59
  */
60
60
  transactionIDPromise?: Promise<void>;
61
- /** The signed in user */
62
- user: (U & GeneratedTypes['user']) | null;
61
+ /** The signed-in user */
62
+ user: GeneratedTypes['user'] | null;
63
63
  } & Pick<URL, 'hash' | 'host' | 'href' | 'origin' | 'pathname' | 'port' | 'protocol' | 'search' | 'searchParams'>;
64
64
  export type PayloadRequestData = {
65
65
  /** Data from the request body */
@@ -73,8 +73,8 @@ export type PayloadRequestData = {
73
73
  tempFilePath?: string;
74
74
  };
75
75
  };
76
- export type PayloadRequest<U = unknown> = Partial<Request> & Required<Pick<Request, 'headers'>> & CustomPayloadRequestProperties<U>;
77
- export type PayloadRequestWithData<U = unknown> = PayloadRequest<U> & PayloadRequestData;
76
+ export type PayloadRequest = Partial<Request> & Required<Pick<Request, 'headers'>> & CustomPayloadRequestProperties;
77
+ export type PayloadRequestWithData = PayloadRequest & PayloadRequestData;
78
78
  export interface RequestContext {
79
79
  [key: string]: unknown;
80
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,KAAK,UAAU,MAAM,YAAY,CAAA;AAExC,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACpF,OAAO,KAAK,OAAO,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,cAAc,E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AA;AAE1B,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAA;AAC/D,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAA;AAC9C,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAA;AACrC,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,SAAS,GAAG,iBAAiB,CAAA;AAE1E,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,kBAAkB,CAEpE;AAED,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACpD,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;AAC5C,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,WAAW,IAAI,KAAK,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,WAAW,GAAG,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["import type { I18n, TFunction } from '@payloadcms/translations'\nimport type DataLoader from 'dataloader'\n\nimport type { TypeWithID, TypeWithTimestamps } from '../collections/config/types.js'\nimport type payload from '../index.js'\nimport type { GeneratedTypes } from '../index.js'\nimport type { validOperators } from './constants.js'\nexport type { Payload as Payload } from '../index.js'\n\nexport type UploadEdits = {\n crop?: {\n height?: number\n width?: number\n x?: number\n y?: number\n }\n focalPoint?: {\n x?: number\n y?: number\n }\n}\n\nexport type CustomPayloadRequestProperties<U = unknown> = {\n context: RequestContext\n /** The locale that should be used for a field when it is not translated to the requested locale */\n fallbackLocale?: string\n i18n: I18n\n /**\n * The requested locale if specified\n * Only available for localized collections\n */\n locale?: GeneratedTypes['locale']\n /**\n * The payload object\n */\n payload: typeof payload\n /**\n * The context in which the request is being made\n */\n payloadAPI: 'GraphQL' | 'REST' | 'local'\n /** Optimized document loader */\n payloadDataLoader?: DataLoader<string, TypeWithID>\n /** Resized versions of the image that was uploaded during this request */\n payloadUploadSizes?: Record<string, Buffer>\n /** Query params on the request */\n query: Record<string, unknown>\n /** The route parameters\n * @example\n * /:collection/:id -> /posts/123\n * { collection: 'posts', id: '123' }\n */\n routeParams?: Record<string, unknown>\n /** Translate function - duplicate of i18n.t */\n t: TFunction\n /**\n * Identifier for the database transaction for interactions in a single, all-or-nothing operation.\n */\n transactionID?: number | string\n /**\n * Used to ensure consistency when multiple operations try to create a transaction concurrently on the same request\n */\n transactionIDPromise?: Promise<void>\n /** The signed in user */\n user: (U & GeneratedTypes['user']) | null\n} & Pick<\n URL,\n 'hash' | 'host' | 'href' | 'origin' | 'pathname' | 'port' | 'protocol' | 'search' | 'searchParams'\n>\nexport type PayloadRequestData = {\n /** Data from the request body */\n data?: Record<string, unknown>\n /** The locale that should be used for a field when it is not translated to the requested locale */\n file?: {\n data: Buffer\n mimetype: string\n name: string\n size: number\n tempFilePath?: string\n }\n}\nexport type PayloadRequest<U = unknown> = Partial<Request> &\n Required<Pick<Request, 'headers'>> &\n CustomPayloadRequestProperties<U>\nexport type PayloadRequestWithData<U = unknown> = PayloadRequest<U> & PayloadRequestData\nexport interface RequestContext {\n [key: string]: unknown\n}\n\nexport type Operator = (typeof validOperators)[number]\n\nexport type WhereField = {\n [key in Operator]?: unknown\n}\n\nexport type Where = {\n [key: string]: Where[] | WhereField\n and?: Where[]\n or?: Where[]\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Document = any\n\nexport type Operation = 'create' | 'delete' | 'read' | 'update'\nexport type VersionOperations = 'readVersions'\nexport type AuthOperations = 'unlock'\nexport type AllOperations = AuthOperations | Operation | VersionOperations\n\nexport function docHasTimestamps(doc: any): doc is TypeWithTimestamps {\n return doc?.createdAt && doc?.updatedAt\n}\n\nexport type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N // This is a commonly used trick to detect 'any'\nexport type IsAny<T> = IfAny<T, true, false>\nexport type ReplaceAny<T, DefaultType> = IsAny<T> extends true ? DefaultType : T\n"],"names":["docHasTimestamps","doc","createdAt","updatedAt"],"rangeMappings":";;","mappings":"AA4GA,OAAO,SAASA,iBAAiBC,GAAQ;IACvC,OAAOA,KAAKC,aAAaD,KAAKE;AAChC"}
1
+ {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["import type { I18n, TFunction } from '@payloadcms/translations'\nimport type DataLoader from 'dataloader'\n\nimport type { TypeWithID, TypeWithTimestamps } from '../collections/config/types.js'\nimport type payload from '../index.js'\nimport type { GeneratedTypes } from '../index.js'\nimport type { validOperators } from './constants.js'\nexport type { Payload as Payload } from '../index.js'\n\nexport type UploadEdits = {\n crop?: {\n height?: number\n width?: number\n x?: number\n y?: number\n }\n focalPoint?: {\n x?: number\n y?: number\n }\n}\n\nexport type CustomPayloadRequestProperties = {\n context: RequestContext\n /** The locale that should be used for a field when it is not translated to the requested locale */\n fallbackLocale?: string\n i18n: I18n\n /**\n * The requested locale if specified\n * Only available for localized collections\n */\n locale?: GeneratedTypes['locale']\n /**\n * The payload object\n */\n payload: typeof payload\n /**\n * The context in which the request is being made\n */\n payloadAPI: 'GraphQL' | 'REST' | 'local'\n /** Optimized document loader */\n payloadDataLoader?: DataLoader<string, TypeWithID>\n /** Resized versions of the image that was uploaded during this request */\n payloadUploadSizes?: Record<string, Buffer>\n /** Query params on the request */\n query: Record<string, unknown>\n /** The route parameters\n * @example\n * /:collection/:id -> /posts/123\n * { collection: 'posts', id: '123' }\n */\n routeParams?: Record<string, unknown>\n /** Translate function - duplicate of i18n.t */\n t: TFunction\n /**\n * Identifier for the database transaction for interactions in a single, all-or-nothing operation.\n */\n transactionID?: number | string\n /**\n * Used to ensure consistency when multiple operations try to create a transaction concurrently on the same request\n */\n transactionIDPromise?: Promise<void>\n /** The signed-in user */\n user: GeneratedTypes['user'] | null\n} & Pick<\n URL,\n 'hash' | 'host' | 'href' | 'origin' | 'pathname' | 'port' | 'protocol' | 'search' | 'searchParams'\n>\nexport type PayloadRequestData = {\n /** Data from the request body */\n data?: Record<string, unknown>\n /** The locale that should be used for a field when it is not translated to the requested locale */\n file?: {\n data: Buffer\n mimetype: string\n name: string\n size: number\n tempFilePath?: string\n }\n}\nexport type PayloadRequest = Partial<Request> &\n Required<Pick<Request, 'headers'>> &\n CustomPayloadRequestProperties\nexport type PayloadRequestWithData = PayloadRequest & PayloadRequestData\nexport interface RequestContext {\n [key: string]: unknown\n}\n\nexport type Operator = (typeof validOperators)[number]\n\nexport type WhereField = {\n [key in Operator]?: unknown\n}\n\nexport type Where = {\n [key: string]: Where[] | WhereField\n and?: Where[]\n or?: Where[]\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Document = any\n\nexport type Operation = 'create' | 'delete' | 'read' | 'update'\nexport type VersionOperations = 'readVersions'\nexport type AuthOperations = 'unlock'\nexport type AllOperations = AuthOperations | Operation | VersionOperations\n\nexport function docHasTimestamps(doc: any): doc is TypeWithTimestamps {\n return doc?.createdAt && doc?.updatedAt\n}\n\nexport type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N // This is a commonly used trick to detect 'any'\nexport type IsAny<T> = IfAny<T, true, false>\nexport type ReplaceAny<T, DefaultType> = IsAny<T> extends true ? DefaultType : T\n"],"names":["docHasTimestamps","doc","createdAt","updatedAt"],"rangeMappings":";;","mappings":"AA4GA,OAAO,SAASA,iBAAiBC,GAAQ;IACvC,OAAOA,KAAKC,aAAaD,KAAKE;AAChC"}
@@ -8,7 +8,7 @@ export const getExternalFile = async ({ data, req, uploadConfig })=>{
8
8
  fileURL = `${baseUrl}${url}`;
9
9
  }
10
10
  const headers = uploadConfig.externalFileHeaderFilter ? uploadConfig.externalFileHeaderFilter(Object.fromEntries(new Headers(req.headers))) : {
11
- cookie: req.headers.get('cookie')
11
+ cookie: req.headers?.get('cookie')
12
12
  };
13
13
  const res = await fetch(fileURL, {
14
14
  credentials: 'include',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/uploads/getExternalFile.ts"],"sourcesContent":["import type { PayloadRequestWithData } from '../types/index.js'\nimport type { File, FileData, UploadConfig } from './types.js'\n\nimport { APIError } from '../errors/index.js'\n\ntype Args = {\n data: FileData\n req: PayloadRequestWithData\n uploadConfig: UploadConfig\n}\nexport const getExternalFile = async ({ data, req, uploadConfig }: Args): Promise<File> => {\n const { filename, url } = data\n\n if (typeof url === 'string') {\n let fileURL = url\n if (!url.startsWith('http')) {\n const baseUrl = req.headers.get('origin') || `${req.protocol}://${req.headers.get('host')}`\n fileURL = `${baseUrl}${url}`\n }\n\n const headers = uploadConfig.externalFileHeaderFilter\n ? uploadConfig.externalFileHeaderFilter(Object.fromEntries(new Headers(req.headers)))\n : { cookie: req.headers.get('cookie') }\n\n const res = await fetch(fileURL, {\n credentials: 'include',\n headers,\n method: 'GET',\n })\n\n if (!res.ok) throw new APIError(`Failed to fetch file from ${fileURL}`, res.status)\n\n const data = await res.arrayBuffer()\n\n return {\n name: filename,\n data: Buffer.from(data),\n mimetype: res.headers.get('content-type') || undefined,\n size: Number(res.headers.get('content-length')) || 0,\n }\n }\n\n throw new APIError('Invalid file url', 400)\n}\n"],"names":["APIError","getExternalFile","data","req","uploadConfig","filename","url","fileURL","startsWith","baseUrl","headers","get","protocol","externalFileHeaderFilter","Object","fromEntries","Headers","cookie","res","fetch","credentials","method","ok","status","arrayBuffer","name","Buffer","from","mimetype","undefined","size","Number"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,QAAQ,QAAQ,qBAAoB;AAO7C,OAAO,MAAMC,kBAAkB,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAEC,YAAY,EAAQ;IACrE,MAAM,EAAEC,QAAQ,EAAEC,GAAG,EAAE,GAAGJ;IAE1B,IAAI,OAAOI,QAAQ,UAAU;QAC3B,IAAIC,UAAUD;QACd,IAAI,CAACA,IAAIE,UAAU,CAAC,SAAS;YAC3B,MAAMC,UAAUN,IAAIO,OAAO,CAACC,GAAG,CAAC,aAAa,CAAC,EAAER,IAAIS,QAAQ,CAAC,GAAG,EAAET,IAAIO,OAAO,CAACC,GAAG,CAAC,QAAQ,CAAC;YAC3FJ,UAAU,CAAC,EAAEE,QAAQ,EAAEH,IAAI,CAAC;QAC9B;QAEA,MAAMI,UAAUN,aAAaS,wBAAwB,GACjDT,aAAaS,wBAAwB,CAACC,OAAOC,WAAW,CAAC,IAAIC,QAAQb,IAAIO,OAAO,MAChF;YAAEO,QAAQd,IAAIO,OAAO,CAACC,GAAG,CAAC;QAAU;QAExC,MAAMO,MAAM,MAAMC,MAAMZ,SAAS;YAC/Ba,aAAa;YACbV;YACAW,QAAQ;QACV;QAEA,IAAI,CAACH,IAAII,EAAE,EAAE,MAAM,IAAItB,SAAS,CAAC,0BAA0B,EAAEO,QAAQ,CAAC,EAAEW,IAAIK,MAAM;QAElF,MAAMrB,OAAO,MAAMgB,IAAIM,WAAW;QAElC,OAAO;YACLC,MAAMpB;YACNH,MAAMwB,OAAOC,IAAI,CAACzB;YAClB0B,UAAUV,IAAIR,OAAO,CAACC,GAAG,CAAC,mBAAmBkB;YAC7CC,MAAMC,OAAOb,IAAIR,OAAO,CAACC,GAAG,CAAC,sBAAsB;QACrD;IACF;IAEA,MAAM,IAAIX,SAAS,oBAAoB;AACzC,EAAC"}
1
+ {"version":3,"sources":["../../src/uploads/getExternalFile.ts"],"sourcesContent":["import type { PayloadRequestWithData } from '../types/index.js'\nimport type { File, FileData, UploadConfig } from './types.js'\n\nimport { APIError } from '../errors/index.js'\n\ntype Args = {\n data: FileData\n req: PayloadRequestWithData\n uploadConfig: UploadConfig\n}\nexport const getExternalFile = async ({ data, req, uploadConfig }: Args): Promise<File> => {\n const { filename, url } = data\n\n if (typeof url === 'string') {\n let fileURL = url\n if (!url.startsWith('http')) {\n const baseUrl = req.headers.get('origin') || `${req.protocol}://${req.headers.get('host')}`\n fileURL = `${baseUrl}${url}`\n }\n\n const headers = uploadConfig.externalFileHeaderFilter\n ? uploadConfig.externalFileHeaderFilter(Object.fromEntries(new Headers(req.headers)))\n : { cookie: req.headers?.get('cookie') }\n\n const res = await fetch(fileURL, {\n credentials: 'include',\n headers,\n method: 'GET',\n })\n\n if (!res.ok) throw new APIError(`Failed to fetch file from ${fileURL}`, res.status)\n\n const data = await res.arrayBuffer()\n\n return {\n name: filename,\n data: Buffer.from(data),\n mimetype: res.headers.get('content-type') || undefined,\n size: Number(res.headers.get('content-length')) || 0,\n }\n }\n\n throw new APIError('Invalid file url', 400)\n}\n"],"names":["APIError","getExternalFile","data","req","uploadConfig","filename","url","fileURL","startsWith","baseUrl","headers","get","protocol","externalFileHeaderFilter","Object","fromEntries","Headers","cookie","res","fetch","credentials","method","ok","status","arrayBuffer","name","Buffer","from","mimetype","undefined","size","Number"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,QAAQ,QAAQ,qBAAoB;AAO7C,OAAO,MAAMC,kBAAkB,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAEC,YAAY,EAAQ;IACrE,MAAM,EAAEC,QAAQ,EAAEC,GAAG,EAAE,GAAGJ;IAE1B,IAAI,OAAOI,QAAQ,UAAU;QAC3B,IAAIC,UAAUD;QACd,IAAI,CAACA,IAAIE,UAAU,CAAC,SAAS;YAC3B,MAAMC,UAAUN,IAAIO,OAAO,CAACC,GAAG,CAAC,aAAa,CAAC,EAAER,IAAIS,QAAQ,CAAC,GAAG,EAAET,IAAIO,OAAO,CAACC,GAAG,CAAC,QAAQ,CAAC;YAC3FJ,UAAU,CAAC,EAAEE,QAAQ,EAAEH,IAAI,CAAC;QAC9B;QAEA,MAAMI,UAAUN,aAAaS,wBAAwB,GACjDT,aAAaS,wBAAwB,CAACC,OAAOC,WAAW,CAAC,IAAIC,QAAQb,IAAIO,OAAO,MAChF;YAAEO,QAAQd,IAAIO,OAAO,EAAEC,IAAI;QAAU;QAEzC,MAAMO,MAAM,MAAMC,MAAMZ,SAAS;YAC/Ba,aAAa;YACbV;YACAW,QAAQ;QACV;QAEA,IAAI,CAACH,IAAII,EAAE,EAAE,MAAM,IAAItB,SAAS,CAAC,0BAA0B,EAAEO,QAAQ,CAAC,EAAEW,IAAIK,MAAM;QAElF,MAAMrB,OAAO,MAAMgB,IAAIM,WAAW;QAElC,OAAO;YACLC,MAAMpB;YACNH,MAAMwB,OAAOC,IAAI,CAACzB;YAClB0B,UAAUV,IAAIR,OAAO,CAACC,GAAG,CAAC,mBAAmBkB;YAC7CC,MAAMC,OAAOb,IAAIR,OAAO,CAACC,GAAG,CAAC,sBAAsB;QACrD;IACF;IAEA,MAAM,IAAIX,SAAS,oBAAoB;AACzC,EAAC"}
@@ -1,6 +1,4 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import type express from 'express';
3
- import type serveStatic from 'serve-static';
4
2
  import type { ResizeOptions, Sharp } from 'sharp';
5
3
  import type { TypeWithID } from '../collections/config/types.js';
6
4
  import type { PayloadRequestWithData } from '../types/index.js';
@@ -97,7 +95,6 @@ export type UploadConfig = {
97
95
  mimeTypes?: string[];
98
96
  resizeOptions?: ResizeOptions;
99
97
  staticDir?: string;
100
- staticOptions?: serveStatic.ServeStaticOptions<express.Response<any, Record<string, any>>>;
101
98
  trimOptions?: ImageUploadTrimOptions;
102
99
  };
103
100
  export type SanitizedUploadConfig = UploadConfig & {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/uploads/types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,KAAK,WAAW,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AA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EAAE,MAAM,CAAA;CACb,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/uploads/types.ts"],"sourcesContent":["import type express from 'express'\nimport type serveStatic from 'serve-static'\nimport type { ResizeOptions, Sharp } from 'sharp'\n\nimport type { TypeWithID } from '../collections/config/types.js'\nimport type { PayloadRequestWithData } from '../types/index.js'\n\nexport type FileSize = {\n filename: null | string\n filesize: null | number\n height: null | number\n mimeType: null | string\n width: null | number\n}\n\nexport type FileSizes = {\n [size: string]: FileSize\n}\n\nexport type FileData = {\n filename: string\n filesize: number\n height: number\n mimeType: string\n sizes: FileSizes\n tempFilePath?: string\n url?: string\n width: number\n}\n\nexport type ProbedImageSize = {\n height: number\n width: number\n}\n\n/**\n * Params sent to the sharp toFormat() function\n * @link https://sharp.pixelplumbing.com/api-output#toformat\n */\nexport type ImageUploadFormatOptions = {\n format: Parameters<Sharp['toFormat']>[0]\n options?: Parameters<Sharp['toFormat']>[1]\n}\n\n/**\n * Params sent to the sharp trim() function\n * @link https://sharp.pixelplumbing.com/api-resize#trim\n */\nexport type ImageUploadTrimOptions = Parameters<Sharp['trim']>[0]\n\nexport type ImageSize = Omit<ResizeOptions, 'withoutEnlargement'> & {\n /**\n * @deprecated prefer position\n */\n crop?: string // comes from sharp package\n formatOptions?: ImageUploadFormatOptions\n name: string\n trimOptions?: ImageUploadTrimOptions\n /**\n * When an uploaded image is smaller than the defined image size, we have 3 options:\n *\n * `undefined | false | true`\n *\n * 1. `undefined` [default]: uploading images with smaller width AND height than the image size will return null\n * 2. `false`: always enlarge images to the image size\n * 3. `true`: if the image is smaller than the image size, return the original image\n */\n withoutEnlargement?: ResizeOptions['withoutEnlargement']\n}\n\nexport type GetAdminThumbnail = (args: { doc: Record<string, unknown> }) => false | null | string\n\nexport type UploadConfig = {\n /**\n * The adapter to use for uploads.\n */\n adapter?: string\n /**\n * Represents an admin thumbnail, which can be either a React component or a string.\n * - If a string, it should be one of the image size names.\n * - If a React component, register a function that generates the thumbnail URL using the `useAdminThumbnail` hook.\n **/\n adminThumbnail?: GetAdminThumbnail | string\n crop?: boolean\n disableLocalStorage?: boolean\n /**\n * Accepts existing headers and can filter/modify them.\n *\n * Useful for adding custom headers to fetch from external providers.\n */\n externalFileHeaderFilter?: (headers: Record<string, string>) => Record<string, string>\n filesRequiredOnCreate?: boolean\n focalPoint?: boolean\n /** Options for original upload file only. For sizes, set each formatOptions individually. */\n formatOptions?: ImageUploadFormatOptions\n handlers?: ((\n req: PayloadRequestWithData,\n args: { doc: TypeWithID; params: { collection: string; filename: string } },\n ) => Promise<Response> | Response)[]\n imageSizes?: ImageSize[]\n mimeTypes?: string[]\n resizeOptions?: ResizeOptions\n staticDir?: string\n staticOptions?: serveStatic.ServeStaticOptions<express.Response<any, Record<string, any>>>\n trimOptions?: ImageUploadTrimOptions\n}\n\nexport type SanitizedUploadConfig = UploadConfig & {\n staticDir: UploadConfig['staticDir']\n}\n\nexport type File = {\n data: Buffer\n mimetype: string\n name: string\n size: number\n}\n\nexport type FileToSave = {\n buffer: Buffer\n path: string\n}\n"],"names":[],"rangeMappings":"","mappings":"AAsHA,WAGC"}
1
+ {"version":3,"sources":["../../src/uploads/types.ts"],"sourcesContent":["import type { ResizeOptions, Sharp } from 'sharp'\n\nimport type { TypeWithID } from '../collections/config/types.js'\nimport type { PayloadRequestWithData } from '../types/index.js'\n\nexport type FileSize = {\n filename: null | string\n filesize: null | number\n height: null | number\n mimeType: null | string\n width: null | number\n}\n\nexport type FileSizes = {\n [size: string]: FileSize\n}\n\nexport type FileData = {\n filename: string\n filesize: number\n height: number\n mimeType: string\n sizes: FileSizes\n tempFilePath?: string\n url?: string\n width: number\n}\n\nexport type ProbedImageSize = {\n height: number\n width: number\n}\n\n/**\n * Params sent to the sharp toFormat() function\n * @link https://sharp.pixelplumbing.com/api-output#toformat\n */\nexport type ImageUploadFormatOptions = {\n format: Parameters<Sharp['toFormat']>[0]\n options?: Parameters<Sharp['toFormat']>[1]\n}\n\n/**\n * Params sent to the sharp trim() function\n * @link https://sharp.pixelplumbing.com/api-resize#trim\n */\nexport type ImageUploadTrimOptions = Parameters<Sharp['trim']>[0]\n\nexport type ImageSize = Omit<ResizeOptions, 'withoutEnlargement'> & {\n /**\n * @deprecated prefer position\n */\n crop?: string // comes from sharp package\n formatOptions?: ImageUploadFormatOptions\n name: string\n trimOptions?: ImageUploadTrimOptions\n /**\n * When an uploaded image is smaller than the defined image size, we have 3 options:\n *\n * `undefined | false | true`\n *\n * 1. `undefined` [default]: uploading images with smaller width AND height than the image size will return null\n * 2. `false`: always enlarge images to the image size\n * 3. `true`: if the image is smaller than the image size, return the original image\n */\n withoutEnlargement?: ResizeOptions['withoutEnlargement']\n}\n\nexport type GetAdminThumbnail = (args: { doc: Record<string, unknown> }) => false | null | string\n\nexport type UploadConfig = {\n /**\n * The adapter to use for uploads.\n */\n adapter?: string\n /**\n * Represents an admin thumbnail, which can be either a React component or a string.\n * - If a string, it should be one of the image size names.\n * - If a React component, register a function that generates the thumbnail URL using the `useAdminThumbnail` hook.\n **/\n adminThumbnail?: GetAdminThumbnail | string\n crop?: boolean\n disableLocalStorage?: boolean\n /**\n * Accepts existing headers and can filter/modify them.\n *\n * Useful for adding custom headers to fetch from external providers.\n */\n externalFileHeaderFilter?: (headers: Record<string, string>) => Record<string, string>\n filesRequiredOnCreate?: boolean\n focalPoint?: boolean\n /** Options for original upload file only. For sizes, set each formatOptions individually. */\n formatOptions?: ImageUploadFormatOptions\n handlers?: ((\n req: PayloadRequestWithData,\n args: { doc: TypeWithID; params: { collection: string; filename: string } },\n ) => Promise<Response> | Response)[]\n imageSizes?: ImageSize[]\n mimeTypes?: string[]\n resizeOptions?: ResizeOptions\n staticDir?: string\n trimOptions?: ImageUploadTrimOptions\n}\n\nexport type SanitizedUploadConfig = UploadConfig & {\n staticDir: UploadConfig['staticDir']\n}\n\nexport type File = {\n data: Buffer\n mimetype: string\n name: string\n size: number\n}\n\nexport type FileToSave = {\n buffer: Buffer\n path: string\n}\n"],"names":[],"rangeMappings":"","mappings":"AAmHA,WAGC"}
@@ -1 +1 @@
1
- {"version":3,"file":"isReactComponent.d.ts","sourceRoot":"","sources":["../../src/utilities/isReactComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,gCAAgC,CAAC,CAAC,SAAS,GAAG,EAC5D,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,CAUhB;AAED,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,GAAG,EAClD,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,CAGhB;AAED,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,GAAG,EACtD,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,CAEhB"}
1
+ {"version":3,"file":"isReactComponent.d.ts","sourceRoot":"","sources":["../../src/utilities/isReactComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAoB9B,wBAAgB,gCAAgC,CAAC,CAAC,SAAS,GAAG,EAC5D,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,CAahB;AAED,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,GAAG,EAClD,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,CAKhB;AAED,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,GAAG,EACtD,SAAS,EAAE,KAAK,CAAC,aAAa,GAAG,GAAG,GACnC,SAAS,IAAI,CAAC,CAEhB"}
@@ -1,12 +1,31 @@
1
1
  import { isPlainObject } from './isPlainObject.js';
2
- export function isReactServerComponentOrFunction(component) {
2
+ /*
3
+ For reference: console.log output of [ClientComponent, RSC] array, tested in Turbo and Webpack (14.3.0-canary.37)
4
+
5
+ Both component functions async:
6
+
7
+ Turbo: [ [Function (anonymous)], [AsyncFunction: ExampleServer] ]
8
+ Webpack: [ {}, [AsyncFunction: ExampleServer] ]
9
+
10
+
11
+ Both component functions non-async:
12
+
13
+ Turbo: [ [Function (anonymous)], [Function: ExampleServer] ]
14
+ Webpack: [ {}, [Function: ExampleServer] ]
15
+
16
+ */ export function isReactServerComponentOrFunction(component) {
3
17
  const isClassComponent = typeof component === 'function' && component.prototype && typeof component.prototype.render === 'function';
4
18
  const isFunctionalComponent = typeof component === 'function' && (!component.prototype || !component.prototype.render);
5
- return isClassComponent || isFunctionalComponent;
19
+ // Anonymous functions are Client Components in Turbopack. RSCs should have a name
20
+ const isAnonymousFunction = typeof component === 'function' && component.name === '';
21
+ return (isClassComponent || isFunctionalComponent) && !isAnonymousFunction;
6
22
  }
7
23
  export function isReactClientComponent(component) {
8
- // Do this to test for client components (`use client` directive) bc they import as empty objects
9
- return typeof component === 'object' && !isPlainObject(component);
24
+ const isClientComponentWebpack = typeof component === 'object' && !isPlainObject(component) // In Webpack, client components are {}
25
+ ;
26
+ const isClientComponentTurbo = typeof component === 'function' && component.name === '' // Anonymous functions are Client Components in Turbopack
27
+ ;
28
+ return isClientComponentWebpack || isClientComponentTurbo;
10
29
  }
11
30
  export function isReactComponentOrFunction(component) {
12
31
  return isReactServerComponentOrFunction(component) || isReactClientComponent(component);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/isReactComponent.ts"],"sourcesContent":["import type React from 'react'\n\nimport { isPlainObject } from './isPlainObject.js'\n\nexport function isReactServerComponentOrFunction<T extends any>(\n component: React.ComponentType | any,\n): component is T {\n const isClassComponent =\n typeof component === 'function' &&\n component.prototype &&\n typeof component.prototype.render === 'function'\n\n const isFunctionalComponent =\n typeof component === 'function' && (!component.prototype || !component.prototype.render)\n\n return isClassComponent || isFunctionalComponent\n}\n\nexport function isReactClientComponent<T extends any>(\n component: React.ComponentType | any,\n): component is T {\n // Do this to test for client components (`use client` directive) bc they import as empty objects\n return typeof component === 'object' && !isPlainObject(component)\n}\n\nexport function isReactComponentOrFunction<T extends any>(\n component: React.ComponentType | any,\n): component is T {\n return isReactServerComponentOrFunction(component) || isReactClientComponent(component)\n}\n"],"names":["isPlainObject","isReactServerComponentOrFunction","component","isClassComponent","prototype","render","isFunctionalComponent","isReactClientComponent","isReactComponentOrFunction"],"rangeMappings":";;;;;;;;;;;;","mappings":"AAEA,SAASA,aAAa,QAAQ,qBAAoB;AAElD,OAAO,SAASC,iCACdC,SAAoC;IAEpC,MAAMC,mBACJ,OAAOD,cAAc,cACrBA,UAAUE,SAAS,IACnB,OAAOF,UAAUE,SAAS,CAACC,MAAM,KAAK;IAExC,MAAMC,wBACJ,OAAOJ,cAAc,cAAe,CAAA,CAACA,UAAUE,SAAS,IAAI,CAACF,UAAUE,SAAS,CAACC,MAAM,AAAD;IAExF,OAAOF,oBAAoBG;AAC7B;AAEA,OAAO,SAASC,uBACdL,SAAoC;IAEpC,iGAAiG;IACjG,OAAO,OAAOA,cAAc,YAAY,CAACF,cAAcE;AACzD;AAEA,OAAO,SAASM,2BACdN,SAAoC;IAEpC,OAAOD,iCAAiCC,cAAcK,uBAAuBL;AAC/E"}
1
+ {"version":3,"sources":["../../src/utilities/isReactComponent.ts"],"sourcesContent":["import type React from 'react'\n\nimport { isPlainObject } from './isPlainObject.js'\n\n/*\nFor reference: console.log output of [ClientComponent, RSC] array, tested in Turbo and Webpack (14.3.0-canary.37)\n\nBoth component functions async:\n\nTurbo: [ [Function (anonymous)], [AsyncFunction: ExampleServer] ]\nWebpack: [ {}, [AsyncFunction: ExampleServer] ]\n\n\nBoth component functions non-async:\n\nTurbo: [ [Function (anonymous)], [Function: ExampleServer] ]\nWebpack: [ {}, [Function: ExampleServer] ]\n\n */\n\nexport function isReactServerComponentOrFunction<T extends any>(\n component: React.ComponentType | any,\n): component is T {\n const isClassComponent =\n typeof component === 'function' &&\n component.prototype &&\n typeof component.prototype.render === 'function'\n\n const isFunctionalComponent =\n typeof component === 'function' && (!component.prototype || !component.prototype.render)\n\n // Anonymous functions are Client Components in Turbopack. RSCs should have a name\n const isAnonymousFunction = typeof component === 'function' && component.name === ''\n\n return (isClassComponent || isFunctionalComponent) && !isAnonymousFunction\n}\n\nexport function isReactClientComponent<T extends any>(\n component: React.ComponentType | any,\n): component is T {\n const isClientComponentWebpack = typeof component === 'object' && !isPlainObject(component) // In Webpack, client components are {}\n const isClientComponentTurbo = typeof component === 'function' && component.name === '' // Anonymous functions are Client Components in Turbopack\n\n return isClientComponentWebpack || isClientComponentTurbo\n}\n\nexport function isReactComponentOrFunction<T extends any>(\n component: React.ComponentType | any,\n): component is T {\n return isReactServerComponentOrFunction(component) || isReactClientComponent(component)\n}\n"],"names":["isPlainObject","isReactServerComponentOrFunction","component","isClassComponent","prototype","render","isFunctionalComponent","isAnonymousFunction","name","isReactClientComponent","isClientComponentWebpack","isClientComponentTurbo","isReactComponentOrFunction"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,aAAa,QAAQ,qBAAoB;AAElD;;;;;;;;;;;;;;CAcC,GAED,OAAO,SAASC,iCACdC,SAAoC;IAEpC,MAAMC,mBACJ,OAAOD,cAAc,cACrBA,UAAUE,SAAS,IACnB,OAAOF,UAAUE,SAAS,CAACC,MAAM,KAAK;IAExC,MAAMC,wBACJ,OAAOJ,cAAc,cAAe,CAAA,CAACA,UAAUE,SAAS,IAAI,CAACF,UAAUE,SAAS,CAACC,MAAM,AAAD;IAExF,kFAAkF;IAClF,MAAME,sBAAsB,OAAOL,cAAc,cAAcA,UAAUM,IAAI,KAAK;IAElF,OAAO,AAACL,CAAAA,oBAAoBG,qBAAoB,KAAM,CAACC;AACzD;AAEA,OAAO,SAASE,uBACdP,SAAoC;IAEpC,MAAMQ,2BAA2B,OAAOR,cAAc,YAAY,CAACF,cAAcE,WAAW,uCAAuC;;IACnI,MAAMS,yBAAyB,OAAOT,cAAc,cAAcA,UAAUM,IAAI,KAAK,GAAG,yDAAyD;;IAEjJ,OAAOE,4BAA4BC;AACrC;AAEA,OAAO,SAASC,2BACdV,SAAoC;IAEpC,OAAOD,iCAAiCC,cAAcO,uBAAuBP;AAC/E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload",
3
- "version": "3.0.0-beta.31",
3
+ "version": "3.0.0-beta.33",
4
4
  "description": "Node, React, Headless CMS and Application Framework built on Next.js",
5
5
  "keywords": [
6
6
  "admin panel",
@@ -96,14 +96,13 @@
96
96
  "scmp": "2.1.0",
97
97
  "ts-essentials": "7.0.3",
98
98
  "uuid": "^9.0.1",
99
- "@payloadcms/translations": "3.0.0-beta.31"
99
+ "@payloadcms/translations": "3.0.0-beta.33"
100
100
  },
101
101
  "devDependencies": {
102
102
  "@monaco-editor/react": "4.5.1",
103
103
  "@types/asap": "2.0.0",
104
104
  "@types/body-parser": "1.19.2",
105
105
  "@types/compression": "1.7.2",
106
- "@types/express": "4.17.17",
107
106
  "@types/express-fileupload": "1.4.1",
108
107
  "@types/express-rate-limit": "5.1.3",
109
108
  "@types/express-serve-static-core": "4.17.35",
@@ -132,13 +131,11 @@
132
131
  "get-port": "5.1.1",
133
132
  "graphql-http": "^1.22.0",
134
133
  "mini-css-extract-plugin": "1.6.2",
135
- "next": "^14.3.0-canary.7",
136
134
  "nodemon": "3.0.3",
137
135
  "object.assign": "4.1.4",
138
136
  "object.entries": "1.1.6",
139
137
  "passport-strategy": "1.0.0",
140
138
  "rimraf": "3.0.2",
141
- "serve-static": "1.15.0",
142
139
  "sharp": "0.32.6",
143
140
  "@payloadcms/eslint-config": "1.1.1"
144
141
  },
@@ -169,7 +166,6 @@
169
166
  "dev:postgres": "cross-env PAYLOAD_DATABASE=postgres nodemon",
170
167
  "fix": "eslint \"src/**/*.ts\" --fix",
171
168
  "lint": "eslint \"src/**/*.ts\"",
172
- "pretest": "pnpm build",
173
- "translateNewKeys": "ts-node -T ./scripts/translateNewKeys.ts"
169
+ "pretest": "pnpm build"
174
170
  }
175
171
  }