@sanity/client 6.7.1 → 6.8.0-pink-lizard.1
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 +79 -2
- package/dist/_chunks/browserMiddleware-Oa7zKwEN.js +1862 -0
- package/dist/_chunks/browserMiddleware-Oa7zKwEN.js.map +1 -0
- package/dist/_chunks/browserMiddleware-zle5A-pb.cjs +1877 -0
- package/dist/_chunks/browserMiddleware-zle5A-pb.cjs.map +1 -0
- package/dist/_chunks/createEditLink-FiifjNgi.cjs +222 -0
- package/dist/_chunks/createEditLink-FiifjNgi.cjs.map +1 -0
- package/dist/_chunks/createEditLink-f3l2nngi.js +212 -0
- package/dist/_chunks/createEditLink-f3l2nngi.js.map +1 -0
- package/dist/_chunks/nodeMiddleware-S6QZVGmT.cjs +1897 -0
- package/dist/_chunks/nodeMiddleware-S6QZVGmT.cjs.map +1 -0
- package/dist/_chunks/nodeMiddleware-XodpBhbR.js +1882 -0
- package/dist/_chunks/nodeMiddleware-XodpBhbR.js.map +1 -0
- package/dist/csm.cjs +71 -0
- package/dist/csm.cjs.map +1 -0
- package/dist/csm.d.ts +248 -0
- package/dist/csm.js +58 -0
- package/dist/csm.js.map +1 -0
- package/dist/index.browser.cjs +13 -1868
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +3 -1858
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +13 -1888
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1878
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.cjs +629 -0
- package/dist/stega.browser.cjs.map +1 -0
- package/dist/stega.browser.js +598 -0
- package/dist/stega.browser.js.map +1 -0
- package/dist/stega.cjs +424 -0
- package/dist/stega.cjs.js +21 -0
- package/dist/stega.cjs.map +1 -0
- package/dist/stega.d.ts +2872 -0
- package/dist/stega.js +393 -0
- package/dist/stega.js.map +1 -0
- package/package.json +42 -2
- package/src/config.ts +6 -0
- package/src/csm/applySourceDocuments.test.ts +820 -0
- package/src/csm/applySourceDocuments.ts +87 -0
- package/src/csm/createEditLink.ts +75 -0
- package/src/csm/getPublishedId.ts +12 -0
- package/src/csm/index.ts +9 -0
- package/src/csm/isArray.ts +3 -0
- package/src/csm/isRecord.ts +3 -0
- package/src/csm/jsonpath.test.ts +33 -0
- package/src/csm/jsonpath.ts +93 -0
- package/src/csm/resolveMapping.ts +41 -0
- package/src/csm/resolvedKeyedSourcePath.ts +23 -0
- package/src/csm/simplifyPath.ts +20 -0
- package/src/csm/types.ts +72 -0
- package/src/csm/walkMap.ts +30 -0
- package/src/stega/SanityStegaClient.ts +244 -0
- package/src/stega/config.ts +56 -0
- package/src/stega/encodeIntoResult.test.ts +268 -0
- package/src/stega/encodeIntoResult.ts +59 -0
- package/src/stega/filterDefault.ts +49 -0
- package/src/stega/index.browser.ts +19 -0
- package/src/stega/index.ts +19 -0
- package/src/stega/shared.ts +4 -0
- package/src/stega/stegaEncodeSourceMap.ts +128 -0
- package/src/stega/types.ts +139 -0
- package/umd/sanityClient.js +5 -1
- package/umd/sanityClient.min.js +1 -1
package/README.md
CHANGED
|
@@ -610,8 +610,6 @@ 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
|
-
|
|
615
613
|
Read the [Content Source Maps introduction][content-source-maps-intro] before diving in, and keep the [Content Source Maps reference][content-source-maps] handy.
|
|
616
614
|
|
|
617
615
|
Enabling Content Source Maps is a two-step process:
|
|
@@ -656,6 +654,85 @@ function useContentSourceMap(resultSourceMap: ContentSourceMapping): unknown {
|
|
|
656
654
|
useContentSourceMap(resultSourceMap)
|
|
657
655
|
```
|
|
658
656
|
|
|
657
|
+
#### Creating Studio edit intent links
|
|
658
|
+
|
|
659
|
+
```ts
|
|
660
|
+
import {createEditLink} from '@sanity/client/csm'
|
|
661
|
+
|
|
662
|
+
const editLink = createEditLink({
|
|
663
|
+
studioUrl: (sourceDocument: ContentSourceMapDocuments[number], sourcePath: PathSegment[]) =>
|
|
664
|
+
StudioUrl,
|
|
665
|
+
resultSourceMap: ContentSourceMapping,
|
|
666
|
+
resultPath: StudioPath,
|
|
667
|
+
})
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
In general, fetch a single post
|
|
671
|
+
|
|
672
|
+
With arrays, and keyed array items.
|
|
673
|
+
|
|
674
|
+
#### Using [Visual editing][visual-editing] with steganography
|
|
675
|
+
|
|
676
|
+
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.
|
|
677
|
+
|
|
678
|
+
```ts
|
|
679
|
+
import {createClient} from '@sanity/client/stega'
|
|
680
|
+
|
|
681
|
+
const client = createClient({
|
|
682
|
+
// ...base config options
|
|
683
|
+
stega: {
|
|
684
|
+
// Required: for encoded metadata from Content Source Maps
|
|
685
|
+
enabled: process.env.VERCEL_ENV !== 'production',
|
|
686
|
+
// Required: when "enabled" is true
|
|
687
|
+
// Set it to relative or absolute URL of your Sanity Studio
|
|
688
|
+
studioUrl: '/studio', // or 'https://your-project-name.sanity.studio'
|
|
689
|
+
studioUrl: (sourceDocument: {_id, _type, _projectId, _dataset}) => select workspace if cross dataset reference
|
|
690
|
+
|
|
691
|
+
// Optional, control what fields have stega payloads
|
|
692
|
+
filter: (props) => {
|
|
693
|
+
// {"name": title}
|
|
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
|
+
import {createQueryStore} from '@sanity/react-loader'
|
|
716
|
+
import {createClient} from '@sanity/client/stega'
|
|
717
|
+
|
|
718
|
+
const studioUrl = '/studio'
|
|
719
|
+
|
|
720
|
+
const client = createClient({
|
|
721
|
+
projectId,
|
|
722
|
+
dataset,
|
|
723
|
+
useCdn: true,
|
|
724
|
+
apiVersion: '2023-11-01',
|
|
725
|
+
stega: {
|
|
726
|
+
studioUrl,
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
const {useQuery, useLiveMode} = createQueryStore({client, studioUrl})
|
|
732
|
+
|
|
733
|
+
useLiveMode({client: client.withConfig({stega: {enabled: true}})})
|
|
734
|
+
```
|
|
735
|
+
|
|
659
736
|
### Listening to queries
|
|
660
737
|
|
|
661
738
|
```js
|