@sanity/client 6.8.0-pink-lizard.11 → 6.8.0
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 +2 -112
- package/dist/_chunks/{nodeMiddleware-cQeqivr5.cjs → nodeMiddleware-AQIXW8nd.cjs} +2 -2
- package/dist/_chunks/{nodeMiddleware-cQeqivr5.cjs.map → nodeMiddleware-AQIXW8nd.cjs.map} +1 -1
- package/dist/_chunks/{nodeMiddleware-pr0WzTXK.js → nodeMiddleware-cKmlsf7J.js} +2 -2
- package/dist/_chunks/{nodeMiddleware-pr0WzTXK.js.map → nodeMiddleware-cKmlsf7J.js.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-xcYOjX4T.cjs → resolveEditInfo-2keGcJpx.cjs} +2 -1
- package/dist/_chunks/{resolveEditInfo-xcYOjX4T.cjs.map → resolveEditInfo-2keGcJpx.cjs.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-8A-bssPb.js → resolveEditInfo-hVGpZYTe.js} +2 -2
- package/dist/_chunks/{resolveEditInfo-8A-bssPb.js.map → resolveEditInfo-hVGpZYTe.js.map} +1 -1
- package/dist/csm.cjs +1 -1
- package/dist/csm.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/stega.browser.cjs +23 -65
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js +23 -65
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +25 -21
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.js +26 -22
- package/dist/stega.js.map +1 -1
- package/package.json +3 -3
- package/src/csm/resolveEditInfo.ts +2 -1
- package/src/stega/stegaEncodeSourceMap.ts +25 -18
- package/src/csm/applySourceDocuments.test.ts +0 -410
- package/src/csm/createEditUrl.test.ts +0 -39
- package/src/csm/jsonPath.test.ts +0 -39
- package/src/csm/resolveEditUrl.test.ts +0 -537
- package/src/csm/studioPath.test.ts +0 -237
- package/src/stega/encodeIntoResult.test.ts +0 -259
- package/src/stega/vercelStegaCleanAll.test.ts +0 -21
package/README.md
CHANGED
|
@@ -610,6 +610,8 @@ Content Source Maps annotate fragments in your query results with metadata about
|
|
|
610
610
|
>
|
|
611
611
|
> [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]
|
|
612
612
|
|
|
613
|
+
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.
|
|
614
|
+
|
|
613
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.
|
|
614
616
|
|
|
615
617
|
Enabling Content Source Maps is a two-step process:
|
|
@@ -654,118 +656,6 @@ function useContentSourceMap(resultSourceMap: ContentSourceMapping): unknown {
|
|
|
654
656
|
useContentSourceMap(resultSourceMap)
|
|
655
657
|
```
|
|
656
658
|
|
|
657
|
-
#### Using [Visual editing][visual-editing] with steganography
|
|
658
|
-
|
|
659
|
-
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.
|
|
660
|
-
|
|
661
|
-
```ts
|
|
662
|
-
import {createClient} from '@sanity/client/stega'
|
|
663
|
-
|
|
664
|
-
const client = createClient({
|
|
665
|
-
// ...base config options
|
|
666
|
-
stega: {
|
|
667
|
-
// Required: for encoded metadata from Content Source Maps
|
|
668
|
-
enabled: process.env.VERCEL_ENV !== 'production',
|
|
669
|
-
// Required: when "enabled" is true
|
|
670
|
-
// Set it to relative or absolute URL of your Sanity Studio
|
|
671
|
-
studioUrl: '/studio', // or 'https://your-project-name.sanity.studio'
|
|
672
|
-
// For resolving Cross Dataset References you can pass a function returning a URL
|
|
673
|
-
studioUrl: (sourceDocument: ContentSourceMapDocument | ContentSourceMapRemoteDocument) => {
|
|
674
|
-
// If `sourceDocument` has a projectId and 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 your Cross Dataset References are available in a workspace then you can return an object to let the client setup 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 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, control what fields have stega payloads
|
|
693
|
-
filter: (props) => {
|
|
694
|
-
const {resultPath, sourcePath, resultPath} = props
|
|
695
|
-
if (props.sourcePath[0] === 'externalurl') {
|
|
696
|
-
return false
|
|
697
|
-
}
|
|
698
|
-
// The default behavior is packaged into `filterDefault`, allowing you enable encoding fields that are skipped by default
|
|
699
|
-
return props.filterDefault(props)
|
|
700
|
-
},
|
|
701
|
-
|
|
702
|
-
// Optional, logs 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'},
|
|
713
|
-
})
|
|
714
|
-
```
|
|
715
|
-
|
|
716
|
-
#### Creating Studio edit intent links
|
|
717
|
-
|
|
718
|
-
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.
|
|
719
|
-
|
|
720
|
-
```ts
|
|
721
|
-
import {createClient} from '@sanity/client' // or '@sanity/client/stega'
|
|
722
|
-
import {resolveEditUrl} from '@sanity/client/csm'
|
|
723
|
-
|
|
724
|
-
const client = createClient({
|
|
725
|
-
// ... standard client config
|
|
726
|
-
// Required: otherwise the `resultSourceMap` property will be empty on `client.fetch`
|
|
727
|
-
resultSourceMap: 'withKeyArraySelector',
|
|
728
|
-
})
|
|
729
|
-
const {result, resultSourceMap} = await client.fetch(
|
|
730
|
-
`*[_type == "author" && slug.current == $slug][0]{name, pictures}`,
|
|
731
|
-
{slug: 'john-doe'},
|
|
732
|
-
// Required, otherwise you can't access `resultSourceMap`
|
|
733
|
-
{filterResponse: false},
|
|
734
|
-
)
|
|
735
|
-
|
|
736
|
-
// The `result` looks like this:
|
|
737
|
-
const result = {
|
|
738
|
-
name: 'John Doe',
|
|
739
|
-
pictures: [
|
|
740
|
-
{
|
|
741
|
-
_type: 'image',
|
|
742
|
-
alt: 'A picture of exactly what you think someone named John Doe would look like',
|
|
743
|
-
_key: 'cee5fbb69da2',
|
|
744
|
-
asset: {
|
|
745
|
-
_ref: 'image-a75b03fdd5b5fa36947bf2b776a542e0c940f682-1000x1500-jpg',
|
|
746
|
-
_type: 'reference',
|
|
747
|
-
},
|
|
748
|
-
},
|
|
749
|
-
],
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
// The URL resolver needs to know what the current document is, and the base URL of your Sanity Studio
|
|
753
|
-
const {projectId, dataset} = client.config()
|
|
754
|
-
const studioUrl = 'https://your-project-name.sanity.studio'
|
|
755
|
-
|
|
756
|
-
resolveEditUrl({
|
|
757
|
-
projectId,
|
|
758
|
-
dataset,
|
|
759
|
-
studioUrl,
|
|
760
|
-
resultSourceMap,
|
|
761
|
-
// The path to the field you want to edit, you can pass a string
|
|
762
|
-
resultPath: 'pictures[0].alt',
|
|
763
|
-
// Or an array of segments
|
|
764
|
-
resultPath: ['pictures', 0, 'alt'],
|
|
765
|
-
})
|
|
766
|
-
// ^? 'https://your-project-name.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=author;path=pictures[_key=="cee5fbb69da2"].alt'
|
|
767
|
-
```
|
|
768
|
-
|
|
769
659
|
### Listening to queries
|
|
770
660
|
|
|
771
661
|
```js
|
|
@@ -1860,7 +1860,7 @@ function defineCreateClientExports(envMiddleware, ClassConstructor) {
|
|
|
1860
1860
|
};
|
|
1861
1861
|
}
|
|
1862
1862
|
var name = "@sanity/client";
|
|
1863
|
-
var version = "6.8.0
|
|
1863
|
+
var version = "6.8.0";
|
|
1864
1864
|
const middleware = [middleware$1.debug({
|
|
1865
1865
|
verbose: true,
|
|
1866
1866
|
namespace: "sanity:client"
|
|
@@ -1894,4 +1894,4 @@ exports.defaultConfig = defaultConfig;
|
|
|
1894
1894
|
exports.defineCreateClientExports = defineCreateClientExports;
|
|
1895
1895
|
exports.middleware = middleware;
|
|
1896
1896
|
exports.printNoDefaultExport = printNoDefaultExport;
|
|
1897
|
-
//# sourceMappingURL=nodeMiddleware-
|
|
1897
|
+
//# sourceMappingURL=nodeMiddleware-AQIXW8nd.cjs.map
|