@sanity/client 7.11.2-audience-decide.0 → 7.11.2
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/dist/index.browser.cjs +5 -40
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +0 -14
- package/dist/index.browser.d.ts +0 -14
- package/dist/index.browser.js +5 -40
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +6 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -14
- package/dist/index.d.ts +0 -14
- package/dist/index.js +6 -41
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +0 -14
- package/dist/stega.browser.d.ts +0 -14
- package/dist/stega.d.cts +0 -14
- package/dist/stega.d.ts +0 -14
- package/package.json +1 -1
- package/src/data/dataMethods.ts +2 -31
- package/src/types.ts +0 -16
- package/umd/sanityClient.js +5 -40
- package/umd/sanityClient.min.js +2 -2
- package/src/data/decideResponseProcessor.ts +0 -111
package/dist/index.cjs
CHANGED
|
@@ -682,32 +682,6 @@ function requestOptions(config2, overrides = {}) {
|
|
|
682
682
|
fetch: typeof overrides.fetch == "object" && typeof config2.fetch == "object" ? { ...config2.fetch, ...overrides.fetch } : overrides.fetch || config2.fetch
|
|
683
683
|
});
|
|
684
684
|
}
|
|
685
|
-
function isDecideField(value) {
|
|
686
|
-
return value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
|
|
687
|
-
}
|
|
688
|
-
function resolveDecideField(field, decideParameters) {
|
|
689
|
-
const audience = decideParameters.audience, matchingCondition = field.conditions.find((condition) => Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience);
|
|
690
|
-
return matchingCondition ? matchingCondition.value : field.default;
|
|
691
|
-
}
|
|
692
|
-
function processObjectRecursively(obj, decideParameters) {
|
|
693
|
-
return obj == null || typeof obj != "object" ? obj : Array.isArray(obj) ? obj.map((item) => processObjectRecursively(item, decideParameters)) : Object.entries(obj).reduce((processed, [key, value]) => {
|
|
694
|
-
try {
|
|
695
|
-
isDecideField(value) ? processed[key] = resolveDecideField(value, decideParameters) : processed[key] = processObjectRecursively(value, decideParameters);
|
|
696
|
-
} catch (error) {
|
|
697
|
-
console.warn(`Failed to process decide field '${key}':`, error), processed[key] = value;
|
|
698
|
-
}
|
|
699
|
-
return processed;
|
|
700
|
-
}, {});
|
|
701
|
-
}
|
|
702
|
-
function processDecideFields(data, decideParameters) {
|
|
703
|
-
if (!decideParameters || !decideParameters.audience)
|
|
704
|
-
return data;
|
|
705
|
-
try {
|
|
706
|
-
return processObjectRecursively(data, decideParameters);
|
|
707
|
-
} catch (error) {
|
|
708
|
-
return console.warn("Failed to process decide fields:", error), data;
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
685
|
const encodeQueryString = ({
|
|
712
686
|
query,
|
|
713
687
|
params = {},
|
|
@@ -732,7 +706,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
732
706
|
const stega = "stega" in options ? {
|
|
733
707
|
..._stega || {},
|
|
734
708
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
735
|
-
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result,
|
|
709
|
+
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
|
|
736
710
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
737
711
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
738
712
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -757,11 +731,11 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
757
731
|
),
|
|
758
732
|
operators.map(
|
|
759
733
|
([res, stegaEncodeSourceMap]) => {
|
|
760
|
-
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega)
|
|
761
|
-
return
|
|
734
|
+
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
|
|
735
|
+
return mapResponse({ ...res, result });
|
|
762
736
|
}
|
|
763
737
|
)
|
|
764
|
-
) : $request.pipe(operators.map(mapResponse)
|
|
738
|
+
) : $request.pipe(operators.map(mapResponse));
|
|
765
739
|
}
|
|
766
740
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
767
741
|
const docId = (() => {
|
|
@@ -914,7 +888,6 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
914
888
|
tag,
|
|
915
889
|
returnQuery,
|
|
916
890
|
perspective: options.perspective,
|
|
917
|
-
decideParameters: options.decideParameters,
|
|
918
891
|
resultSourceMap: options.resultSourceMap,
|
|
919
892
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
920
893
|
cacheMode,
|
|
@@ -959,15 +932,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
959
932
|
perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
|
|
960
933
|
...options.query
|
|
961
934
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
962
|
-
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, config.printCdnPreviewDraftsWarning()));
|
|
963
|
-
const decideParametersOption = options.decideParameters || config$1.decideParameters;
|
|
964
|
-
decideParametersOption && typeof decideParametersOption == "object" && (options.query = {
|
|
965
|
-
...options.query,
|
|
966
|
-
...Object.keys(decideParametersOption).reduce(
|
|
967
|
-
(acc, key) => (acc[`decide.${key}`] = decideParametersOption[key], acc),
|
|
968
|
-
{}
|
|
969
|
-
)
|
|
970
|
-
}), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
|
|
935
|
+
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, config.printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
|
|
971
936
|
}
|
|
972
937
|
const reqOptions = requestOptions(
|
|
973
938
|
config$1,
|
|
@@ -2718,7 +2683,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2718
2683
|
return config.printNoDefaultExport(), createClient2(config$1);
|
|
2719
2684
|
};
|
|
2720
2685
|
}
|
|
2721
|
-
var name = "@sanity/client", version = "7.11.2
|
|
2686
|
+
var name = "@sanity/client", version = "7.11.2";
|
|
2722
2687
|
const middleware = [
|
|
2723
2688
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2724
2689
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|