@sanity/client
Advanced tools
Comparing version 6.20.0-canary.0 to 6.20.0
{ | ||
"name": "@sanity/client", | ||
"version": "6.20.0-canary.0", | ||
"version": "6.20.0", | ||
"description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -121,3 +121,3 @@ "keywords": [ | ||
"@sanity/eventsource": "^5.0.2", | ||
"get-it": "^8.5.0", | ||
"get-it": "^8.6.0", | ||
"rxjs": "^7.0.0" | ||
@@ -130,3 +130,3 @@ }, | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@sanity/pkg-utils": "^6.9.2", | ||
"@sanity/pkg-utils": "^6.9.3", | ||
"@types/json-diff": "^1.0.3", | ||
@@ -133,0 +133,0 @@ "@types/node": "^20.8.8", |
179
README.md
@@ -104,2 +104,11 @@ # @sanity/client | ||
- [Set client configuration](#set-client-configuration) | ||
- [Server Side Actions](#server-side-actions) | ||
- [Action options](#action-options) | ||
- [Create Action](#create-action) | ||
- [Delete Action](#delete-action) | ||
- [Discard Action](#discard-action) | ||
- [Edit Action](#edit-action) | ||
- [Publish Action](#publish-action) | ||
- [ReplaceDraft Action](#replacedraft-action) | ||
- [Unpublish Action](#unpublish-action) | ||
- [License](#license) | ||
@@ -1152,2 +1161,172 @@ - [From `v5`](#from-v5) | ||
### Server Side Actions | ||
The Server Side Actions API provides a new interface for creating, updating and publishing documents. It is a wrapper around the [Server Side Actions API](https://www.sanity.io/docs/http-actions). | ||
This API is only available from API version `v2024-05-23`. | ||
#### Action options | ||
The following options are available for actions, and can be applied as the second argument to `action()`. | ||
- `transactionId`: If set, this ID is as transaction ID for the action instead of using an autogenerated one. | ||
- `dryRun` (`true|false`) - default `false`. If true, the mutation will be a dry run - the response will be identical to the one returned had this property been omitted or false (including error responses) but no documents will be affected. | ||
- `skipCrossDatasetReferenceValidation` (`true|false`) - default `false`. If true, the mutation will be skipped validation of cross dataset references. This is useful when you are creating a document that references a document in a different dataset, and you want to skip the validation to avoid an error. | ||
#### Create Action | ||
A document draft can be created by specifying a create action type: | ||
```js | ||
client | ||
.action( | ||
{ | ||
actionType: 'sanity.action.document.create', | ||
publishedId: 'bike-123', | ||
attributes: {name: 'Sanity Tandem Extraordinaire', _type: 'bike', seats: 1}, | ||
ifExists: 'fail', | ||
}, | ||
actionOptions, | ||
) | ||
.then(() => { | ||
console.log('Bike draft created') | ||
}) | ||
.catch((err) => { | ||
console.error('Create draft failed: ', err.message) | ||
}) | ||
``` | ||
#### Delete Action | ||
A published document can be deleted by specifying a delete action type, optionally including some drafts: | ||
```js | ||
client | ||
.action( | ||
{ | ||
actionType: 'sanity.action.document.delete', | ||
publishedId: 'bike-123', | ||
includeDrafts: ['draft.bike-123'], | ||
}, | ||
actionOptions, | ||
) | ||
.then(() => { | ||
console.log('Bike deleted') | ||
}) | ||
.catch((err) => { | ||
console.error('Delete failed: ', err.message) | ||
}) | ||
``` | ||
#### Discard Action | ||
A draft document can be deleted by specifying a discard action type: | ||
```js | ||
client | ||
.action( | ||
{ | ||
actionType: 'sanity.action.document.discard', | ||
draftId: 'draft.bike-123', | ||
}, | ||
actionOptions, | ||
) | ||
.then(() => { | ||
console.log('Bike draft deleted') | ||
}) | ||
.catch((err) => { | ||
console.error('Discard failed: ', err.message) | ||
}) | ||
``` | ||
#### Edit Action | ||
A patch can be applied to an existing document draft or create a new one by specifying an edit action type: | ||
```js | ||
client | ||
.action( | ||
{ | ||
actionType: 'sanity.action.document.edit', | ||
publishedId: 'bike-123', | ||
attributes: {name: 'Sanity Tandem Extraordinaire', _type: 'bike', seats: 2}, | ||
}, | ||
actionOptions, | ||
) | ||
.then(() => { | ||
console.log('Bike draft edited') | ||
}) | ||
.catch((err) => { | ||
console.error('Edit draft failed: ', err.message) | ||
}) | ||
``` | ||
#### Publish Action | ||
A draft document can be published by specifying a publish action type, optionally with revision ID checks: | ||
```js | ||
client | ||
.action( | ||
{ | ||
actionType: 'sanity.action.document.publish', | ||
draftId: 'draft.bike-123', | ||
ifDraftRevisionId: '<previously-known-revision>', | ||
publishedId: 'bike-123', | ||
ifPublishedRevisionId: '<previously-known-revision>', | ||
}, | ||
actionOptions, | ||
) | ||
.then(() => { | ||
console.log('Bike draft published') | ||
}) | ||
.catch((err) => { | ||
console.error('Publish draft failed: ', err.message) | ||
}) | ||
``` | ||
#### ReplaceDraft Action | ||
An existing document draft can be deleted and replaced by a new one by specifying a replaceDraft action type: | ||
```js | ||
client | ||
.action( | ||
{ | ||
actionType: 'sanity.action.document.replaceDraft', | ||
publishedId: 'bike-123', | ||
attributes: {name: 'Sanity Tandem Extraordinaire', _type: 'bike', seats: 1}, | ||
}, | ||
actionOptions, | ||
) | ||
.then(() => { | ||
console.log('Bike draft replaced') | ||
}) | ||
.catch((err) => { | ||
console.error('Replace draft failed: ', err.message) | ||
}) | ||
``` | ||
#### Unpublish Action | ||
A published document can be retracted by specifying an unpublish action type: | ||
```js | ||
client | ||
.action( | ||
{ | ||
actionType: 'sanity.action.document.unpublish', | ||
draftId: 'draft.bike-123', | ||
publishedId: 'bike-123', | ||
}, | ||
actionOptions, | ||
) | ||
.then(() => { | ||
console.log('Bike draft unpublished') | ||
}) | ||
.catch((err) => { | ||
console.error('Unpublish draft failed: ', err.message) | ||
}) | ||
``` | ||
### Uploading assets | ||
@@ -1154,0 +1333,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2241645
0
1834
Updatedget-it@^8.6.0