@sanity/client 6.11.3 → 6.11.4-canary.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.
Files changed (49) hide show
  1. package/README.md +85 -4
  2. package/dist/_chunks/{browserMiddleware-1MULg59S.cjs → browserMiddleware-Pe3R-Bkh.cjs} +106 -20
  3. package/dist/_chunks/browserMiddleware-Pe3R-Bkh.cjs.map +1 -0
  4. package/dist/_chunks/{browserMiddleware-heyg-fDk.js → browserMiddleware-wklv-F5c.js} +108 -22
  5. package/dist/_chunks/browserMiddleware-wklv-F5c.js.map +1 -0
  6. package/dist/_chunks/{nodeMiddleware-CHxg1-zH.cjs → nodeMiddleware-7PkLkt-m.cjs} +107 -21
  7. package/dist/_chunks/nodeMiddleware-7PkLkt-m.cjs.map +1 -0
  8. package/dist/_chunks/{nodeMiddleware-u_fUUnxa.js → nodeMiddleware-LGORMZpx.js} +109 -23
  9. package/dist/_chunks/nodeMiddleware-LGORMZpx.js.map +1 -0
  10. package/dist/_chunks/stegaEncodeSourceMap-2y-qTNKB.cjs +230 -0
  11. package/dist/_chunks/stegaEncodeSourceMap-2y-qTNKB.cjs.map +1 -0
  12. package/dist/_chunks/stegaEncodeSourceMap-9L0STMBo.js +475 -0
  13. package/dist/_chunks/stegaEncodeSourceMap-9L0STMBo.js.map +1 -0
  14. package/dist/_chunks/stegaEncodeSourceMap-gXzb3LIV.js +226 -0
  15. package/dist/_chunks/stegaEncodeSourceMap-gXzb3LIV.js.map +1 -0
  16. package/dist/_chunks/stegaEncodeSourceMap-vNYIaMiu.cjs +479 -0
  17. package/dist/_chunks/stegaEncodeSourceMap-vNYIaMiu.cjs.map +1 -0
  18. package/dist/index.browser.cjs +1 -1
  19. package/dist/index.browser.js +2 -2
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.ts +133 -0
  22. package/dist/index.js +2 -2
  23. package/dist/stega.browser.cjs +10 -700
  24. package/dist/stega.browser.cjs.map +1 -1
  25. package/dist/stega.browser.js +5 -693
  26. package/dist/stega.browser.js.map +1 -1
  27. package/dist/stega.cjs +10 -451
  28. package/dist/stega.cjs.js +3 -5
  29. package/dist/stega.cjs.map +1 -1
  30. package/dist/stega.d.ts +1302 -1455
  31. package/dist/stega.js +5 -444
  32. package/dist/stega.js.map +1 -1
  33. package/package.json +12 -7
  34. package/src/SanityClient.ts +40 -4
  35. package/src/config.ts +34 -12
  36. package/src/data/dataMethods.ts +37 -9
  37. package/src/stega/index.browser.ts +3 -6
  38. package/src/stega/index.ts +3 -6
  39. package/src/stega/shared.ts +1 -13
  40. package/src/stega/types.ts +11 -18
  41. package/src/types.ts +24 -0
  42. package/umd/sanityClient.js +1073 -20
  43. package/umd/sanityClient.min.js +4 -3
  44. package/dist/_chunks/browserMiddleware-1MULg59S.cjs.map +0 -1
  45. package/dist/_chunks/browserMiddleware-heyg-fDk.js.map +0 -1
  46. package/dist/_chunks/nodeMiddleware-CHxg1-zH.cjs.map +0 -1
  47. package/dist/_chunks/nodeMiddleware-u_fUUnxa.js.map +0 -1
  48. package/src/stega/SanityStegaClient.ts +0 -298
  49. package/src/stega/config.ts +0 -76
package/dist/index.d.ts CHANGED
@@ -325,6 +325,10 @@ export declare interface ClientConfig {
325
325
  *@deprecated set `cache` and `next` options on `client.fetch` instead
326
326
  */
327
327
  fetch?: RequestFetchOptions | boolean
328
+ /**
329
+ * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
330
+ */
331
+ stega?: StegaConfig | boolean
328
332
  }
329
333
 
330
334
  /** @public */
@@ -388,6 +392,19 @@ export declare type ContentSourceMapMapping = ContentSourceMapValueMapping
388
392
  /** @public */
389
393
  export declare type ContentSourceMapMappings = Record<string, ContentSourceMapMapping>
390
394
 
395
+ /** @alpha */
396
+ export declare type ContentSourceMapParsedPath = (
397
+ | string
398
+ | number
399
+ | ContentSourceMapParsedPathKeyedSegment
400
+ )[]
401
+
402
+ /** @alpha */
403
+ export declare type ContentSourceMapParsedPathKeyedSegment = {
404
+ _key: string
405
+ _index: number
406
+ }
407
+
391
408
  /** @public */
392
409
  export declare type ContentSourceMapPaths = string[]
393
410
 
@@ -520,6 +537,55 @@ export declare interface ErrorProps {
520
537
  details: Any
521
538
  }
522
539
 
540
+ /** @public */
541
+ export declare type FilterDefault = (props: {
542
+ /**
543
+ * The path to the value in the source document, for example if you queried for a document like this:
544
+ * `*[_type == "author"][0]{"slug": slug.current}`
545
+ * Then the `sourcePath` for `result.slug` would be `['slug', 'current']`.
546
+ *
547
+ */
548
+ sourcePath: ContentSourceMapParsedPath
549
+ /**
550
+ * If `sourcePath` alone isn't enough to tell you if it's safe to contain stega strings, then you can use `sourceDocument`
551
+ * for additional metadata.
552
+ * It'll always have a `_type` property, which can be used to trace it to the Studio Schema that were used initially.
553
+ * It also has `_id` to help you debug and look at the whole document when troubleshooting.
554
+ * Finally, if the document origins in a Cross Dataset Reference you'll also have `_projectId` and `_dataset` properties to help you trace it.
555
+ */
556
+ sourceDocument: ContentSourceMapDocuments[number]
557
+ /**
558
+ * If you don't colocate your Studio Schemas with your GROQ queries it might be hard to make sense of `sourcePath`,
559
+ * as it operates on the original shape of a document.
560
+ * In that case `resultPath` can be used, as it mirrors the path to the value in the result.
561
+ * For example in a query like this:
562
+ * `*[_type == "author"][0]{"slug": slug.current}`
563
+ * The `resultPath` for `result.slug` would be `['slug']`, while `sourcePath` will be `['slug', 'current']`.
564
+ */
565
+ resultPath: ContentSourceMapParsedPath
566
+ /**
567
+ * You can also use your own string validation logic to determine if it's safe.
568
+ */
569
+ value: string
570
+ /**
571
+ * If you want to keep the default filtering behavior, but only override it for a specific path, you can use `filterDefault` to do that.
572
+ * For example, here all "icon" documents in a Page Builder skips encoding:
573
+ * ```ts
574
+ {
575
+ filter: (props) => {
576
+ switch (props.sourceDocument._type) {
577
+ case 'icon':
578
+ return false
579
+ default:
580
+ return props.filterDefault(props)
581
+ }
582
+ }
583
+ }
584
+ * ```
585
+ */
586
+ filterDefault: FilterDefault
587
+ }) => boolean
588
+
523
589
  /** @public */
524
590
  export declare type FilteredResponseQueryOptions = ResponseQueryOptions & {
525
591
  filterResponse?: true
@@ -573,8 +639,16 @@ export declare interface InitializedClientConfig extends ClientConfig {
573
639
  * @deprecated Internal, don't use
574
640
  */
575
641
  cdnUrl: string
642
+ /**
643
+ * The fully initialized stega config, can be used to check if stega is enabled
644
+ */
645
+ stega: InitializedStegaConfig
576
646
  }
577
647
 
648
+ /** @public */
649
+ export declare type InitializedStegaConfig = Omit<StegaConfig, StegaConfigRequiredKeys> &
650
+ Required<Pick<StegaConfig, StegaConfigRequiredKeys>>
651
+
578
652
  /** @internal */
579
653
  export declare type InsertPatch =
580
654
  | {
@@ -685,6 +759,13 @@ export declare interface ListenOptions {
685
759
  tag?: string
686
760
  }
687
761
 
762
+ /** @public */
763
+ export declare type Logger =
764
+ | typeof console
765
+ | Partial<
766
+ Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
767
+ >
768
+
688
769
  /** @internal */
689
770
  export declare interface MultipleMutationResult {
690
771
  transactionId: string
@@ -1742,6 +1823,11 @@ export declare interface RequestOptions {
1742
1823
  signal?: AbortSignal
1743
1824
  }
1744
1825
 
1826
+ /** @alpha */
1827
+ export declare type ResolveStudioUrl = (
1828
+ sourceDocument: ContentSourceMapDocuments[number],
1829
+ ) => StudioUrl
1830
+
1745
1831
  /** @public */
1746
1832
  export declare interface ResponseEvent<T = unknown> {
1747
1833
  type: 'response'
@@ -1760,6 +1846,7 @@ export declare interface ResponseQueryOptions<T = 'next'> extends RequestOptions
1760
1846
  cache?: RequestInit['cache']
1761
1847
  next?: T extends keyof RequestInit ? RequestInit[T] : never
1762
1848
  useCdn?: boolean
1849
+ stega?: boolean | StegaConfig
1763
1850
  }
1764
1851
 
1765
1852
  /** @internal */
@@ -2394,6 +2481,52 @@ export declare interface SingleMutationResult {
2394
2481
  }[]
2395
2482
  }
2396
2483
 
2484
+ /** @public */
2485
+ export declare interface StegaConfig {
2486
+ /**
2487
+ * Enable or disable stega encoded strings in query results
2488
+ * ```ts
2489
+ {
2490
+ enabled: process.env.VERCEL_ENV !== 'production'
2491
+ }
2492
+ * ```
2493
+ * @defaultValue `false`
2494
+ */
2495
+ enabled?: boolean
2496
+ /**
2497
+ * Where the Studio is hosted.
2498
+ * If it's embedded in the app, use the base path for example `/studio`.
2499
+ * Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.
2500
+ *
2501
+ */
2502
+ studioUrl?: StudioUrl | ResolveStudioUrl
2503
+ filter?: FilterDefault
2504
+ /**
2505
+ * Specify a `console.log` compatible logger to see debug logs, which keys are encoded and which are not.
2506
+ */
2507
+ logger?: Logger
2508
+ }
2509
+
2510
+ /** @public */
2511
+ export declare type StegaConfigRequiredKeys = Extract<keyof StegaConfig, 'enabled'>
2512
+
2513
+ /** @alpha */
2514
+ export declare type StudioBaseRoute = {
2515
+ baseUrl: StudioBaseUrl
2516
+ workspace?: string
2517
+ tool?: string
2518
+ }
2519
+
2520
+ /** @alpha */
2521
+ export declare type StudioBaseUrl =
2522
+ | `/${string}`
2523
+ | `${string}.sanity.studio`
2524
+ | `https://${string}`
2525
+ | string
2526
+
2527
+ /** @alpha */
2528
+ export declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
2529
+
2397
2530
  /** @public */
2398
2531
  export declare class Transaction extends BaseTransaction {
2399
2532
  #private
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { printNoDefaultExport, defineCreateClientExports, SanityClient, middleware } from './_chunks/nodeMiddleware-u_fUUnxa.js';
2
- export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-u_fUUnxa.js';
1
+ import { printNoDefaultExport, defineCreateClientExports, SanityClient, middleware } from './_chunks/nodeMiddleware-LGORMZpx.js';
2
+ export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-LGORMZpx.js';
3
3
  export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it';
4
4
 
5
5
  function defineDeprecatedCreateClient(createClient) {