Skip to content

Commit

Permalink
fix: add release notes
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Jacobsen <174970+mmgj@users.noreply.github.com>
Co-authored-by: tarungangwani <7750305+tarungangwani@users.noreply.github.com>
Co-authored-by: even westvang <even@sanity.io>
  • Loading branch information
4 people committed May 3, 2023
1 parent 284c845 commit 53533f5
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ jobs:
cache: npm
- run: npm ci
# Branches that will release new versions are defined in .releaserc.json
- run: npx semantic-release --dry-run --debug
- run: npx semantic-release
# Don't allow interrupting the release step if the job is cancelled, as it can lead to an inconsistent state
# e.g. git tags were pushed but it exited before `npm publish`
if: always()
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@
All notable changes to this project will be documented in this file. See
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [6.0.0](https://github.com/sanity-io/client/compare/v5.4.2...v6.0.0) (2023-05-03)

### ⚠ BREAKING CHANGES

- `useCdn` is now set to `true` by default. Our CDN ensures your content has reliably, world-wide delivery by caching queries made from your front-end. If you require fresh data for every query, perhaps for testing purposes, add `useCdn: false` to your configuration.
- Client will now automatically retry all GET/HEAD requests as well as queries if the server responds with a 429, 502 or 503 status code - as well as on socket/DNS errors. Previously, the client would immediately throw an error. If you have application-level retry code, you should either disable the retrying in the client by passing `{maxRetries: 0}`, or remove the custom retry code and potentially alter the `retryDelay` and `maxRetries` options to match your wanted behavior.

[The migration guide outlines every breaking change and how to migrate your code](https://github.com/sanity-io/client#from-v5)

### Introducing Content Source Maps

> **Note**
>
> Content Source Maps are available for select [Sanity enterprise customers](https://www.sanity.io/enterprise?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch). [Contact our sales team for more information.](https://www.sanity.io/contact/sales?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch)
![](https://i.imgur.com/wt95U5Q.jpg)

Content Source Maps are an optional layer of contextual metadata sent with queries to enable use cases such as [Visual Editing](https://www.sanity.io/blog/visual-editing-sanity-vercel?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch), tracing content lineage, and more. Our implementation of Content Source Maps are based on an [open standard posted on GitHub](https://github.com/sanity-io/content-source-maps), and you can read [the API documentation here](https://#https://www.sanity.io/docs/content-source-maps?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch). To get started with Content Source Maps, check out the documentation in the README file.

### Features

- add automatic retrying of 429, 502, 503 (#199)

### Bug Fixes

- make useCdn use true by default (#191)
- undeprecate request() (#205)

## [5.4.2](https://github.com/sanity-io/client/compare/v5.4.1...v5.4.2) (2023-04-03)

### Bug Fixes
Expand Down
85 changes: 73 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
// token: process.env.SANITY_SECRET_TOKEN // Only if you want to update content with the client
})

Expand Down Expand Up @@ -65,6 +65,7 @@ export async function updateDocumentTitle(_id, title) {
- [UMD](#umd)
- [Specifying API version](#specifying-api-version)
- [Performing queries](#performing-queries)
- [Fetching Content Source Maps](#fetching-content-source-maps)
- [Listening to queries](#listening-to-queries)
- [Fetch a single document](#fetch-a-single-document)
- [Fetch multiple documents in one go](#fetch-multiple-documents-in-one-go)
Expand Down Expand Up @@ -132,7 +133,7 @@ const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})

const data = await client.fetch(`count(*)`)
Expand All @@ -148,7 +149,7 @@ const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})

client
Expand All @@ -166,7 +167,7 @@ const config: ClientConfig = {
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
}
const client = createClient(config)

Expand All @@ -186,7 +187,7 @@ const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})

const schema = z.number()
Expand All @@ -213,7 +214,7 @@ const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})

const data = await client.fetch<number>(`count(*)`)
Expand Down Expand Up @@ -241,7 +242,7 @@ const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})

const data = await client.fetch<number>(`count(*)`)
Expand Down Expand Up @@ -274,7 +275,7 @@ export default async function handler(req: NextRequest) {
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})

const count = await client.fetch<number>(`count(*)`)
Expand Down Expand Up @@ -305,7 +306,7 @@ Using [esm.sh] you can either load the client using a `<script type="module">` t
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})
const data = await client.fetch(`count(*)`)
Expand All @@ -324,7 +325,7 @@ const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})

const data = await client.fetch(`count(*)`)
Expand All @@ -346,7 +347,7 @@ Loading the UMD script creates a `SanityClient` global that have the same export
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})
client.fetch(`count(*)`).then((data) => console.log(`Number of documents: ${data}`))
Expand All @@ -367,7 +368,7 @@ The `require-unpkg` library lets you consume `npm` packages from `unpkg.com` sim
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2022-01-12', // use current date (YYYY-MM-DD) to target the latest API version
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
})
const data = await client.fetch(`count(*)`)
Expand Down Expand Up @@ -404,6 +405,60 @@ client.fetch(query, params).then((bikes) => {

Perform a query using the given parameters (if any).

### Fetching Content Source Maps

Content Source Maps annotate fragments in your query results with metadata about its origin: the field, document, and dataset it originated from.

> **Note**
>
> [Content Source Maps][content-source-maps-intro] are available [as an API][content-source-maps] for select [Sanity enterprise customers][enterprise-cta]. [Contact our sales team for more information.][sales-cta]
A high level API using Content Source Maps for [Visual editing][visual-editing] is also available in [`@sanity/preview-kit/client`][preview-kit-client]. It offers both a turn-key solution and a flexible API for custom experiences.

Read the [Content Source Maps introduction][content-source-maps-intro] before diving in, and keep the [Content Source Maps reference][content-source-maps] handy.

Enabling Content Source Maps is a two-step process:

1. Update your client configuration with `resultSourceMap`.

```js
import {createClient} from '@sanity/client'

const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset-name',
useCdn: true, // set to `false` to bypass the edge cache
apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
resultSourceMap: true, // tells the API to start sending source maps, if available
})
```

2. On `client.fetch` calls add `{filterResponse: false}` to return the full response on queries.

```js
// Before
// const result = await client.fetch(query, params)
// After adding `filterResponse: false`
const {result, resultSourceMap} = await client.fetch(query, params, {filterResponse: false})
// Build something cool with the source map
console.log(resultSourceMap)
```

Once enabled, the `resultSourceMap` property will always exist on the response, given your `apiVersion` is recent enough. If there is no source map, it will be an empty object. There's also a TypeScript definition for it:
```ts
import type {ContentSourceMapping} from '@sanity/client'
const {result, resultSourceMap} = await client.fetch(query, params, {filterResponse: false})
function useContentSourceMap(resultSourceMap: ContentSourceMapping): unknown {
// Sky's the limit
}

useContentSourceMap(resultSourceMap)
```

### Listening to queries

```js
Expand Down Expand Up @@ -1242,3 +1297,9 @@ await client.request<void>({uri: '/auth/logout', method: 'POST'})
[groqd]: https://github.com/FormidableLabs/groqd#readme
[AbortSignal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
[AbortController]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
[visual-editing]: https://www.sanity.io/docs/vercel-visual-editing?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
[content-source-maps]: https://www.sanity.io/docs/content-source-maps?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
[content-source-maps-intro]: https://www.sanity.io/blog/content-source-maps-announce?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
[preview-kit-client]: https://github.com/sanity-io/preview-kit#sanitypreview-kitclient
[sales-cta]: https://www.sanity.io/contact/sales?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
[enterprise-cta]: https://www.sanity.io/enterprise?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch

0 comments on commit 53533f5

Please sign in to comment.