@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.
Files changed (65) hide show
  1. package/README.md +79 -2
  2. package/dist/_chunks/browserMiddleware-Oa7zKwEN.js +1862 -0
  3. package/dist/_chunks/browserMiddleware-Oa7zKwEN.js.map +1 -0
  4. package/dist/_chunks/browserMiddleware-zle5A-pb.cjs +1877 -0
  5. package/dist/_chunks/browserMiddleware-zle5A-pb.cjs.map +1 -0
  6. package/dist/_chunks/createEditLink-FiifjNgi.cjs +222 -0
  7. package/dist/_chunks/createEditLink-FiifjNgi.cjs.map +1 -0
  8. package/dist/_chunks/createEditLink-f3l2nngi.js +212 -0
  9. package/dist/_chunks/createEditLink-f3l2nngi.js.map +1 -0
  10. package/dist/_chunks/nodeMiddleware-S6QZVGmT.cjs +1897 -0
  11. package/dist/_chunks/nodeMiddleware-S6QZVGmT.cjs.map +1 -0
  12. package/dist/_chunks/nodeMiddleware-XodpBhbR.js +1882 -0
  13. package/dist/_chunks/nodeMiddleware-XodpBhbR.js.map +1 -0
  14. package/dist/csm.cjs +71 -0
  15. package/dist/csm.cjs.map +1 -0
  16. package/dist/csm.d.ts +248 -0
  17. package/dist/csm.js +58 -0
  18. package/dist/csm.js.map +1 -0
  19. package/dist/index.browser.cjs +13 -1868
  20. package/dist/index.browser.cjs.map +1 -1
  21. package/dist/index.browser.js +3 -1858
  22. package/dist/index.browser.js.map +1 -1
  23. package/dist/index.cjs +13 -1888
  24. package/dist/index.cjs.js +2 -2
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.js +3 -1878
  27. package/dist/index.js.map +1 -1
  28. package/dist/stega.browser.cjs +629 -0
  29. package/dist/stega.browser.cjs.map +1 -0
  30. package/dist/stega.browser.js +598 -0
  31. package/dist/stega.browser.js.map +1 -0
  32. package/dist/stega.cjs +424 -0
  33. package/dist/stega.cjs.js +21 -0
  34. package/dist/stega.cjs.map +1 -0
  35. package/dist/stega.d.ts +2872 -0
  36. package/dist/stega.js +393 -0
  37. package/dist/stega.js.map +1 -0
  38. package/package.json +42 -2
  39. package/src/config.ts +6 -0
  40. package/src/csm/applySourceDocuments.test.ts +820 -0
  41. package/src/csm/applySourceDocuments.ts +87 -0
  42. package/src/csm/createEditLink.ts +75 -0
  43. package/src/csm/getPublishedId.ts +12 -0
  44. package/src/csm/index.ts +9 -0
  45. package/src/csm/isArray.ts +3 -0
  46. package/src/csm/isRecord.ts +3 -0
  47. package/src/csm/jsonpath.test.ts +33 -0
  48. package/src/csm/jsonpath.ts +93 -0
  49. package/src/csm/resolveMapping.ts +41 -0
  50. package/src/csm/resolvedKeyedSourcePath.ts +23 -0
  51. package/src/csm/simplifyPath.ts +20 -0
  52. package/src/csm/types.ts +72 -0
  53. package/src/csm/walkMap.ts +30 -0
  54. package/src/stega/SanityStegaClient.ts +244 -0
  55. package/src/stega/config.ts +56 -0
  56. package/src/stega/encodeIntoResult.test.ts +268 -0
  57. package/src/stega/encodeIntoResult.ts +59 -0
  58. package/src/stega/filterDefault.ts +49 -0
  59. package/src/stega/index.browser.ts +19 -0
  60. package/src/stega/index.ts +19 -0
  61. package/src/stega/shared.ts +4 -0
  62. package/src/stega/stegaEncodeSourceMap.ts +128 -0
  63. package/src/stega/types.ts +139 -0
  64. package/umd/sanityClient.js +5 -1
  65. 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