diff --git a/docs/configuration/collections.mdx b/docs/configuration/collections.mdx index 68e28e14a9..b1aef90d2c 100644 --- a/docs/configuration/collections.mdx +++ b/docs/configuration/collections.mdx @@ -27,8 +27,9 @@ It's often best practice to write your Collections in separate files and then im | **`endpoints`** | Add custom routes to the REST API. [More](/docs/rest-api/overview#custom-endpoints) | | **`graphQL`** | An object with `singularName` and `pluralName` strings used in schema generation. Auto-generated from slug if not defined. | | **`typescript`** | An object with property `interface` as the text used in schema generation. Auto-generated from slug if not defined. | -| **`defaultSort`** | Pass a top-level field to sort by default in the collection List view. Prefix the name of the field with a minus symbol ("-") to sort in descending order. | -| **`pagination`** | Set pagination-specific options for this collection. [More](#pagination) | +| **`defaultSort`** | Pass a top-level field to sort by default in the collection List view. Prefix the name of the field with a minus symbol ("-") to sort in descending order. | +| **`pagination`** | Set pagination-specific options for this collection. [More](#pagination) | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/configuration/globals.mdx b/docs/configuration/globals.mdx index 88c3d902bb..fe14da7295 100644 --- a/docs/configuration/globals.mdx +++ b/docs/configuration/globals.mdx @@ -25,6 +25,7 @@ As with Collection configs, it's often best practice to write your Globals in se | **`endpoints`** | Add custom routes to the REST API. [More](/docs/rest-api/overview#custom-endpoints) | | **`graphQL.name`** | Text used in schema generation. Auto-generated from slug if not defined. | | **`typescript`** | An object with property `interface` as the text used in schema generation. Auto-generated from slug if not defined. | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | _\* An asterisk denotes that a property is required._ diff --git a/docs/configuration/overview.mdx b/docs/configuration/overview.mdx index 71896bb313..0c7db48dca 100644 --- a/docs/configuration/overview.mdx +++ b/docs/configuration/overview.mdx @@ -43,6 +43,7 @@ Payload is a _config-based_, code-first CMS and application framework. The Paylo | `hooks` | Tap into Payload-wide hooks. [More](/docs/hooks/overview) | | `plugins` | An array of Payload plugins. [More](/docs/plugins/overview) | | `endpoints` | An array of custom API endpoints added to the Payload router. [More](/docs/rest-api/overview#custom-endpoints) | +| `custom` | Extension point for adding custom data (e.g. for plugins) | #### Simple example diff --git a/docs/fields/array.mdx b/docs/fields/array.mdx index d42a61a33e..b17c957edd 100644 --- a/docs/fields/array.mdx +++ b/docs/fields/array.mdx @@ -35,7 +35,8 @@ keywords: array, fields, config, configuration, documentation, Content Managemen | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. If enabled, a separate, localized set of all data within this Array will be kept, so there is no need to specify each nested field as `localized`. | | **`required`** | Require this field to have a value. | | **`labels`** | Customize the row labels appearing in the Admin dashboard. | -| **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/blocks.mdx b/docs/fields/blocks.mdx index 1b10b4a32f..7103e57dce 100644 --- a/docs/fields/blocks.mdx +++ b/docs/fields/blocks.mdx @@ -37,6 +37,7 @@ keywords: blocks, fields, config, configuration, documentation, Content Manageme | **`unique`** | Enforce that each entry in the Collection has a unique value for this field. | | **`labels`** | Customize the block row labels appearing in the Admin dashboard. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/checkbox.mdx b/docs/fields/checkbox.mdx index 34baa7b5fb..54f725f23d 100644 --- a/docs/fields/checkbox.mdx +++ b/docs/fields/checkbox.mdx @@ -26,6 +26,7 @@ keywords: checkbox, fields, config, configuration, documentation, Content Manage | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See the [default field admin config](/docs/fields/overview#admin-config) for more details. | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/code.mdx b/docs/fields/code.mdx index 5766f87f48..e70010f149 100644 --- a/docs/fields/code.mdx +++ b/docs/fields/code.mdx @@ -32,6 +32,7 @@ This field uses the `monaco-react` editor syntax highlighting. | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | _\* An asterisk denotes that a property is required._ diff --git a/docs/fields/collapsible.mdx b/docs/fields/collapsible.mdx index e8ab1707c0..8a6a4c8085 100644 --- a/docs/fields/collapsible.mdx +++ b/docs/fields/collapsible.mdx @@ -17,6 +17,7 @@ keywords: row, fields, config, configuration, documentation, Content Management | **`label`** * | A label to render within the header of the collapsible component. This can be a string, function or react component. Function/components receive `({ data, path })` as args. | | **`fields`** * | Array of field types to nest within this Collapsible. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/date.mdx b/docs/fields/date.mdx index f0d1c3ecb0..6e358fb395 100644 --- a/docs/fields/date.mdx +++ b/docs/fields/date.mdx @@ -29,6 +29,7 @@ This field uses [`react-datepicker`](https://www.npmjs.com/package/react-datepic | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | _\* An asterisk denotes that a property is required._ diff --git a/docs/fields/email.mdx b/docs/fields/email.mdx index 2ccb458e31..9e5a305b3a 100644 --- a/docs/fields/email.mdx +++ b/docs/fields/email.mdx @@ -27,6 +27,7 @@ keywords: email, fields, config, configuration, documentation, Content Managemen | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/group.mdx b/docs/fields/group.mdx index 86015433d6..a7dc8f3204 100644 --- a/docs/fields/group.mdx +++ b/docs/fields/group.mdx @@ -25,6 +25,7 @@ keywords: group, fields, config, configuration, documentation, Content Managemen | **`defaultValue`** | Provide an object of data to be used for this field's default value. [More](/docs/fields/overview#default-values) | | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. If enabled, a separate, localized set of all data within this Group will be kept, so there is no need to specify each nested field as `localized`. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/json.mdx b/docs/fields/json.mdx index a35b0c81ec..89a7ace771 100644 --- a/docs/fields/json.mdx +++ b/docs/fields/json.mdx @@ -30,6 +30,7 @@ This field uses the `monaco-react` editor syntax highlighting. | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | _\* An asterisk denotes that a property is required._ diff --git a/docs/fields/number.mdx b/docs/fields/number.mdx index d8b91bcb15..c18c685acd 100644 --- a/docs/fields/number.mdx +++ b/docs/fields/number.mdx @@ -29,6 +29,7 @@ keywords: number, fields, config, configuration, documentation, Content Manageme | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/point.mdx b/docs/fields/point.mdx index 568b932364..ebd4595968 100644 --- a/docs/fields/point.mdx +++ b/docs/fields/point.mdx @@ -30,6 +30,7 @@ The data structure in the database matches the GeoJSON structure to represent po | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/radio.mdx b/docs/fields/radio.mdx index 0255962fbe..664582dd22 100644 --- a/docs/fields/radio.mdx +++ b/docs/fields/radio.mdx @@ -27,6 +27,7 @@ keywords: radio, fields, config, configuration, documentation, Content Managemen | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/relationship.mdx b/docs/fields/relationship.mdx index a0c1ed1d04..bb64160bc4 100644 --- a/docs/fields/relationship.mdx +++ b/docs/fields/relationship.mdx @@ -26,7 +26,7 @@ keywords: relationship, fields, config, configuration, documentation, Content Ma | **`filterOptions`** | A query to filter which options appear in the UI and validate against. [More](#filtering-relationship-options). | | **`hasMany`** | Boolean when, if set to `true`, allows this field to have many relations instead of only one. | | **`min`** | A number for the fewest allowed items during validation when a value is present. Used with `hasMany`. | -| **`max`** | A number for the most allowed items during validation when a value is present. Used with `hasMany`. | +| **`max`** | A number for the most allowed items during validation when a value is present. Used with `hasMany`. | | **`maxDepth`** | Sets a number limit on iterations of related documents to populate when queried. [Depth](/docs/getting-started/concepts#depth) | | **`label`** | Text used as a field label in the Admin panel or an object with keys for each language. | | **`unique`** | Enforce that each entry in the Collection has a unique value for this field. | @@ -40,6 +40,7 @@ keywords: relationship, fields, config, configuration, documentation, Content Ma | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See the [default field admin config](/docs/fields/overview#admin-config) for more details. | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | _\* An asterisk denotes that a property is required._ diff --git a/docs/fields/rich-text.mdx b/docs/fields/rich-text.mdx index ecfd31f8ae..338981a525 100644 --- a/docs/fields/rich-text.mdx +++ b/docs/fields/rich-text.mdx @@ -31,6 +31,7 @@ The Admin component is built on the powerful [`slatejs`](https://docs.slatejs.or | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/row.mdx b/docs/fields/row.mdx index 9823aeacd4..5987e59f3a 100644 --- a/docs/fields/row.mdx +++ b/docs/fields/row.mdx @@ -16,6 +16,7 @@ keywords: row, fields, config, configuration, documentation, Content Management | ---------------- | ----------- | | **`fields`** * | Array of field types to nest within this Row. | | **`admin`** | Admin-specific configuration excluding `description`, `readOnly`, and `hidden`. See the [default field admin config](/docs/fields/overview#admin-config) for more details. | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/select.mdx b/docs/fields/select.mdx index fbfd03326a..a0a92aee0e 100644 --- a/docs/fields/select.mdx +++ b/docs/fields/select.mdx @@ -30,6 +30,7 @@ keywords: select, multi-select, fields, config, configuration, documentation, Co | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See the [default field admin config](/docs/fields/overview#admin-config) for more details. | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | _\* An asterisk denotes that a property is required._ diff --git a/docs/fields/tabs.mdx b/docs/fields/tabs.mdx index a40f4aff2f..9d1a498560 100644 --- a/docs/fields/tabs.mdx +++ b/docs/fields/tabs.mdx @@ -19,6 +19,7 @@ keywords: tabs, fields, config, configuration, documentation, Content Management | ---------------- | ----------- | | **`tabs`** * | Array of tabs to render within this Tabs field. | | **`admin`** | Admin-specific configuration. See the [default field admin config](/docs/fields/overview#admin-config) for more details. | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | #### Tab-specific Config diff --git a/docs/fields/text.mdx b/docs/fields/text.mdx index ccb36cccbe..3c44e26055 100644 --- a/docs/fields/text.mdx +++ b/docs/fields/text.mdx @@ -29,6 +29,7 @@ keywords: text, fields, config, configuration, documentation, Content Management | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/textarea.mdx b/docs/fields/textarea.mdx index bd33a34f10..29005aba66 100644 --- a/docs/fields/textarea.mdx +++ b/docs/fields/textarea.mdx @@ -29,6 +29,7 @@ keywords: textarea, fields, config, configuration, documentation, Content Manage | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See below for [more detail](#admin-config). | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/ui.mdx b/docs/fields/ui.mdx index 61847d6644..7f393ccf82 100644 --- a/docs/fields/ui.mdx +++ b/docs/fields/ui.mdx @@ -29,6 +29,7 @@ With this field, you can also inject custom `Cell` components that appear as add | **`label`** | Human-readable label for this UI field. | | **`admin.components.Field`** | React component to be rendered for this field within the Edit view. [More](/docs/admin/components/#field-component) | | **`admin.components.Cell`** | React component to be rendered as a Cell within collection List views. [More](/docs/admin/components/#field-component) | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/fields/upload.mdx b/docs/fields/upload.mdx index 5c8f2f3d6c..44d0d2e8cf 100644 --- a/docs/fields/upload.mdx +++ b/docs/fields/upload.mdx @@ -41,6 +41,7 @@ keywords: upload, images media, fields, config, configuration, documentation, Co | **`localized`** | Enable localization for this field. Requires [localization to be enabled](/docs/configuration/localization) in the Base config. | | **`required`** | Require this field to have a value. | | **`admin`** | Admin-specific configuration. See the [default field admin config](/docs/fields/overview#admin-config) for more details. | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | *\* An asterisk denotes that a property is required.* diff --git a/docs/rest-api/overview.mdx b/docs/rest-api/overview.mdx index 9e994fa091..bf4219bc11 100644 --- a/docs/rest-api/overview.mdx +++ b/docs/rest-api/overview.mdx @@ -91,6 +91,7 @@ Each endpoint object needs to have: | **`method`** | The lowercase HTTP verb to use: 'get', 'head', 'post', 'put', 'delete', 'connect' or 'options' | | **`handler`** | A function or array of functions to be called with **req**, **res** and **next** arguments. [Express](https://expressjs.com/en/guide/routing.html#route-handlers) | | **`root`** | When `true`, defines the endpoint on the root Express app, bypassing Payload handlers and the `routes.api` subpath. Note: this only applies to top-level endpoints of your Payload config, endpoints defined on `collections` or `globals` cannot be root. | +| **`custom`** | Extension point for adding custom data (e.g. for plugins) | Example: diff --git a/src/collections/config/defaults.ts b/src/collections/config/defaults.ts index 96625710b3..da20e64571 100644 --- a/src/collections/config/defaults.ts +++ b/src/collections/config/defaults.ts @@ -39,6 +39,7 @@ export const defaults = { auth: false, upload: false, versions: false, + custom: {}, }; export const authDefaults = { diff --git a/src/collections/config/schema.ts b/src/collections/config/schema.ts index 2950eff74d..107fa66996 100644 --- a/src/collections/config/schema.ts +++ b/src/collections/config/schema.ts @@ -187,6 +187,7 @@ const collectionSchema = joi.object().keys({ }), joi.boolean(), ), + custom: joi.object().pattern(joi.string(), joi.any()), }); export default collectionSchema; diff --git a/src/collections/config/types.ts b/src/collections/config/types.ts index 2d5f6ddabc..082b57778b 100644 --- a/src/collections/config/types.ts +++ b/src/collections/config/types.ts @@ -304,13 +304,16 @@ export type CollectionConfig = { * @default true */ timestamps?: boolean + /** Extension point to add your custom data. */ + custom?: Record; }; -export interface SanitizedCollectionConfig extends Omit, 'auth' | 'upload' | 'fields' | 'versions'> { +export interface SanitizedCollectionConfig extends Omit, 'auth' | 'upload' | 'fields' | 'versions'| 'endpoints'> { auth: Auth; upload: Upload; fields: Field[]; - versions: SanitizedCollectionVersions + versions: SanitizedCollectionVersions; + endpoints: Omit[]; } export type Collection = { diff --git a/src/config/defaults.ts b/src/config/defaults.ts index 3ffbfd729c..da7d231715 100644 --- a/src/config/defaults.ts +++ b/src/config/defaults.ts @@ -55,4 +55,5 @@ export const defaults: Config = { hooks: {}, localization: false, telemetry: true, + custom: {}, }; diff --git a/src/config/schema.ts b/src/config/schema.ts index eece575e94..33a3ccef05 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -13,6 +13,7 @@ export const endpointsSchema = joi.array().items(joi.object({ joi.array().items(joi.func()), joi.func(), ), + custom: joi.object().pattern(joi.string(), joi.any()), })); export default joi.object({ @@ -162,4 +163,5 @@ export default joi.object({ ), onInit: joi.func(), debug: joi.boolean(), + custom: joi.object().pattern(joi.string(), joi.any()), }); diff --git a/src/config/types.ts b/src/config/types.ts index c54ecf9418..440a79f775 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -189,6 +189,8 @@ export type Endpoint = { * @default false */ root?: boolean; + /** Extension point to add your custom data. */ + custom?: Record; }; export type AdminView = React.ComponentType<{ @@ -527,14 +529,17 @@ export type Config = { telemetry?: boolean; /** A function that is called immediately following startup that receives the Payload instance as its only argument. */ onInit?: (payload: Payload) => Promise | void; + /** Extension point to add your custom data. */ + custom?: Record; }; export type SanitizedConfig = Omit< DeepRequired, - 'collections' | 'globals' + 'collections' | 'globals' | 'endpoint' > & { collections: SanitizedCollectionConfig[]; globals: SanitizedGlobalConfig[]; + endpoints: Endpoint[]; paths: { configDir: string config: string diff --git a/src/fields/config/schema.ts b/src/fields/config/schema.ts index 78011974a4..4f8c5a7ecc 100644 --- a/src/fields/config/schema.ts +++ b/src/fields/config/schema.ts @@ -52,6 +52,7 @@ export const baseField = joi.object().keys({ afterRead: joi.array().items(joi.func()).default([]), }).default(), admin: baseAdminFields.default(), + custom: joi.object().pattern(joi.string(), joi.any()), }).default(); export const idField = baseField.keys({ diff --git a/src/fields/config/types.ts b/src/fields/config/types.ts index b517e1c03b..e0ea264d50 100644 --- a/src/fields/config/types.ts +++ b/src/fields/config/types.ts @@ -121,6 +121,8 @@ export interface FieldBase { read?: FieldAccess; update?: FieldAccess; }; + /** Extension point to add your custom data. */ + custom?: Record; } export type NumberField = FieldBase & { @@ -241,6 +243,8 @@ export type UIField = { } } type: 'ui'; + /** Extension point to add your custom data. */ + custom?: Record; } export type UploadField = FieldBase & { diff --git a/src/globals/config/sanitize.ts b/src/globals/config/sanitize.ts index 321f79530f..095c3d297f 100644 --- a/src/globals/config/sanitize.ts +++ b/src/globals/config/sanitize.ts @@ -51,6 +51,8 @@ const sanitizeGlobals = (collections: CollectionConfig[], globals: GlobalConfig[ } } + if (!sanitizedGlobal.custom) sanitizedGlobal.custom = {}; + // ///////////////////////////////// // Sanitize fields // ///////////////////////////////// diff --git a/src/globals/config/schema.ts b/src/globals/config/schema.ts index 0101308eb2..1d15e9de89 100644 --- a/src/globals/config/schema.ts +++ b/src/globals/config/schema.ts @@ -66,6 +66,7 @@ const globalSchema = joi.object().keys({ }), joi.boolean(), ), + custom: joi.object().pattern(joi.string(), joi.any()), }).unknown(); export default globalSchema; diff --git a/src/globals/config/types.ts b/src/globals/config/types.ts index 67ca97b72b..d7219fc6cb 100644 --- a/src/globals/config/types.ts +++ b/src/globals/config/types.ts @@ -109,10 +109,13 @@ export type GlobalConfig = { } fields: Field[]; admin?: GlobalAdminOptions + /** Extension point to add your custom data. */ + custom?: Record; } -export interface SanitizedGlobalConfig extends Omit, 'fields' | 'versions'> { +export interface SanitizedGlobalConfig extends Omit, 'fields' | 'versions' | 'endpoints'> { fields: Field[] + endpoints: Omit[], versions: SanitizedGlobalVersions } diff --git a/test/config/config.ts b/test/config/config.ts new file mode 100644 index 0000000000..d7d252990f --- /dev/null +++ b/test/config/config.ts @@ -0,0 +1,65 @@ +import { buildConfig } from '../buildConfig'; +import { openAccess } from '../helpers/configHelpers'; +import { Config } from '../../src/config/types'; + +const config: Config = { + collections: [ + { + slug: 'pages', + access: openAccess, + endpoints: [ + { + path: '/hello', + method: 'get', + handler: (_, res): void => { + res.json({ message: 'hi' }); + }, + custom: { examples: [{ type: 'response', value: { message: 'hi' } }] }, + }, + ], + fields: [ + { + name: 'title', + type: 'text', + custom: { description: 'The title of this page' }, + }, + ], + custom: { externalLink: 'https://foo.bar' }, + }, + ], + globals: [ + { + slug: 'my-global', + endpoints: [{ + path: '/greet', + method: 'get', + handler: (req, res): void => { + const { name } = req.query; + res.json({ message: `Hi ${name}!` }); + }, + custom: { params: [{ in: 'query', name: 'name', type: 'string' }] }, + }], + fields: [{ + name: 'title', + type: 'text', + custom: { description: 'The title of my global' }, + }, + ], + custom: { foo: 'bar' }, + }, + ], + endpoints: [ + { + path: '/config', + method: 'get', + root: true, + handler: (req, res): void => { + res.json(req.payload.config); + }, + custom: { description: 'Get the sanitized payload config' }, + }, + ], + custom: { name: 'Customer portal' }, +}; + +export default buildConfig(config); diff --git a/test/config/int.spec.ts b/test/config/int.spec.ts new file mode 100644 index 0000000000..d680bf6f16 --- /dev/null +++ b/test/config/int.spec.ts @@ -0,0 +1,66 @@ +import { initPayloadTest } from '../helpers/configHelpers'; +import payload from '../../src'; + +require('isomorphic-fetch'); + +describe('Config', () => { + beforeAll(async () => { + await initPayloadTest({ __dirname, init: { local: true } }); + }); + + describe('payload config', () => { + it('allows a custom field at the config root', () => { + const { config } = payload; + expect(config.custom).toEqual({ name: 'Customer portal' }); + }); + + it('allows a custom field in the root endpoints', () => { + const [endpoint] = payload.config.endpoints; + + expect(endpoint.custom).toEqual({ description: 'Get the sanitized payload config' }); + }); + }); + + describe('collection config', () => { + it('allows a custom field in collections', () => { + const [collection] = payload.config.collections; + expect(collection.custom).toEqual({ externalLink: 'https://foo.bar' }); + }); + + it('allows a custom field in collection endpoints', () => { + const [collection] = payload.config.collections; + const [endpoint] = collection.endpoints; + + expect(endpoint.custom).toEqual({ examples: [{ type: 'response', value: { message: 'hi' } }] }); + }); + + it('allows a custom field in collection fields', () => { + const [collection] = payload.config.collections; + const [field] = collection.fields; + + expect(field.custom).toEqual({ description: 'The title of this page' }); + }); + }); + + + describe('global config', () => { + it('allows a custom field in globals', () => { + const [global] = payload.config.globals; + expect(global.custom).toEqual({ foo: 'bar' }); + }); + + it('allows a custom field in global endpoints', () => { + const [global] = payload.config.globals; + const [endpoint] = global.endpoints; + + expect(endpoint.custom).toEqual({ params: [{ in: 'query', name: 'name', type: 'string' }] }); + }); + + it('allows a custom field in global fields', () => { + const [global] = payload.config.globals; + const [field] = global.fields; + + expect(field.custom).toEqual({ description: 'The title of my global' }); + }); + }); +});