payload 0.17.2 → 0.17.3
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.
- package/CHANGELOG.md +8 -0
- package/dist/admin/components/elements/DeleteDocument/index.js +5 -2
- package/dist/auth/requestHandlers/me.js +3 -2
- package/dist/collections/config/defaults.d.ts +1 -0
- package/dist/collections/config/defaults.js +2 -1
- package/dist/collections/config/schema.js +6 -1
- package/dist/collections/config/types.d.ts +5 -1
- package/dist/collections/init.js +20 -18
- package/dist/collections/operations/local/create.js +5 -5
- package/dist/collections/operations/local/delete.js +4 -4
- package/dist/collections/operations/local/findByID.js +4 -4
- package/dist/collections/operations/local/findVersionByID.js +5 -5
- package/dist/collections/tests/collections.spec.js +10 -1
- package/dist/collections/tests/endpoints.spec.d.ts +1 -0
- package/dist/collections/tests/endpoints.spec.js +71 -0
- package/dist/config/types.d.ts +6 -1
- package/dist/config/validate.js +1 -2
- package/dist/fields/hooks/beforeChange/promise.js +4 -4
- package/dist/globals/config/sanitize.js +3 -1
- package/dist/globals/config/schema.js +6 -1
- package/dist/globals/config/types.d.ts +2 -1
- package/dist/globals/init.js +9 -6
- package/dist/globals/requestHandlers/globals.spec.js +14 -1
- package/dist/init/mountEndpoints.d.ts +4 -0
- package/dist/init/mountEndpoints.js +9 -0
- package/docs/access-control/collections.mdx +80 -8
- package/docs/access-control/overview.mdx +2 -2
- package/docs/configuration/collections.mdx +8 -7
- package/docs/configuration/globals.mdx +1 -0
- package/docs/fields/overview.mdx +1 -30
- package/docs/rest-api/overview.mdx +46 -0
- package/package.json +2 -2
package/docs/fields/overview.mdx
CHANGED
|
@@ -200,35 +200,6 @@ The `condition` function should return a boolean that will control if the field
|
|
|
200
200
|
}
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
If you are building custom components, and you'd like for your custom components to support conditional logic as well, you can utilize Payload's `withCondition` higher-order function by importing it and using it as follows:
|
|
204
|
-
|
|
205
|
-
```js
|
|
206
|
-
import { withCondition } from 'payload/components/forms';
|
|
207
|
-
|
|
208
|
-
const CustomComponent = () => {
|
|
209
|
-
return (
|
|
210
|
-
<div>
|
|
211
|
-
<p>Hello, on my own, I won't respect my field's conditional logic.<p/>
|
|
212
|
-
<p>But, I will if I'm wrapped with the withCondition HOC as shown below!</p>
|
|
213
|
-
</div>
|
|
214
|
-
)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const CustomComponentWithCondition = withCondition(CustomComponent);
|
|
218
|
-
|
|
219
|
-
const customFieldWithCondition = {
|
|
220
|
-
name: 'myCustomField',
|
|
221
|
-
type: 'text',
|
|
222
|
-
admin: {
|
|
223
|
-
condition: (data) => Boolean(data.enableCustomField),
|
|
224
|
-
components: {
|
|
225
|
-
Field: CustomComponentWithCondition,
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
```
|
|
231
|
-
|
|
232
203
|
### Default values
|
|
233
204
|
|
|
234
205
|
Fields can be prefilled with starting values using the `defaultValue` property. This is used in the admin UI and also on the backend as API requests will be populated with missing or undefined field values. You can assign the defaultValue directly in the field configuration or supply a function for dynamic behavior. Values assigned during a create request on the server are added before validation occurs.
|
|
@@ -243,7 +214,7 @@ Here is an example of a defaultValue function that uses both:
|
|
|
243
214
|
```js
|
|
244
215
|
const translation: {
|
|
245
216
|
en: 'Written by',
|
|
246
|
-
es: '
|
|
217
|
+
es: 'Escrito por',
|
|
247
218
|
};
|
|
248
219
|
|
|
249
220
|
const field = {
|
|
@@ -43,6 +43,8 @@ The `find` endpoint supports the following additional query parameters:
|
|
|
43
43
|
|
|
44
44
|
## Auth Operations
|
|
45
45
|
|
|
46
|
+
Auth enabled collections are also given the following endpoints:
|
|
47
|
+
|
|
46
48
|
| Method | Path | Description |
|
|
47
49
|
| -------- | --------------------------- | ----------- |
|
|
48
50
|
| `POST` | `/api/{collectionSlug}/verify/:token` | [Email verification](/docs/authentication/operations#verify-by-email), if enabled. |
|
|
@@ -72,3 +74,47 @@ In addition to the dynamically generated endpoints above Payload also has REST e
|
|
|
72
74
|
| `GET` | `/api/_preferences/{key}` | Get a preference by key |
|
|
73
75
|
| `POST` | `/api/_preferences/{key}` | Create or update by key |
|
|
74
76
|
| `DELETE` | `/api/_preferences/{key}` | Delete a user preference by key |
|
|
77
|
+
|
|
78
|
+
## Custom Endpoints
|
|
79
|
+
|
|
80
|
+
Additional REST API endpoints can be added to `collections` and `globals` by providing array of `endpoints` in the configuration. These can be used to write additional middleware on existing routes or build custom functionality into Payload apps and plugins.
|
|
81
|
+
|
|
82
|
+
Each endpoint object needs to have:
|
|
83
|
+
|
|
84
|
+
| Property | Description |
|
|
85
|
+
| ---------- | ----------------------------------------- |
|
|
86
|
+
| **`path`** | A string for the endpoint route after the collection or globals slug |
|
|
87
|
+
| **`method`** | The lowercase HTTP verb to use: 'get', 'head', 'post', 'put', 'delete', 'connect' or 'options' |
|
|
88
|
+
| **`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) |
|
|
89
|
+
|
|
90
|
+
Example:
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
|
|
94
|
+
// a collection of 'orders' with an additional route for tracking details, reachable at /api/orders/:id/tracking
|
|
95
|
+
const Orders = {
|
|
96
|
+
slug: 'orders',
|
|
97
|
+
fields: [ /* ... */ ],
|
|
98
|
+
// highlight-start
|
|
99
|
+
endpoints: [
|
|
100
|
+
{
|
|
101
|
+
path: '/:id/tracking',
|
|
102
|
+
method: 'get',
|
|
103
|
+
handler: async (req, res, next) => {
|
|
104
|
+
const tracking = await getTrackingInfo(req.params.id);
|
|
105
|
+
if (tracking) {
|
|
106
|
+
res.status('200').send({ tracking });
|
|
107
|
+
} else {
|
|
108
|
+
res.status('404').send({ error: 'not found' });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
// highlight-end
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
<Banner>
|
|
118
|
+
<strong>Note:</strong><br/>
|
|
119
|
+
**req** will have the **payload** object and can be used inside your endpoint handlers for making calls like req.payload.find() that will make use of access control and hooks.
|
|
120
|
+
</Banner>
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3",
|
|
4
4
|
"description": "Node, React and MongoDB Headless CMS and Application Framework",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"email": "info@payloadcms.com",
|
|
8
8
|
"name": "Payload CMS",
|