@sanity/client 6.9.1 → 6.9.2
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/README.md +125 -10
- package/dist/_chunks/{nodeMiddleware-_IDbqRDk.js → nodeMiddleware-Od3pONaJ.js} +2 -2
- package/dist/_chunks/{nodeMiddleware-_IDbqRDk.js.map → nodeMiddleware-Od3pONaJ.js.map} +1 -1
- package/dist/_chunks/{nodeMiddleware-xi7HzSDh.cjs → nodeMiddleware-k4wmk2Ss.cjs} +2 -2
- package/dist/_chunks/{nodeMiddleware-xi7HzSDh.cjs.map → nodeMiddleware-k4wmk2Ss.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +1 -1
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.d.ts +1191 -1163
- package/dist/stega.js +2 -2
- package/dist/stega.js.map +1 -1
- package/package.json +14 -15
- package/src/stega/SanityStegaClient.ts +11 -3
- package/src/stega/index.browser.ts +1 -0
- package/src/stega/index.ts +1 -0
- package/src/stega/shared.ts +12 -0
package/README.md
CHANGED
|
@@ -606,13 +606,11 @@ Which changes the result to be:
|
|
|
606
606
|
|
|
607
607
|
Content Source Maps annotate fragments in your query results with metadata about its origin: the field, document, and dataset it originated from.
|
|
608
608
|
|
|
609
|
-
>
|
|
609
|
+
> [!IMPORTANT]
|
|
610
610
|
>
|
|
611
|
-
>
|
|
611
|
+
> Content Source Maps are supported in the Content Lake API versions `2021-03-25` and later.
|
|
612
612
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
Read the [Content Source Maps introduction][content-source-maps-intro] before diving in, and keep the [Content Source Maps reference][content-source-maps] handy.
|
|
613
|
+
Before diving in, review the [Content Source Maps introduction][content-source-maps-intro] and keep the [Content Source Maps reference][content-source-maps] within reach for a quick lookup.
|
|
616
614
|
|
|
617
615
|
Enabling Content Source Maps is a two-step process:
|
|
618
616
|
|
|
@@ -625,7 +623,7 @@ Enabling Content Source Maps is a two-step process:
|
|
|
625
623
|
projectId: 'your-project-id',
|
|
626
624
|
dataset: 'your-dataset-name',
|
|
627
625
|
useCdn: true, // set to `false` to bypass the edge cache
|
|
628
|
-
apiVersion: '
|
|
626
|
+
apiVersion: '2021-03-25', // use current date (YYYY-MM-DD) to target the latest API version
|
|
629
627
|
resultSourceMap: true, // tells the API to start sending source maps, if available
|
|
630
628
|
})
|
|
631
629
|
```
|
|
@@ -642,7 +640,8 @@ Enabling Content Source Maps is a two-step process:
|
|
|
642
640
|
console.log(resultSourceMap)
|
|
643
641
|
```
|
|
644
642
|
|
|
645
|
-
|
|
643
|
+
If your `apiVersion` is `2021-03-25` or later, the `resultSourceMap` property will always exist in the response after enabling it. If there is no source map, `resultSourceMap` is an empty object.
|
|
644
|
+
This is the corresponding TypeScript definition:
|
|
646
645
|
|
|
647
646
|
```ts
|
|
648
647
|
import type {ContentSourceMapping} from '@sanity/client'
|
|
@@ -656,6 +655,125 @@ function useContentSourceMap(resultSourceMap: ContentSourceMapping): unknown {
|
|
|
656
655
|
useContentSourceMap(resultSourceMap)
|
|
657
656
|
```
|
|
658
657
|
|
|
658
|
+
#### Using [Visual editing][visual-editing] with steganography
|
|
659
|
+
|
|
660
|
+
A turnkey integration with [Visual editing][visual-editing] is available in [`@sanity/client/stega`]. It creates edit intent links for all the string values in your query result, using [steganography](https://npmjs.com/package/@vercel/stega) under the hood.
|
|
661
|
+
|
|
662
|
+
```ts
|
|
663
|
+
import {createClient} from '@sanity/client/stega'
|
|
664
|
+
|
|
665
|
+
const client = createClient({
|
|
666
|
+
// ...base config options
|
|
667
|
+
stega: {
|
|
668
|
+
// If you use Vercel Visual Editing, we recommend enabling it for Preview deployments
|
|
669
|
+
enabled: process.env.VERCEL_ENV === 'preview',
|
|
670
|
+
// Required: Set it to the relative or absolute URL of your Sanity Studio instance
|
|
671
|
+
studioUrl: '/studio', // or 'https://your-project-name.sanity.studio'
|
|
672
|
+
// To resolve Cross Dataset References, pass a function returning a URL
|
|
673
|
+
studioUrl: (sourceDocument: ContentSourceMapDocument | ContentSourceMapRemoteDocument) => {
|
|
674
|
+
// If `sourceDocument` has a projectId and a dataset, then it's a Cross Dataset Reference
|
|
675
|
+
if (source._projectId && source._dataset) {
|
|
676
|
+
return 'https://acme-global.sanity.studio'
|
|
677
|
+
}
|
|
678
|
+
return 'https://acme-store.sanity.studio'
|
|
679
|
+
},
|
|
680
|
+
// If your Studio has Workspaces: https://www.sanity.io/docs/workspaces
|
|
681
|
+
// and if your Cross Dataset References are available in a workspace, you can return an object to let the client set up the URL
|
|
682
|
+
studioUrl: (sourceDocument) => {
|
|
683
|
+
// This organization has a single studio with everything organized in workspaces
|
|
684
|
+
const baseUrl = 'https://acme.sanity.studio'
|
|
685
|
+
// If `sourceDocument` has a projectId and a dataset, then it's a Cross Dataset Reference
|
|
686
|
+
if (source._projectId && source._dataset) {
|
|
687
|
+
return {baseUrl, workspace: 'global'}
|
|
688
|
+
}
|
|
689
|
+
return {baseUrl, workspace: 'store'}
|
|
690
|
+
},
|
|
691
|
+
|
|
692
|
+
// Optional, to control which fields have stega payloads
|
|
693
|
+
filter: (props) => {
|
|
694
|
+
const {resultPath, sourcePath, sourceDocument, value} = props
|
|
695
|
+
if (sourcePath[0] === 'externalurl') {
|
|
696
|
+
return false
|
|
697
|
+
}
|
|
698
|
+
// The default behavior is packaged into `filterDefault`, allowing you to enable encoding fields that are skipped by default
|
|
699
|
+
return props.filterDefault(props)
|
|
700
|
+
},
|
|
701
|
+
|
|
702
|
+
// Optional, to log what's encoded and what isn't
|
|
703
|
+
// logger: console,
|
|
704
|
+
},
|
|
705
|
+
})
|
|
706
|
+
|
|
707
|
+
// Disable on demand
|
|
708
|
+
client.config({stega: {enabled: false}})
|
|
709
|
+
|
|
710
|
+
// New client with different stega settings
|
|
711
|
+
const debugClient = client.withConfig({
|
|
712
|
+
stega: {studioUrl: 'https://your-project-name.sanity.studio', logger: console},
|
|
713
|
+
})
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
Removing stega from part of the result:
|
|
717
|
+
|
|
718
|
+
```ts
|
|
719
|
+
import {vercelStegaCleanAll} from '@sanity/client/stega'
|
|
720
|
+
const result = await client.fetch('*[_type == "video"][0]')
|
|
721
|
+
|
|
722
|
+
// Remove stega from the payload sent to a third party library
|
|
723
|
+
const videoAsset = vercelStegaCleanAll(result.videoAsset)
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
#### Creating Studio edit intent links
|
|
727
|
+
|
|
728
|
+
If you want to create an edit link to something that isn't a string, or a field that isn't rendered directly, like a `slug` used in a URL but not rendered on the page, you can use the `resolveEditUrl` function.
|
|
729
|
+
|
|
730
|
+
```ts
|
|
731
|
+
import {createClient} from '@sanity/client' // or '@sanity/client/stega'
|
|
732
|
+
import {resolveEditUrl} from '@sanity/client/csm'
|
|
733
|
+
|
|
734
|
+
const client = createClient({
|
|
735
|
+
// ... standard client config
|
|
736
|
+
// Required: the new 'withKeyArraySelector' option is used here instead of 'true' so that links to array items and portable text are stable even if the array is reordered
|
|
737
|
+
resultSourceMap: 'withKeyArraySelector',
|
|
738
|
+
})
|
|
739
|
+
const {result, resultSourceMap} = await client.fetch(
|
|
740
|
+
`*[_type == "author" && slug.current == $slug][0]{name, pictures}`,
|
|
741
|
+
{slug: 'john-doe'},
|
|
742
|
+
// Required, otherwise you can't access `resultSourceMap`
|
|
743
|
+
{filterResponse: false},
|
|
744
|
+
)
|
|
745
|
+
|
|
746
|
+
// The `result` looks like this:
|
|
747
|
+
const result = {
|
|
748
|
+
name: 'John Doe',
|
|
749
|
+
pictures: [
|
|
750
|
+
{
|
|
751
|
+
_type: 'image',
|
|
752
|
+
alt: 'A picture of exactly what you think someone named John Doe would look like',
|
|
753
|
+
_key: 'cee5fbb69da2',
|
|
754
|
+
asset: {
|
|
755
|
+
_ref: 'image-a75b03fdd5b5fa36947bf2b776a542e0c940f682-1000x1500-jpg',
|
|
756
|
+
_type: 'reference',
|
|
757
|
+
},
|
|
758
|
+
},
|
|
759
|
+
],
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
const studioUrl = 'https://your-project-name.sanity.studio'
|
|
763
|
+
|
|
764
|
+
resolveEditUrl({
|
|
765
|
+
// The URL resolver requires the base URL of your Sanity Studio instance
|
|
766
|
+
studioUrl,
|
|
767
|
+
// It also requires a Content Source Map for the query result you want to create an edit intent link for
|
|
768
|
+
resultSourceMap,
|
|
769
|
+
// The path to the field you want to edit. You can pass a string
|
|
770
|
+
resultPath: 'pictures[0].alt',
|
|
771
|
+
// or an array of segments
|
|
772
|
+
resultPath: ['pictures', 0, 'alt'],
|
|
773
|
+
})
|
|
774
|
+
// ^? 'https://your-project-name.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=author;path=pictures[_key=="cee5fbb69da2"].alt'
|
|
775
|
+
```
|
|
776
|
+
|
|
659
777
|
### Listening to queries
|
|
660
778
|
|
|
661
779
|
```js
|
|
@@ -1490,6 +1608,3 @@ await client.request<void>({uri: '/auth/logout', method: 'POST'})
|
|
|
1490
1608
|
[visual-editing]: https://www.sanity.io/docs/vercel-visual-editing?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|
|
1491
1609
|
[content-source-maps]: https://www.sanity.io/docs/content-source-maps?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|
|
1492
1610
|
[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
|
|
1493
|
-
[preview-kit-client]: https://github.com/sanity-io/preview-kit#sanitypreview-kitclient
|
|
1494
|
-
[sales-cta]: https://www.sanity.io/contact/sales?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|
|
1495
|
-
[enterprise-cta]: https://www.sanity.io/enterprise?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch
|
|
@@ -1858,7 +1858,7 @@ function defineCreateClientExports(envMiddleware, ClassConstructor) {
|
|
|
1858
1858
|
};
|
|
1859
1859
|
}
|
|
1860
1860
|
var name = "@sanity/client";
|
|
1861
|
-
var version = "6.9.
|
|
1861
|
+
var version = "6.9.2";
|
|
1862
1862
|
const middleware = [debug({
|
|
1863
1863
|
verbose: true,
|
|
1864
1864
|
namespace: "sanity:client"
|
|
@@ -1879,4 +1879,4 @@ agent({
|
|
|
1879
1879
|
maxTotalSockets: 256
|
|
1880
1880
|
})];
|
|
1881
1881
|
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, defaultConfig, defineCreateClientExports, middleware, printNoDefaultExport };
|
|
1882
|
-
//# sourceMappingURL=nodeMiddleware-
|
|
1882
|
+
//# sourceMappingURL=nodeMiddleware-Od3pONaJ.js.map
|