@sanity/client 7.11.2-audience-decide.8 → 7.12.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/dist/index.browser.cjs +12 -108
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +4 -14
- package/dist/index.browser.d.ts +4 -14
- package/dist/index.browser.js +12 -108
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +22 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -14
- package/dist/index.d.ts +4 -14
- package/dist/index.js +22 -109
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +4 -14
- package/dist/stega.browser.d.ts +4 -14
- package/dist/stega.d.cts +4 -14
- package/dist/stega.d.ts +4 -14
- package/package.json +1 -1
- package/src/SanityClient.ts +0 -26
- package/src/data/dataMethods.ts +9 -37
- package/src/defineCreateClient.ts +1 -0
- package/src/http/nodeMiddleware.ts +18 -1
- package/src/http/request.ts +5 -1
- package/src/types.ts +4 -16
- package/umd/sanityClient.js +12 -108
- package/umd/sanityClient.min.js +2 -2
- package/src/data/decideResponseProcessor.ts +0 -185
package/umd/sanityClient.js
CHANGED
|
@@ -2813,80 +2813,6 @@ ${selectionOpts}`);
|
|
|
2813
2813
|
fetch: typeof overrides.fetch == "object" && typeof config.fetch == "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
|
|
2814
2814
|
});
|
|
2815
2815
|
}
|
|
2816
|
-
function isDecideField(value) {
|
|
2817
|
-
return value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
|
|
2818
|
-
}
|
|
2819
|
-
function resolveDecideField(field, decideParameters) {
|
|
2820
|
-
console.log("[client-8] resolveDecideField: starting resolution:", {
|
|
2821
|
-
field: {
|
|
2822
|
-
default: field.default,
|
|
2823
|
-
conditionsCount: field.conditions.length,
|
|
2824
|
-
conditions: field.conditions.map((c, i) => ({
|
|
2825
|
-
index: i,
|
|
2826
|
-
audience: c.audience,
|
|
2827
|
-
value: c.value
|
|
2828
|
-
}))
|
|
2829
|
-
},
|
|
2830
|
-
decideParameters
|
|
2831
|
-
});
|
|
2832
|
-
const audience = decideParameters?.audience;
|
|
2833
|
-
if (console.log("[client-8] resolveDecideField: audience processing:", {
|
|
2834
|
-
audience,
|
|
2835
|
-
audienceType: typeof audience,
|
|
2836
|
-
isArray: Array.isArray(audience),
|
|
2837
|
-
isEmpty: Array.isArray(audience) ? audience.length === 0 : audience === "",
|
|
2838
|
-
isUndefined: audience === void 0,
|
|
2839
|
-
isNull: audience === null
|
|
2840
|
-
}), !audience || Array.isArray(audience) && audience.length === 0 || audience === "")
|
|
2841
|
-
return console.log(
|
|
2842
|
-
"[client-8] resolveDecideField: no valid audience, returning default:",
|
|
2843
|
-
field.default
|
|
2844
|
-
), field.default;
|
|
2845
|
-
console.log("[client-8] resolveDecideField: searching for matching condition...");
|
|
2846
|
-
const matchingCondition = field.conditions.find((condition, index) => {
|
|
2847
|
-
const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
|
|
2848
|
-
return console.log(`[client-8] resolveDecideField: checking condition ${index}:`, {
|
|
2849
|
-
conditionAudience: condition.audience,
|
|
2850
|
-
conditionValue: condition.value,
|
|
2851
|
-
searchAudience: audience,
|
|
2852
|
-
isArraySearch: Array.isArray(audience),
|
|
2853
|
-
isMatch
|
|
2854
|
-
}), isMatch;
|
|
2855
|
-
}), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
|
|
2856
|
-
return console.log("[client-8] resolveDecideField: resolution complete:", {
|
|
2857
|
-
matchingCondition: matchingCondition ? {
|
|
2858
|
-
audience: matchingCondition.audience,
|
|
2859
|
-
value: matchingCondition.value
|
|
2860
|
-
} : null,
|
|
2861
|
-
resolvedValue,
|
|
2862
|
-
usedDefault: !matchingCondition
|
|
2863
|
-
}), resolvedValue;
|
|
2864
|
-
}
|
|
2865
|
-
function processObjectRecursively(obj, decideParameters, depth = 0, path = "root") {
|
|
2866
|
-
return obj == null || typeof obj != "object" ? obj : Array.isArray(obj) ? obj.map(
|
|
2867
|
-
(item, index) => processObjectRecursively(item, decideParameters, depth + 1, `${path}[${index}]`)
|
|
2868
|
-
) : Object.entries(obj).reduce((processed, [key, value]) => {
|
|
2869
|
-
const currentPath = `${path}.${key}`, isDecide = isDecideField(value);
|
|
2870
|
-
try {
|
|
2871
|
-
isDecide ? (console.log(`[client-8] DECIDE FIELD FOUND: Key: '${key}'`), processed[key] = resolveDecideField(value, decideParameters)) : processed[key] = processObjectRecursively(value, decideParameters, depth + 1, currentPath);
|
|
2872
|
-
} catch {
|
|
2873
|
-
processed[key] = value;
|
|
2874
|
-
}
|
|
2875
|
-
return processed;
|
|
2876
|
-
}, {});
|
|
2877
|
-
}
|
|
2878
|
-
function processDecideFields(data, decideParameters) {
|
|
2879
|
-
console.log("[client-8] === DECIDE FIELD PROCESSING START ===");
|
|
2880
|
-
try {
|
|
2881
|
-
const result = processObjectRecursively(data, decideParameters);
|
|
2882
|
-
return console.log("[client-8] === DECIDE FIELD PROCESSING END ==="), result;
|
|
2883
|
-
} catch (error) {
|
|
2884
|
-
return console.warn(
|
|
2885
|
-
"[client-8] processDecideFields: processing failed, returning original data:",
|
|
2886
|
-
error
|
|
2887
|
-
), data;
|
|
2888
|
-
}
|
|
2889
|
-
}
|
|
2890
2816
|
const encodeQueryString = ({
|
|
2891
2817
|
query,
|
|
2892
2818
|
params = {},
|
|
@@ -2911,7 +2837,7 @@ ${selectionOpts}`);
|
|
|
2911
2837
|
const stega = "stega" in options ? {
|
|
2912
2838
|
..._stega || {},
|
|
2913
2839
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
2914
|
-
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result,
|
|
2840
|
+
} : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
|
|
2915
2841
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
2916
2842
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
2917
2843
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -2934,16 +2860,11 @@ ${selectionOpts}`);
|
|
|
2934
2860
|
),
|
|
2935
2861
|
map(
|
|
2936
2862
|
([res, stegaEncodeSourceMap]) => {
|
|
2937
|
-
const
|
|
2863
|
+
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
|
|
2938
2864
|
return mapResponse({ ...res, result });
|
|
2939
2865
|
}
|
|
2940
2866
|
)
|
|
2941
|
-
) : $request.pipe(
|
|
2942
|
-
map((res) => {
|
|
2943
|
-
const mappedResponse = mapResponse(res);
|
|
2944
|
-
return processDecideResponse(mappedResponse);
|
|
2945
|
-
})
|
|
2946
|
-
);
|
|
2867
|
+
) : $request.pipe(map(mapResponse));
|
|
2947
2868
|
}
|
|
2948
2869
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
2949
2870
|
const docId = (() => {
|
|
@@ -3096,7 +3017,6 @@ ${selectionOpts}`);
|
|
|
3096
3017
|
tag,
|
|
3097
3018
|
returnQuery,
|
|
3098
3019
|
perspective: options.perspective,
|
|
3099
|
-
decideParameters: options.decideParameters,
|
|
3100
3020
|
resultSourceMap: options.resultSourceMap,
|
|
3101
3021
|
lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
|
|
3102
3022
|
cacheMode,
|
|
@@ -3143,9 +3063,12 @@ ${selectionOpts}`);
|
|
|
3143
3063
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
3144
3064
|
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = false, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === false && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
|
|
3145
3065
|
}
|
|
3146
|
-
const
|
|
3147
|
-
|
|
3148
|
-
|
|
3066
|
+
const reqOptions = requestOptions(
|
|
3067
|
+
config,
|
|
3068
|
+
Object.assign({}, options, {
|
|
3069
|
+
url: _getUrl(client, uri, useCdn)
|
|
3070
|
+
})
|
|
3071
|
+
), request = new Observable(
|
|
3149
3072
|
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
3150
3073
|
);
|
|
3151
3074
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
@@ -4365,17 +4288,7 @@ ${selectionOpts}`);
|
|
|
4365
4288
|
});
|
|
4366
4289
|
}
|
|
4367
4290
|
fetch(query, params, options) {
|
|
4368
|
-
return
|
|
4369
|
-
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
4370
|
-
params,
|
|
4371
|
-
options: {
|
|
4372
|
-
...options,
|
|
4373
|
-
decideParameters: options?.decideParameters
|
|
4374
|
-
},
|
|
4375
|
-
clientConfig: {
|
|
4376
|
-
decideParameters: this.#clientConfig.decideParameters
|
|
4377
|
-
}
|
|
4378
|
-
}), _fetch(
|
|
4291
|
+
return _fetch(
|
|
4379
4292
|
this,
|
|
4380
4293
|
this.#httpRequest,
|
|
4381
4294
|
this.#clientConfig.stega,
|
|
@@ -4639,17 +4552,7 @@ ${selectionOpts}`);
|
|
|
4639
4552
|
});
|
|
4640
4553
|
}
|
|
4641
4554
|
fetch(query, params, options) {
|
|
4642
|
-
return
|
|
4643
|
-
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
4644
|
-
params,
|
|
4645
|
-
options: {
|
|
4646
|
-
...options,
|
|
4647
|
-
decideParameters: options?.decideParameters
|
|
4648
|
-
},
|
|
4649
|
-
clientConfig: {
|
|
4650
|
-
decideParameters: this.#clientConfig.decideParameters
|
|
4651
|
-
}
|
|
4652
|
-
}), lastValueFrom(
|
|
4555
|
+
return lastValueFrom(
|
|
4653
4556
|
_fetch(
|
|
4654
4557
|
this,
|
|
4655
4558
|
this.#httpRequest,
|
|
@@ -4898,6 +4801,7 @@ ${selectionOpts}`);
|
|
|
4898
4801
|
maxRedirects: 0,
|
|
4899
4802
|
maxRetries: config.maxRetries,
|
|
4900
4803
|
retryDelay: config.retryDelay,
|
|
4804
|
+
lineage: config.lineage,
|
|
4901
4805
|
...options
|
|
4902
4806
|
}),
|
|
4903
4807
|
config
|