@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
@@ -1,7 +1,8 @@
1
1
  import { getIt } from 'get-it';
2
2
  import { retry, jsonRequest, jsonResponse, progress, observable } from 'get-it/middleware';
3
- import { Observable, lastValueFrom } from 'rxjs';
4
- import { map, filter } from 'rxjs/operators';
3
+ import { Observable, from, lastValueFrom } from 'rxjs';
4
+ import { combineLatestWith, map, filter } from 'rxjs/operators';
5
+ import { vercelStegaSplit } from '@vercel/stega';
5
6
 
6
7
  const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
7
8
  class ClientError extends Error {
@@ -651,7 +652,8 @@ const defaultCdnHost = "apicdn.sanity.io";
651
652
  const defaultConfig = {
652
653
  apiHost: "https://api.sanity.io",
653
654
  apiVersion: "1",
654
- useProjectHostname: true
655
+ useProjectHostname: true,
656
+ stega: { enabled: false }
655
657
  };
656
658
  const LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
657
659
  const isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
@@ -678,11 +680,21 @@ const validateApiPerspective = function validateApiPerspective2(perspective) {
678
680
  }
679
681
  };
680
682
  const initConfig = (config, prevConfig) => {
681
- const specifiedConfig = Object.assign({}, prevConfig, config);
683
+ const specifiedConfig = {
684
+ ...prevConfig,
685
+ ...config,
686
+ stega: {
687
+ ...typeof prevConfig.stega === "boolean" ? { enabled: prevConfig.stega } : prevConfig.stega || defaultConfig.stega,
688
+ ...typeof config.stega === "boolean" ? { enabled: config.stega } : config.stega || {}
689
+ }
690
+ };
682
691
  if (!specifiedConfig.apiVersion) {
683
692
  printNoApiVersionSpecifiedWarning();
684
693
  }
685
- const newConfig = Object.assign({}, defaultConfig, specifiedConfig);
694
+ const newConfig = {
695
+ ...defaultConfig,
696
+ ...specifiedConfig
697
+ };
686
698
  const projectBased = newConfig.useProjectHostname;
687
699
  if (typeof Promise === "undefined") {
688
700
  const helpUrl = generateHelpUrl("js-client-promise-polyfill");
@@ -694,14 +706,25 @@ const initConfig = (config, prevConfig) => {
694
706
  if (typeof newConfig.perspective === "string") {
695
707
  validateApiPerspective(newConfig.perspective);
696
708
  }
697
- if ("encodeSourceMapAtPath" in newConfig || "encodeSourceMap" in newConfig || "studioUrl" in newConfig || "logger" in newConfig) {
709
+ if ("encodeSourceMap" in newConfig) {
698
710
  throw new Error(
699
- "It looks like you're using options meant for '@sanity/preview-kit/client', such as 'encodeSourceMapAtPath', 'encodeSourceMap', 'studioUrl' and 'logger'. Make sure you're using the right import."
711
+ "It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client'. Did you mean 'stega.enabled'?"
700
712
  );
701
713
  }
702
- if ("stega" in newConfig && newConfig["stega"] !== void 0 && newConfig["stega"] !== false) {
714
+ if ("encodeSourceMapAtPath" in newConfig) {
715
+ throw new Error(
716
+ "It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client'. Did you mean 'stega.filter'?"
717
+ );
718
+ }
719
+ if (typeof newConfig.stega.enabled !== "boolean") {
720
+ throw new Error("stega.enabled must be a boolean, received ".concat(newConfig.stega.enabled));
721
+ }
722
+ if (newConfig.stega.enabled && newConfig.stega.studioUrl === void 0) {
723
+ throw new Error("stega.studioUrl must be defined when stega.enabled is true");
724
+ }
725
+ if (newConfig.stega.enabled && typeof newConfig.stega.studioUrl !== "string" && typeof newConfig.stega.studioUrl !== "function") {
703
726
  throw new Error(
704
- "It looks like you're using options meant for '@sanity/client/stega'. Make sure you're using the right import. Or set 'stega' in 'createClient' to 'false'."
727
+ "stega.studioUrl must be a string or a function, received ".concat(newConfig.stega.studioUrl)
705
728
  );
706
729
  }
707
730
  const isBrowser = typeof window !== "undefined" && window.location && window.location.hostname;
@@ -762,6 +785,20 @@ function requestOptions(config, overrides = {}) {
762
785
  });
763
786
  }
764
787
 
788
+ function vercelStegaCleanAll(result) {
789
+ try {
790
+ return JSON.parse(
791
+ JSON.stringify(result, (key, value) => {
792
+ if (typeof value !== "string")
793
+ return value;
794
+ return vercelStegaSplit(value).cleaned;
795
+ })
796
+ );
797
+ } catch {
798
+ return result;
799
+ }
800
+ }
801
+
765
802
  const encodeQueryString = ({
766
803
  query,
767
804
  params = {},
@@ -803,21 +840,38 @@ const indexBy = (docs, attr) => docs.reduce((indexed, doc) => {
803
840
  return indexed;
804
841
  }, /* @__PURE__ */ Object.create(null));
805
842
  const getQuerySizeLimit = 11264;
806
- function _fetch(client, httpRequest, query, params, options = {}) {
807
- if ("stega" in options && options["stega"] !== void 0 && options["stega"] !== false) {
808
- throw new Error(
809
- "It looks like you're using options meant for '@sanity/client/stega'. Make sure you're using the right import. Or set 'stega' in 'fetch' to 'false'."
810
- );
811
- }
843
+ function _fetch(client, httpRequest, _stega, query, _params, options = {}) {
844
+ const stega = "stega" in options ? {
845
+ ..._stega || {},
846
+ ...typeof options.stega === "boolean" ? { enabled: options.stega } : options.stega || {}
847
+ } : _stega;
848
+ const params = stega.enabled ? vercelStegaCleanAll(_params) : _params;
812
849
  const mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result;
813
850
  const { cache, next, ...opts } = {
814
851
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
815
852
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
816
853
  useAbortSignal: typeof options.signal !== "undefined",
854
+ // Set `resultSourceMap' when stega is enabled, as it's required for encoding.
855
+ resultSourceMap: stega.enabled ? "withKeyArraySelector" : options.resultSourceMap,
817
856
  ...options
818
857
  };
819
858
  const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? { ...opts, fetch: { cache, next } } : opts;
820
- return _dataRequest(client, httpRequest, "query", { query, params }, reqOpts).pipe(map(mapResponse));
859
+ const $request = _dataRequest(client, httpRequest, "query", { query, params }, reqOpts);
860
+ return stega.enabled ? $request.pipe(
861
+ combineLatestWith(
862
+ from(
863
+ import('./stegaEncodeSourceMap-9L0STMBo.js').then(function (n) { return n.stegaEncodeSourceMap$1; }).then(
864
+ ({ stegaEncodeSourceMap }) => stegaEncodeSourceMap
865
+ )
866
+ )
867
+ ),
868
+ map(
869
+ ([res, stegaEncodeSourceMap]) => {
870
+ const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
871
+ return mapResponse({ ...res, result });
872
+ }
873
+ )
874
+ ) : $request.pipe(map(mapResponse));
821
875
  }
822
876
  function _getDocument(client, httpRequest, id, opts = {}) {
823
877
  const options = { uri: _getDataUrl(client, "doc", id), json: true, tag: opts.tag };
@@ -1558,10 +1612,25 @@ const _ObservableSanityClient = class _ObservableSanityClient {
1558
1612
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
1559
1613
  */
1560
1614
  withConfig(newConfig) {
1561
- return new _ObservableSanityClient(__privateGet(this, _httpRequest), { ...this.config(), ...newConfig });
1615
+ const thisConfig = this.config();
1616
+ return new _ObservableSanityClient(__privateGet(this, _httpRequest), {
1617
+ ...this.config(),
1618
+ ...newConfig,
1619
+ stega: {
1620
+ ...thisConfig.stega || {},
1621
+ ...typeof (newConfig == null ? void 0 : newConfig.stega) === "boolean" ? { enabled: newConfig.stega } : (newConfig == null ? void 0 : newConfig.stega) || {}
1622
+ }
1623
+ });
1562
1624
  }
1563
1625
  fetch(query, params, options = {}) {
1564
- return _fetch(this, __privateGet(this, _httpRequest), query, params, options);
1626
+ return _fetch(
1627
+ this,
1628
+ __privateGet(this, _httpRequest),
1629
+ __privateGet(this, _clientConfig).stega,
1630
+ query,
1631
+ params,
1632
+ options
1633
+ );
1565
1634
  }
1566
1635
  /**
1567
1636
  * Fetch a single document with the given ID.
@@ -1693,10 +1762,27 @@ const _SanityClient = class _SanityClient {
1693
1762
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
1694
1763
  */
1695
1764
  withConfig(newConfig) {
1696
- return new _SanityClient(__privateGet(this, _httpRequest2), { ...this.config(), ...newConfig });
1765
+ const thisConfig = this.config();
1766
+ return new _SanityClient(__privateGet(this, _httpRequest2), {
1767
+ ...thisConfig,
1768
+ ...newConfig,
1769
+ stega: {
1770
+ ...thisConfig.stega || {},
1771
+ ...typeof (newConfig == null ? void 0 : newConfig.stega) === "boolean" ? { enabled: newConfig.stega } : (newConfig == null ? void 0 : newConfig.stega) || {}
1772
+ }
1773
+ });
1697
1774
  }
1698
1775
  fetch(query, params, options = {}) {
1699
- return lastValueFrom(_fetch(this, __privateGet(this, _httpRequest2), query, params, options));
1776
+ return lastValueFrom(
1777
+ _fetch(
1778
+ this,
1779
+ __privateGet(this, _httpRequest2),
1780
+ __privateGet(this, _clientConfig2).stega,
1781
+ query,
1782
+ params,
1783
+ options
1784
+ )
1785
+ );
1700
1786
  }
1701
1787
  /**
1702
1788
  * Fetch a single document with the given ID.
@@ -1819,5 +1905,5 @@ function defineCreateClientExports(envMiddleware, ClassConstructor) {
1819
1905
 
1820
1906
  var envMiddleware = [];
1821
1907
 
1822
- export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, defaultConfig, defineCreateClientExports, envMiddleware, printNoDefaultExport };
1823
- //# sourceMappingURL=browserMiddleware-heyg-fDk.js.map
1908
+ export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, defineCreateClientExports, envMiddleware, printNoDefaultExport, vercelStegaCleanAll };
1909
+ //# sourceMappingURL=browserMiddleware-wklv-F5c.js.map