@sanity/client 6.8.0-pink-lizard.12 → 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 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,128 +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
- 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: otherwise the `resultSourceMap` property will be empty on `client.fetch`
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
- // The URL resolver needs to know what the current document is, and the base URL of your Sanity Studio
763
- const {projectId, dataset} = client.config()
764
- const studioUrl = 'https://your-project-name.sanity.studio'
765
-
766
- resolveEditUrl({
767
- projectId,
768
- dataset,
769
- studioUrl,
770
- resultSourceMap,
771
- // The path to the field you want to edit, you can pass a string
772
- resultPath: 'pictures[0].alt',
773
- // Or an array of segments
774
- resultPath: ['pictures', 0, 'alt'],
775
- })
776
- // ^? 'https://your-project-name.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=author;path=pictures[_key=="cee5fbb69da2"].alt'
777
- ```
778
-
779
659
  ### Listening to queries
780
660
 
781
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-pink-lizard.12";
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-XGS8GPhb.cjs.map
1897
+ //# sourceMappingURL=nodeMiddleware-AQIXW8nd.cjs.map