@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.browser.cjs
CHANGED
|
@@ -853,32 +853,6 @@ function requestOptions(config, overrides = {}) {
|
|
|
853
853
|
fetch: typeof overrides.fetch == "object" && typeof config.fetch == "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
|
|
854
854
|
});
|
|
855
855
|
}
|
|
856
|
-
function isDecideField(value) {
|
|
857
|
-
return value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
|
|
858
|
-
}
|
|
859
|
-
function resolveDecideField(field, decideParameters) {
|
|
860
|
-
const audience = decideParameters.audience, matchingCondition = field.conditions.find((condition) => Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience);
|
|
861
|
-
return matchingCondition ? matchingCondition.value : field.default;
|
|
862
|
-
}
|
|
863
|
-
function processObjectRecursively(obj, decideParameters) {
|
|
864
|
-
return obj == null || typeof obj != "object" ? obj : Array.isArray(obj) ? obj.map((item) => processObjectRecursively(item, decideParameters)) : Object.entries(obj).reduce((processed, [key, value]) => {
|
|
865
|
-
try {
|
|
866
|
-
isDecideField(value) ? processed[key] = resolveDecideField(value, decideParameters) : processed[key] = processObjectRecursively(value, decideParameters);
|
|
867
|
-
} catch (error) {
|
|
868
|
-
console.warn(`Failed to process decide field '${key}':`, error), processed[key] = value;
|
|
869
|
-
}
|
|
870
|
-
return processed;
|
|
871
|
-
}, {});
|
|
872
|
-
}
|
|
873
|
-
function processDecideFields(data, decideParameters) {
|
|
874
|
-
if (!decideParameters || !decideParameters.audience)
|
|
875
|
-
return data;
|
|
876
|
-
try {
|
|
877
|
-
return processObjectRecursively(data, decideParameters);
|
|
878
|
-
} catch (error) {
|
|
879
|
-
return console.warn("Failed to process decide fields:", error), data;
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
856
|
const encodeQueryString = ({
|
|
883
857
|
query,
|
|
884
858
|
params = {},
|
|
@@ -903,7 +877,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
903
877
|
const stega = "stega" in options ? {
|
|
904
878
|
..._stega || {},
|
|
905
879
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
906
|
-
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result,
|
|
880
|
+
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
|
|
907
881
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
908
882
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
909
883
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -928,11 +902,11 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
928
902
|
),
|
|
929
903
|
operators.map(
|
|
930
904
|
([res, stegaEncodeSourceMap]) => {
|
|
931
|
-
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega)
|
|
932
|
-
return
|
|
905
|
+
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
|
|
906
|
+
return mapResponse({ ...res, result });
|
|
933
907
|
}
|
|
934
908
|
)
|
|
935
|
-
) : $request.pipe(operators.map(mapResponse)
|
|
909
|
+
) : $request.pipe(operators.map(mapResponse));
|
|
936
910
|
}
|
|
937
911
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
938
912
|
const docId = (() => {
|
|
@@ -1085,7 +1059,6 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
1085
1059
|
tag,
|
|
1086
1060
|
returnQuery,
|
|
1087
1061
|
perspective: options.perspective,
|
|
1088
|
-
decideParameters: options.decideParameters,
|
|
1089
1062
|
resultSourceMap: options.resultSourceMap,
|
|
1090
1063
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
1091
1064
|
cacheMode,
|
|
@@ -1130,15 +1103,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
1130
1103
|
perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
|
|
1131
1104
|
...options.query
|
|
1132
1105
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
1133
|
-
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
1134
|
-
const decideParametersOption = options.decideParameters || config.decideParameters;
|
|
1135
|
-
decideParametersOption && typeof decideParametersOption == "object" && (options.query = {
|
|
1136
|
-
...options.query,
|
|
1137
|
-
...Object.keys(decideParametersOption).reduce(
|
|
1138
|
-
(acc, key) => (acc[`decide.${key}`] = decideParametersOption[key], acc),
|
|
1139
|
-
{}
|
|
1140
|
-
)
|
|
1141
|
-
}), 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 });
|
|
1106
|
+
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, 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 });
|
|
1142
1107
|
}
|
|
1143
1108
|
const reqOptions = requestOptions(
|
|
1144
1109
|
config,
|