@sanity/client 7.11.2-audience-decide.3 → 7.11.2-audience-decide.5
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 +136 -36
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +136 -36
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +137 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +137 -37
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/SanityClient.ts +2 -2
- package/src/data/dataMethods.ts +60 -27
- package/src/data/decideResponseProcessor.ts +204 -18
- package/umd/sanityClient.js +136 -36
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.cjs
CHANGED
|
@@ -854,30 +854,118 @@ function requestOptions(config, overrides = {}) {
|
|
|
854
854
|
});
|
|
855
855
|
}
|
|
856
856
|
function isDecideField(value) {
|
|
857
|
-
|
|
857
|
+
console.log("[client-5] isDecideField: checking value:", {
|
|
858
|
+
value: typeof value == "object" ? JSON.stringify(value, null, 2) : value,
|
|
859
|
+
type: typeof value,
|
|
860
|
+
isNull: value === null,
|
|
861
|
+
isArray: Array.isArray(value)
|
|
862
|
+
});
|
|
863
|
+
const isValid = value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
|
|
864
|
+
return console.log("[client-5] isDecideField: result:", {
|
|
865
|
+
isValid,
|
|
866
|
+
hasDefault: value != null && typeof value == "object" && "default" in value,
|
|
867
|
+
hasConditions: value != null && typeof value == "object" && "conditions" in value,
|
|
868
|
+
conditionsIsArray: value != null && typeof value == "object" && "conditions" in value && Array.isArray(value.conditions)
|
|
869
|
+
}), isValid;
|
|
858
870
|
}
|
|
859
871
|
function resolveDecideField(field, decideParameters) {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
872
|
+
console.log("[client-5] resolveDecideField: starting resolution:", {
|
|
873
|
+
field: {
|
|
874
|
+
default: field.default,
|
|
875
|
+
conditionsCount: field.conditions.length,
|
|
876
|
+
conditions: field.conditions.map((c, i) => ({
|
|
877
|
+
index: i,
|
|
878
|
+
audience: c.audience,
|
|
879
|
+
value: c.value
|
|
880
|
+
}))
|
|
881
|
+
},
|
|
882
|
+
decideParameters
|
|
883
|
+
});
|
|
884
|
+
const audience = decideParameters?.audience;
|
|
885
|
+
if (console.log("[client-5] resolveDecideField: audience processing:", {
|
|
886
|
+
audience,
|
|
887
|
+
audienceType: typeof audience,
|
|
888
|
+
isArray: Array.isArray(audience),
|
|
889
|
+
isEmpty: Array.isArray(audience) ? audience.length === 0 : audience === "",
|
|
890
|
+
isUndefined: audience === void 0,
|
|
891
|
+
isNull: audience === null
|
|
892
|
+
}), !audience || Array.isArray(audience) && audience.length === 0 || audience === "")
|
|
893
|
+
return console.log("[client-5] resolveDecideField: no valid audience, returning default:", field.default), field.default;
|
|
894
|
+
console.log("[client-5] resolveDecideField: searching for matching condition...");
|
|
895
|
+
const matchingCondition = field.conditions.find((condition, index) => {
|
|
896
|
+
const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
|
|
897
|
+
return console.log(`[client-5] resolveDecideField: checking condition ${index}:`, {
|
|
898
|
+
conditionAudience: condition.audience,
|
|
899
|
+
conditionValue: condition.value,
|
|
900
|
+
searchAudience: audience,
|
|
901
|
+
isArraySearch: Array.isArray(audience),
|
|
902
|
+
isMatch
|
|
903
|
+
}), isMatch;
|
|
904
|
+
}), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
|
|
905
|
+
return console.log("[client-5] resolveDecideField: resolution complete:", {
|
|
906
|
+
matchingCondition: matchingCondition ? {
|
|
907
|
+
audience: matchingCondition.audience,
|
|
908
|
+
value: matchingCondition.value
|
|
909
|
+
} : null,
|
|
910
|
+
resolvedValue,
|
|
911
|
+
usedDefault: !matchingCondition
|
|
912
|
+
}), resolvedValue;
|
|
913
|
+
}
|
|
914
|
+
function processObjectRecursively(obj, decideParameters, depth = 0, path = "root") {
|
|
915
|
+
const indent = " ".repeat(depth);
|
|
916
|
+
return console.log(`[client-5] ${indent}processObjectRecursively: processing at path '${path}':`, {
|
|
917
|
+
type: typeof obj,
|
|
918
|
+
isNull: obj === null,
|
|
919
|
+
isUndefined: obj === void 0,
|
|
920
|
+
isArray: Array.isArray(obj),
|
|
921
|
+
depth,
|
|
922
|
+
decideParameters
|
|
923
|
+
}), obj == null || typeof obj != "object" ? (console.log(`[client-5] ${indent}processObjectRecursively: returning primitive/null value:`, obj), obj) : Array.isArray(obj) ? (console.log(`[client-5] ${indent}processObjectRecursively: processing array with ${obj.length} items`), obj.map((item, index) => (console.log(`[client-5] ${indent}processObjectRecursively: processing array item ${index}`), processObjectRecursively(item, decideParameters, depth + 1, `${path}[${index}]`)))) : (console.log(`[client-5] ${indent}processObjectRecursively: processing object with keys:`, Object.keys(obj)), Object.entries(obj).reduce((processed, [key, value]) => {
|
|
924
|
+
const currentPath = `${path}.${key}`;
|
|
925
|
+
console.log(`[client-5] ${indent}processObjectRecursively: processing key '${key}' at path '${currentPath}'`);
|
|
865
926
|
try {
|
|
866
|
-
isDecideField(value) ? processed[key] = resolveDecideField(value, decideParameters) : processed[key] = processObjectRecursively(value, decideParameters);
|
|
927
|
+
isDecideField(value) ? (console.log(`[client-5] ${indent}processObjectRecursively: '${key}' is a decide field, resolving...`), processed[key] = resolveDecideField(value, decideParameters), console.log(`[client-5] ${indent}processObjectRecursively: '${key}' resolved to:`, processed[key])) : (console.log(`[client-5] ${indent}processObjectRecursively: '${key}' is not a decide field, recursing...`), processed[key] = processObjectRecursively(value, decideParameters, depth + 1, currentPath));
|
|
867
928
|
} catch (error) {
|
|
868
|
-
console.warn(`Failed to process decide field '${key}':`, error), processed[key] = value;
|
|
929
|
+
console.warn(`[client-5] ${indent}processObjectRecursively: Failed to process decide field '${key}':`, error), processed[key] = value;
|
|
869
930
|
}
|
|
870
931
|
return processed;
|
|
871
|
-
}, {});
|
|
932
|
+
}, {}));
|
|
872
933
|
}
|
|
873
934
|
function processDecideFields(data, decideParameters) {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
935
|
+
console.log("[client-5] === DECIDE FIELD PROCESSING START ==="), console.log("[client-5] processDecideFields: analyzing response structure:", {
|
|
936
|
+
dataType: typeof data,
|
|
937
|
+
isObject: typeof data == "object" && data !== null,
|
|
938
|
+
hasResultsKey: typeof data == "object" && data !== null && "result" in data,
|
|
939
|
+
hasDocumentsKey: typeof data == "object" && data !== null && "documents" in data,
|
|
940
|
+
topLevelKeys: typeof data == "object" && data !== null ? Object.keys(data) : null
|
|
941
|
+
});
|
|
942
|
+
let decideFieldCount = 0;
|
|
943
|
+
const countDecideFields = (obj, path = "") => {
|
|
944
|
+
obj == null || typeof obj != "object" || (Array.isArray(obj) ? obj.forEach((item, index) => countDecideFields(item, `${path}[${index}]`)) : Object.entries(obj).forEach(([key, value]) => {
|
|
945
|
+
const currentPath = path ? `${path}.${key}` : key;
|
|
946
|
+
isDecideField(value) ? (decideFieldCount++, console.log(`[client-5] processDecideFields: Found decide field at path '${currentPath}':`, {
|
|
947
|
+
default: value.default,
|
|
948
|
+
conditionsCount: value.conditions.length
|
|
949
|
+
})) : countDecideFields(value, currentPath);
|
|
950
|
+
}));
|
|
951
|
+
};
|
|
952
|
+
console.log("[client-5] processDecideFields: scanning for decide fields..."), countDecideFields(data), console.log(`[client-5] processDecideFields: found ${decideFieldCount} decide fields in response`), console.log("[client-5] processDecideFields: entry parameters:", {
|
|
953
|
+
decideParameters,
|
|
954
|
+
hasAudience: !!decideParameters?.audience,
|
|
955
|
+
audience: decideParameters?.audience,
|
|
956
|
+
audienceType: typeof decideParameters?.audience,
|
|
957
|
+
dataType: typeof data,
|
|
958
|
+
dataPreview: typeof data == "object" && data !== null ? JSON.stringify(data, null, 2).substring(0, 500) + (JSON.stringify(data, null, 2).length > 500 ? "..." : "") : data
|
|
959
|
+
});
|
|
877
960
|
try {
|
|
878
|
-
|
|
961
|
+
console.log("[client-5] processDecideFields: starting recursive processing...");
|
|
962
|
+
const result = processObjectRecursively(data, decideParameters);
|
|
963
|
+
return console.log("[client-5] processDecideFields: processing completed successfully"), console.log("[client-5] processDecideFields: result preview:", {
|
|
964
|
+
resultType: typeof result,
|
|
965
|
+
resultPreview: typeof result == "object" && result !== null ? JSON.stringify(result, null, 2).substring(0, 500) + (JSON.stringify(result, null, 2).length > 500 ? "..." : "") : result
|
|
966
|
+
}), console.log("[client-5] === DECIDE FIELD PROCESSING END ==="), result;
|
|
879
967
|
} catch (error) {
|
|
880
|
-
return console.warn("
|
|
968
|
+
return console.warn("[client-5] processDecideFields: processing failed, returning original data:", error), console.log("[client-5] === DECIDE FIELD PROCESSING END (ERROR) ==="), data;
|
|
881
969
|
}
|
|
882
970
|
}
|
|
883
971
|
const encodeQueryString = ({
|
|
@@ -901,7 +989,7 @@ const encodeQueryString = ({
|
|
|
901
989
|
skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
|
|
902
990
|
}), isResponse = (event) => event.type === "response", getBody = (event) => event.body, indexBy = (docs, attr) => docs.reduce((indexed, doc) => (indexed[attr(doc)] = doc, indexed), /* @__PURE__ */ Object.create(null)), getQuerySizeLimit = 11264;
|
|
903
991
|
function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
904
|
-
console.log("_fetch called with:", {
|
|
992
|
+
console.log("[client-5] _fetch called with:", {
|
|
905
993
|
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
906
994
|
params: _params,
|
|
907
995
|
options: {
|
|
@@ -913,13 +1001,18 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
913
1001
|
const stega = "stega" in options ? {
|
|
914
1002
|
..._stega || {},
|
|
915
1003
|
...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
|
|
916
|
-
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) =>
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1004
|
+
} : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) => {
|
|
1005
|
+
console.log("[client-5] === HTTP RESPONSE TO DECIDE PROCESSING ==="), console.log("[client-5] processDecideResponse: received response for processing:", {
|
|
1006
|
+
responseType: typeof response,
|
|
1007
|
+
responseKeys: typeof response == "object" && response !== null ? Object.keys(response) : null,
|
|
1008
|
+
responsePreview: typeof response == "object" && response !== null ? JSON.stringify(response, null, 2).substring(0, 300) + (JSON.stringify(response, null, 2).length > 300 ? "..." : "") : response,
|
|
1009
|
+
audience: options.decideParameters?.audience,
|
|
1010
|
+
decideParameters: options.decideParameters,
|
|
1011
|
+
hasDecideParameters: !!options.decideParameters
|
|
1012
|
+
}), console.log("[client-5] processDecideResponse: calling processDecideFields...");
|
|
1013
|
+
const processedData = processDecideFields(response, options.decideParameters);
|
|
1014
|
+
return console.log("[client-5] processDecideResponse: decide processing complete, returning processed data"), console.log("[client-5] === HTTP RESPONSE TO DECIDE PROCESSING COMPLETE ==="), processedData;
|
|
1015
|
+
}, { cache, next, ...opts } = {
|
|
923
1016
|
// Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
|
|
924
1017
|
// This is necessary in React Server Components to avoid opting out of Request Memoization.
|
|
925
1018
|
useAbortSignal: typeof options.signal < "u",
|
|
@@ -930,7 +1023,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
930
1023
|
// or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
|
|
931
1024
|
returnQuery: options.filterResponse === !1 && options.returnQuery !== !1
|
|
932
1025
|
}, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(client, httpRequest, "query", { query, params }, reqOpts);
|
|
933
|
-
return stega.enabled ? $request.pipe(
|
|
1026
|
+
return console.log("[client-5] _fetch: pipeline setup, stega.enabled:", stega.enabled), stega.enabled ? $request.pipe(
|
|
934
1027
|
operators.combineLatestWith(
|
|
935
1028
|
rxjs.from(
|
|
936
1029
|
Promise.resolve().then(function() {
|
|
@@ -944,11 +1037,18 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
944
1037
|
),
|
|
945
1038
|
operators.map(
|
|
946
1039
|
([res, stegaEncodeSourceMap]) => {
|
|
1040
|
+
console.log("[client-5] _fetch: stega path - processing response");
|
|
947
1041
|
const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega), mappedResponse = mapResponse({ ...res, result });
|
|
948
|
-
return processDecideResponse(mappedResponse);
|
|
1042
|
+
return console.log("[client-5] _fetch: stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
|
|
949
1043
|
}
|
|
950
1044
|
)
|
|
951
|
-
) : $request.pipe(
|
|
1045
|
+
) : $request.pipe(
|
|
1046
|
+
operators.map((res) => {
|
|
1047
|
+
console.log("[client-5] _fetch: non-stega path - processing response");
|
|
1048
|
+
const mappedResponse = mapResponse(res);
|
|
1049
|
+
return console.log("[client-5] _fetch: non-stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
|
|
1050
|
+
})
|
|
1051
|
+
);
|
|
952
1052
|
}
|
|
953
1053
|
function _getDocument(client, httpRequest, id, opts = {}) {
|
|
954
1054
|
const docId = (() => {
|
|
@@ -1089,7 +1189,7 @@ function _action(client, httpRequest, actions, options) {
|
|
|
1089
1189
|
);
|
|
1090
1190
|
}
|
|
1091
1191
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
1092
|
-
console.log("_dataRequest called with:", {
|
|
1192
|
+
console.log("[client-5] _dataRequest called with:", {
|
|
1093
1193
|
endpoint,
|
|
1094
1194
|
body: endpoint === "query" ? {
|
|
1095
1195
|
query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
|
|
@@ -1123,7 +1223,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
|
1123
1223
|
useAbortSignal: options.useAbortSignal,
|
|
1124
1224
|
useCdn: options.useCdn
|
|
1125
1225
|
};
|
|
1126
|
-
return console.log("_dataRequest calling _requestObservable with reqOptions:", {
|
|
1226
|
+
return console.log("[client-5] _dataRequest calling _requestObservable with reqOptions:", {
|
|
1127
1227
|
...reqOptions,
|
|
1128
1228
|
decideParameters: reqOptions.decideParameters,
|
|
1129
1229
|
perspective: reqOptions.perspective,
|
|
@@ -1156,7 +1256,7 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
1156
1256
|
const hasDataConfig = (client) => client.config().dataset !== void 0 && client.config().projectId !== void 0 || client.config()["~experimental_resource"] !== void 0, isQuery = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "query")), isMutate = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "mutate")), isDoc = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "doc", "")), isListener = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "listen")), isHistory = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "history", "")), isData = (client, uri) => uri.startsWith("/data/") || isQuery(client, uri) || isMutate(client, uri) || isDoc(client, uri) || isListener(client, uri) || isHistory(client, uri);
|
|
1157
1257
|
function _requestObservable(client, httpRequest, options) {
|
|
1158
1258
|
const uri = options.url || options.uri, config = client.config();
|
|
1159
|
-
console.log("_requestObservable called with options:", {
|
|
1259
|
+
console.log("[client-5] _requestObservable called with options:", {
|
|
1160
1260
|
uri,
|
|
1161
1261
|
method: options.method,
|
|
1162
1262
|
decideParameters: options.decideParameters,
|
|
@@ -1177,28 +1277,28 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
1177
1277
|
}, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
|
|
1178
1278
|
perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
|
|
1179
1279
|
const decideParametersOption = options.decideParameters || config.decideParameters;
|
|
1180
|
-
console.log("Processing decideParameters:", {
|
|
1280
|
+
console.log("[client-5] Processing decideParameters:", {
|
|
1181
1281
|
optionsDecideParameters: options.decideParameters,
|
|
1182
1282
|
configDecideParameters: config.decideParameters,
|
|
1183
1283
|
finalDecideParametersOption: decideParametersOption
|
|
1184
1284
|
}), decideParametersOption && typeof decideParametersOption == "object" ? (console.log(
|
|
1185
|
-
"DecideParameters received - keeping for response processing only:",
|
|
1285
|
+
"[client-5] DecideParameters received - keeping for response processing only:",
|
|
1186
1286
|
decideParametersOption
|
|
1187
1287
|
), console.log(
|
|
1188
|
-
"DecideParameters will be preserved for response processing but not sent in HTTP request"
|
|
1189
|
-
)) : console.log("No decideParameters to process or invalid format"), 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 });
|
|
1288
|
+
"[client-5] DecideParameters will be preserved for response processing but not sent in HTTP request"
|
|
1289
|
+
)) : console.log("[client-5] No decideParameters to process or invalid format"), 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 });
|
|
1190
1290
|
}
|
|
1191
1291
|
const finalOptions = Object.assign({}, options, {
|
|
1192
1292
|
url: _getUrl(client, uri, useCdn)
|
|
1193
1293
|
});
|
|
1194
|
-
console.log("Final options before requestOptions call:", {
|
|
1294
|
+
console.log("[client-5] Final options before requestOptions call:", {
|
|
1195
1295
|
url: finalOptions.url,
|
|
1196
1296
|
decideParameters: finalOptions.decideParameters,
|
|
1197
1297
|
query: finalOptions.query,
|
|
1198
1298
|
method: finalOptions.method
|
|
1199
1299
|
});
|
|
1200
1300
|
const reqOptions = requestOptions(config, finalOptions);
|
|
1201
|
-
console.log("Final reqOptions from requestOptions:", {
|
|
1301
|
+
console.log("[client-5] Final reqOptions from requestOptions:", {
|
|
1202
1302
|
method: reqOptions.method,
|
|
1203
1303
|
headers: reqOptions.headers,
|
|
1204
1304
|
query: reqOptions.query
|
|
@@ -2424,7 +2524,7 @@ class ObservableSanityClient {
|
|
|
2424
2524
|
});
|
|
2425
2525
|
}
|
|
2426
2526
|
fetch(query, params, options) {
|
|
2427
|
-
return console.log("ObservableSanityClient.fetch called with:", {
|
|
2527
|
+
return console.log("[client-5] ObservableSanityClient.fetch called with:", {
|
|
2428
2528
|
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2429
2529
|
params,
|
|
2430
2530
|
options: {
|
|
@@ -2698,7 +2798,7 @@ class SanityClient {
|
|
|
2698
2798
|
});
|
|
2699
2799
|
}
|
|
2700
2800
|
fetch(query, params, options) {
|
|
2701
|
-
return console.log("SanityClient.fetch called with:", {
|
|
2801
|
+
return console.log("[client-5] SanityClient.fetch called with:", {
|
|
2702
2802
|
query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
|
|
2703
2803
|
params,
|
|
2704
2804
|
options: {
|