@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.
- package/README.md +85 -4
- package/dist/_chunks/{browserMiddleware-1MULg59S.cjs → browserMiddleware-Pe3R-Bkh.cjs} +106 -20
- package/dist/_chunks/browserMiddleware-Pe3R-Bkh.cjs.map +1 -0
- package/dist/_chunks/{browserMiddleware-heyg-fDk.js → browserMiddleware-wklv-F5c.js} +108 -22
- package/dist/_chunks/browserMiddleware-wklv-F5c.js.map +1 -0
- package/dist/_chunks/{nodeMiddleware-CHxg1-zH.cjs → nodeMiddleware-7PkLkt-m.cjs} +107 -21
- package/dist/_chunks/nodeMiddleware-7PkLkt-m.cjs.map +1 -0
- package/dist/_chunks/{nodeMiddleware-u_fUUnxa.js → nodeMiddleware-LGORMZpx.js} +109 -23
- package/dist/_chunks/nodeMiddleware-LGORMZpx.js.map +1 -0
- package/dist/_chunks/stegaEncodeSourceMap-2y-qTNKB.cjs +230 -0
- package/dist/_chunks/stegaEncodeSourceMap-2y-qTNKB.cjs.map +1 -0
- package/dist/_chunks/stegaEncodeSourceMap-9L0STMBo.js +475 -0
- package/dist/_chunks/stegaEncodeSourceMap-9L0STMBo.js.map +1 -0
- package/dist/_chunks/stegaEncodeSourceMap-gXzb3LIV.js +226 -0
- package/dist/_chunks/stegaEncodeSourceMap-gXzb3LIV.js.map +1 -0
- package/dist/_chunks/stegaEncodeSourceMap-vNYIaMiu.cjs +479 -0
- package/dist/_chunks/stegaEncodeSourceMap-vNYIaMiu.cjs.map +1 -0
- package/dist/index.browser.cjs +1 -1
- package/dist/index.browser.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +133 -0
- package/dist/index.js +2 -2
- package/dist/stega.browser.cjs +10 -700
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js +5 -693
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +10 -451
- package/dist/stega.cjs.js +3 -5
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.d.ts +1302 -1455
- package/dist/stega.js +5 -444
- package/dist/stega.js.map +1 -1
- package/package.json +12 -7
- package/src/SanityClient.ts +40 -4
- package/src/config.ts +34 -12
- package/src/data/dataMethods.ts +37 -9
- package/src/stega/index.browser.ts +3 -6
- package/src/stega/index.ts +3 -6
- package/src/stega/shared.ts +1 -13
- package/src/stega/types.ts +11 -18
- package/src/types.ts +24 -0
- package/umd/sanityClient.js +1073 -20
- package/umd/sanityClient.min.js +4 -3
- package/dist/_chunks/browserMiddleware-1MULg59S.cjs.map +0 -1
- package/dist/_chunks/browserMiddleware-heyg-fDk.js.map +0 -1
- package/dist/_chunks/nodeMiddleware-CHxg1-zH.cjs.map +0 -1
- package/dist/_chunks/nodeMiddleware-u_fUUnxa.js.map +0 -1
- package/src/stega/SanityStegaClient.ts +0 -298
- package/src/stega/config.ts +0 -76
|
@@ -4,6 +4,7 @@ var getIt = require('get-it');
|
|
|
4
4
|
var middleware$1 = require('get-it/middleware');
|
|
5
5
|
var rxjs = require('rxjs');
|
|
6
6
|
var operators = require('rxjs/operators');
|
|
7
|
+
var stega = require('@vercel/stega');
|
|
7
8
|
|
|
8
9
|
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
9
10
|
class ClientError extends Error {
|
|
@@ -653,7 +654,8 @@ const defaultCdnHost = "apicdn.sanity.io";
|
|
|
653
654
|
const defaultConfig = {
|
|
654
655
|
apiHost: "https://api.sanity.io",
|
|
655
656
|
apiVersion: "1",
|
|
656
|
-
useProjectHostname: true
|
|
657
|
+
useProjectHostname: true,
|
|
658
|
+
stega: { enabled: false }
|
|
657
659
|
};
|
|
658
660
|
const LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
|
|
659
661
|
const isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
@@ -680,11 +682,21 @@ const validateApiPerspective = function validateApiPerspective2(perspective) {
|
|
|
680
682
|
}
|
|
681
683
|
};
|
|
682
684
|
const initConfig = (config, prevConfig) => {
|
|
683
|
-
const specifiedConfig =
|
|
685
|
+
const specifiedConfig = {
|
|
686
|
+
...prevConfig,
|
|
687
|
+
...config,
|
|
688
|
+
stega: {
|
|
689
|
+
...typeof prevConfig.stega === "boolean" ? { enabled: prevConfig.stega } : prevConfig.stega || defaultConfig.stega,
|
|
690
|
+
...typeof config.stega === "boolean" ? { enabled: config.stega } : config.stega || {}
|
|
691
|
+
}
|
|
692
|
+
};
|
|
684
693
|
if (!specifiedConfig.apiVersion) {
|
|
685
694
|
printNoApiVersionSpecifiedWarning();
|
|
686
695
|
}
|
|
687
|
-
const newConfig =
|
|
696
|
+
const newConfig = {
|
|
697
|
+
...defaultConfig,
|
|
698
|
+
...specifiedConfig
|
|
699
|
+
};
|
|
688
700
|
const projectBased = newConfig.useProjectHostname;
|
|
689
701
|
if (typeof Promise === "undefined") {
|
|
690
702
|
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
@@ -696,14 +708,25 @@ const initConfig = (config, prevConfig) => {
|
|
|
696
708
|
if (typeof newConfig.perspective === "string") {
|
|
697
709
|
validateApiPerspective(newConfig.perspective);
|
|
698
710
|
}
|
|
699
|
-
if ("
|
|
711
|
+
if ("encodeSourceMap" in newConfig) {
|
|
700
712
|
throw new Error(
|
|
701
|
-
"It looks like you're using options meant for '@sanity/preview-kit/client'
|
|
713
|
+
"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'?"
|
|
702
714
|
);
|
|
703
715
|
}
|
|
704
|
-
if ("
|
|
716
|
+
if ("encodeSourceMapAtPath" in newConfig) {
|
|
717
|
+
throw new Error(
|
|
718
|
+
"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'?"
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
if (typeof newConfig.stega.enabled !== "boolean") {
|
|
722
|
+
throw new Error("stega.enabled must be a boolean, received ".concat(newConfig.stega.enabled));
|
|
723
|
+
}
|
|
724
|
+
if (newConfig.stega.enabled && newConfig.stega.studioUrl === void 0) {
|
|
725
|
+
throw new Error("stega.studioUrl must be defined when stega.enabled is true");
|
|
726
|
+
}
|
|
727
|
+
if (newConfig.stega.enabled && typeof newConfig.stega.studioUrl !== "string" && typeof newConfig.stega.studioUrl !== "function") {
|
|
705
728
|
throw new Error(
|
|
706
|
-
"
|
|
729
|
+
"stega.studioUrl must be a string or a function, received ".concat(newConfig.stega.studioUrl)
|
|
707
730
|
);
|
|
708
731
|
}
|
|
709
732
|
const isBrowser = typeof window !== "undefined" && window.location && window.location.hostname;
|
|
@@ -764,6 +787,20 @@ function requestOptions(config, overrides = {}) {
|
|
|
764
787
|
});
|
|
765
788
|
}
|
|
766
789
|
|
|
790
|
+
function vercelStegaCleanAll(result) {
|
|
791
|
+
try {
|
|
792
|
+
return JSON.parse(
|
|
793
|
+
JSON.stringify(result, (key, value) => {
|
|
794
|
+
if (typeof value !== "string")
|
|
795
|
+
return value;
|
|
796
|
+
return stega.vercelStegaSplit(value).cleaned;
|
|
797
|
+
})
|
|
798
|
+
);
|
|
799
|
+
} catch {
|
|
800
|
+
return result;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
767
804
|
const encodeQueryString = ({
|
|
768
805
|
query,
|
|
769
806
|
params = {},
|
|
@@ -805,21 +842,38 @@ const indexBy = (docs, attr) => docs.reduce((indexed, doc) => {
|
|
|
805
842
|
return indexed;
|
|
806
843
|
}, /* @__PURE__ */ Object.create(null));
|
|
807
844
|
const getQuerySizeLimit = 11264;
|
|
808
|
-
function _fetch(client, httpRequest, query,
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
845
|
+
function _fetch(client, httpRequest, _stega, query, _params, options = {}) {
|
|
846
|
+
const stega = "stega" in options ? {
|
|
847
|
+
..._stega || {},
|
|
848
|
+
...typeof options.stega === "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
849
|
+
} : _stega;
|
|
850
|
+
const params = stega.enabled ? vercelStegaCleanAll(_params) : _params;
|
|
814
851
|
const mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result;
|
|
815
852
|
const { cache, next, ...opts } = {
|
|
816
853
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
817
854
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
818
855
|
useAbortSignal: typeof options.signal !== "undefined",
|
|
856
|
+
// Set `resultSourceMap' when stega is enabled, as it's required for encoding.
|
|
857
|
+
resultSourceMap: stega.enabled ? "withKeyArraySelector" : options.resultSourceMap,
|
|
819
858
|
...options
|
|
820
859
|
};
|
|
821
860
|
const reqOpts = typeof cache !== "undefined" || typeof next !== "undefined" ? { ...opts, fetch: { cache, next } } : opts;
|
|
822
|
-
|
|
861
|
+
const $request = _dataRequest(client, httpRequest, "query", { query, params }, reqOpts);
|
|
862
|
+
return stega.enabled ? $request.pipe(
|
|
863
|
+
operators.combineLatestWith(
|
|
864
|
+
rxjs.from(
|
|
865
|
+
Promise.resolve().then(function () { return require('./stegaEncodeSourceMap-2y-qTNKB.cjs'); }).then(function (n) { return n.stegaEncodeSourceMap$1; }).then(
|
|
866
|
+
({ stegaEncodeSourceMap }) => stegaEncodeSourceMap
|
|
867
|
+
)
|
|
868
|
+
)
|
|
869
|
+
),
|
|
870
|
+
operators.map(
|
|
871
|
+
([res, stegaEncodeSourceMap]) => {
|
|
872
|
+
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
|
|
873
|
+
return mapResponse({ ...res, result });
|
|
874
|
+
}
|
|
875
|
+
)
|
|
876
|
+
) : $request.pipe(operators.map(mapResponse));
|
|
823
877
|
}
|
|
824
878
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
825
879
|
const options = { uri: _getDataUrl(client, "doc", id), json: true, tag: opts.tag };
|
|
@@ -1560,10 +1614,25 @@ const _ObservableSanityClient = class _ObservableSanityClient {
|
|
|
1560
1614
|
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1561
1615
|
*/
|
|
1562
1616
|
withConfig(newConfig) {
|
|
1563
|
-
|
|
1617
|
+
const thisConfig = this.config();
|
|
1618
|
+
return new _ObservableSanityClient(__privateGet(this, _httpRequest), {
|
|
1619
|
+
...this.config(),
|
|
1620
|
+
...newConfig,
|
|
1621
|
+
stega: {
|
|
1622
|
+
...thisConfig.stega || {},
|
|
1623
|
+
...typeof (newConfig == null ? void 0 : newConfig.stega) === "boolean" ? { enabled: newConfig.stega } : (newConfig == null ? void 0 : newConfig.stega) || {}
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1564
1626
|
}
|
|
1565
1627
|
fetch(query, params, options = {}) {
|
|
1566
|
-
return _fetch(
|
|
1628
|
+
return _fetch(
|
|
1629
|
+
this,
|
|
1630
|
+
__privateGet(this, _httpRequest),
|
|
1631
|
+
__privateGet(this, _clientConfig).stega,
|
|
1632
|
+
query,
|
|
1633
|
+
params,
|
|
1634
|
+
options
|
|
1635
|
+
);
|
|
1567
1636
|
}
|
|
1568
1637
|
/**
|
|
1569
1638
|
* Fetch a single document with the given ID.
|
|
@@ -1695,10 +1764,27 @@ const _SanityClient = class _SanityClient {
|
|
|
1695
1764
|
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1696
1765
|
*/
|
|
1697
1766
|
withConfig(newConfig) {
|
|
1698
|
-
|
|
1767
|
+
const thisConfig = this.config();
|
|
1768
|
+
return new _SanityClient(__privateGet(this, _httpRequest2), {
|
|
1769
|
+
...thisConfig,
|
|
1770
|
+
...newConfig,
|
|
1771
|
+
stega: {
|
|
1772
|
+
...thisConfig.stega || {},
|
|
1773
|
+
...typeof (newConfig == null ? void 0 : newConfig.stega) === "boolean" ? { enabled: newConfig.stega } : (newConfig == null ? void 0 : newConfig.stega) || {}
|
|
1774
|
+
}
|
|
1775
|
+
});
|
|
1699
1776
|
}
|
|
1700
1777
|
fetch(query, params, options = {}) {
|
|
1701
|
-
return rxjs.lastValueFrom(
|
|
1778
|
+
return rxjs.lastValueFrom(
|
|
1779
|
+
_fetch(
|
|
1780
|
+
this,
|
|
1781
|
+
__privateGet(this, _httpRequest2),
|
|
1782
|
+
__privateGet(this, _clientConfig2).stega,
|
|
1783
|
+
query,
|
|
1784
|
+
params,
|
|
1785
|
+
options
|
|
1786
|
+
)
|
|
1787
|
+
);
|
|
1702
1788
|
}
|
|
1703
1789
|
/**
|
|
1704
1790
|
* Fetch a single document with the given ID.
|
|
@@ -1820,7 +1906,7 @@ function defineCreateClientExports(envMiddleware, ClassConstructor) {
|
|
|
1820
1906
|
}
|
|
1821
1907
|
|
|
1822
1908
|
var name = "@sanity/client";
|
|
1823
|
-
var version = "6.11.
|
|
1909
|
+
var version = "6.11.4-canary.0";
|
|
1824
1910
|
|
|
1825
1911
|
const middleware = [
|
|
1826
1912
|
middleware$1.debug({ verbose: true, namespace: "sanity:client" }),
|
|
@@ -1850,8 +1936,8 @@ exports.Patch = Patch;
|
|
|
1850
1936
|
exports.SanityClient = SanityClient;
|
|
1851
1937
|
exports.ServerError = ServerError;
|
|
1852
1938
|
exports.Transaction = Transaction;
|
|
1853
|
-
exports.defaultConfig = defaultConfig;
|
|
1854
1939
|
exports.defineCreateClientExports = defineCreateClientExports;
|
|
1855
1940
|
exports.middleware = middleware;
|
|
1856
1941
|
exports.printNoDefaultExport = printNoDefaultExport;
|
|
1857
|
-
|
|
1942
|
+
exports.vercelStegaCleanAll = vercelStegaCleanAll;
|
|
1943
|
+
//# sourceMappingURL=nodeMiddleware-7PkLkt-m.cjs.map
|