documents
For use with Netlify Visual Editor only.
connector.documents(opts)
Used to define how to send document updates back to your data source.
To define document model types, use the model API
Searching for information on how to define document model types? Refer to the define.document()
section of the connector.model
API reference doc.
Takes an object where the keys are functions defined by your connector. The object contains the following properties:
Parameter | Description |
---|---|
create | Used to create a document on your data source. |
delete | Used to delete a document on your data source. |
publish | Used to publish a document on your data source. |
update | Used to update a document on your data source. |
Create
Receives a function to be used for specifying logic for creating documents on your data source. The function is passed an object as the first parameter with the following properties:
Property | Description |
---|---|
model | Model representing the document to create. |
state | Object containing data stored in initState when addConnector runs. |
updateOperationFields | Record<string, UpdateOperationField> . A map of update operation fields by field names. |
userContext | Object with information about the current user. |
Your function should use the accessToken
in userContext
to verify and ensure that all changes in the data source are made on behalf of the user. Changes should not use a general management token that is used to read content.
Usage example
Delete
Receives a function to be used for specifying logic for deleting documents on your data source. The function is passed an object as the first parameter with the following properties:
Property | Description |
---|---|
document | Object representing the Document to delete, as stored in the visual editing cache. |
state | Object containing data stored in initState when addConnector runs. |
userContext | Object with information about the current user. |
Your function should use the accessToken
in userContext
to verify and ensure that all changes in the data source are made on behalf of the user. Changes should not use a general management token that is used to read content.
Usage example
Publish
Receives a function to be used for specifying logic for publishing documents on your data source. The function is passed an object as the first parameter with the following properties:
Property | Description |
---|---|
documents | Array of Document objects from the visual editing cache to publish. |
state | Object containing data stored in initState when addConnector runs. |
userContext | Object with information about the current user. |
Your function should use the accessToken
in userContext
to verify and ensure that all changes in the data source are made on behalf of the user. Changes should not use a general management token that is used to read content.
Usage example
Update
Receives a function to be used for specifying logic for updating documents on your data source. The function is passed an object as the first parameter with the following properties:
Property | Description |
---|---|
document | The existing Document from the visual editing cache before any updates are applied. |
getDocument | Method used to get a document by ID. |
operations | Array of UpdateOperation . |
state | Object containing data stored in initState when addConnector runs. |
userContext | Object with information about the current user. |
Your function should use the accessToken
in userContext
to verify and ensure that all changes in the data source are made on behalf of the user. Changes should not use a general management token that is used to read content.