@sanity/client
Advanced tools
Comparing version 6.19.1 to 6.19.2
{ | ||
"name": "@sanity/client", | ||
"version": "6.19.1", | ||
"version": "6.19.2", | ||
"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,7 +130,7 @@ }, | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@sanity/pkg-utils": "^6.8.18", | ||
"@sanity/pkg-utils": "^6.9.3", | ||
"@types/json-diff": "^1.0.3", | ||
"@types/node": "^20.8.8", | ||
"@typescript-eslint/eslint-plugin": "^7.11.0", | ||
"@typescript-eslint/parser": "^7.11.0", | ||
"@typescript-eslint/eslint-plugin": "^7.12.0", | ||
"@typescript-eslint/parser": "^7.12.0", | ||
"@vercel/stega": "0.1.2", | ||
@@ -148,3 +148,3 @@ "@vitest/coverage-v8": "1.6.0", | ||
"nock": "^13.5.4", | ||
"prettier": "^3.2.5", | ||
"prettier": "^3.3.1", | ||
"prettier-plugin-packagejson": "^2.5.0", | ||
@@ -154,3 +154,3 @@ "rimraf": "^5.0.1", | ||
"sse-channel": "^4.0.0", | ||
"terser": "^5.31.0", | ||
"terser": "^5.31.1", | ||
"typescript": "5.4.5", | ||
@@ -157,0 +157,0 @@ "vitest": "1.6.0", |
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
2237657
1834
Updatedget-it@^8.6.0