@sanity/client 7.11.2-audience-decide.5 → 7.11.2-audience-decide.6

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.
@@ -854,14 +854,14 @@ function requestOptions(config, overrides = {}) {
854
854
  });
855
855
  }
856
856
  function isDecideField(value) {
857
- console.log("[client-5] isDecideField: checking value:", {
857
+ console.log("[client-6] isDecideField: checking value:", {
858
858
  value: typeof value == "object" ? JSON.stringify(value, null, 2) : value,
859
859
  type: typeof value,
860
860
  isNull: value === null,
861
861
  isArray: Array.isArray(value)
862
862
  });
863
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:", {
864
+ return console.log("[client-6] isDecideField: result:", {
865
865
  isValid,
866
866
  hasDefault: value != null && typeof value == "object" && "default" in value,
867
867
  hasConditions: value != null && typeof value == "object" && "conditions" in value,
@@ -869,7 +869,7 @@ function isDecideField(value) {
869
869
  }), isValid;
870
870
  }
871
871
  function resolveDecideField(field, decideParameters) {
872
- console.log("[client-5] resolveDecideField: starting resolution:", {
872
+ console.log("[client-6] resolveDecideField: starting resolution:", {
873
873
  field: {
874
874
  default: field.default,
875
875
  conditionsCount: field.conditions.length,
@@ -882,7 +882,7 @@ function resolveDecideField(field, decideParameters) {
882
882
  decideParameters
883
883
  });
884
884
  const audience = decideParameters?.audience;
885
- if (console.log("[client-5] resolveDecideField: audience processing:", {
885
+ if (console.log("[client-6] resolveDecideField: audience processing:", {
886
886
  audience,
887
887
  audienceType: typeof audience,
888
888
  isArray: Array.isArray(audience),
@@ -890,11 +890,14 @@ function resolveDecideField(field, decideParameters) {
890
890
  isUndefined: audience === void 0,
891
891
  isNull: audience === null
892
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...");
893
+ return console.log(
894
+ "[client-6] resolveDecideField: no valid audience, returning default:",
895
+ field.default
896
+ ), field.default;
897
+ console.log("[client-6] resolveDecideField: searching for matching condition...");
895
898
  const matchingCondition = field.conditions.find((condition, index) => {
896
899
  const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
897
- return console.log(`[client-5] resolveDecideField: checking condition ${index}:`, {
900
+ return console.log(`[client-6] resolveDecideField: checking condition ${index}:`, {
898
901
  conditionAudience: condition.audience,
899
902
  conditionValue: condition.value,
900
903
  searchAudience: audience,
@@ -902,7 +905,7 @@ function resolveDecideField(field, decideParameters) {
902
905
  isMatch
903
906
  }), isMatch;
904
907
  }), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
905
- return console.log("[client-5] resolveDecideField: resolution complete:", {
908
+ return console.log("[client-6] resolveDecideField: resolution complete:", {
906
909
  matchingCondition: matchingCondition ? {
907
910
  audience: matchingCondition.audience,
908
911
  value: matchingCondition.value
@@ -913,26 +916,46 @@ function resolveDecideField(field, decideParameters) {
913
916
  }
914
917
  function processObjectRecursively(obj, decideParameters, depth = 0, path = "root") {
915
918
  const indent = " ".repeat(depth);
916
- return console.log(`[client-5] ${indent}processObjectRecursively: processing at path '${path}':`, {
919
+ return console.log(`[client-6] ${indent}processObjectRecursively: processing at path '${path}':`, {
917
920
  type: typeof obj,
918
921
  isNull: obj === null,
919
922
  isUndefined: obj === void 0,
920
923
  isArray: Array.isArray(obj),
921
924
  depth,
922
925
  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]) => {
926
+ }), obj == null || typeof obj != "object" ? (console.log(
927
+ `[client-6] ${indent}processObjectRecursively: returning primitive/null value:`,
928
+ obj
929
+ ), obj) : Array.isArray(obj) ? (console.log(
930
+ `[client-6] ${indent}processObjectRecursively: processing array with ${obj.length} items`
931
+ ), obj.map((item, index) => (console.log(`[client-6] ${indent}processObjectRecursively: processing array item ${index}`), processObjectRecursively(item, decideParameters, depth + 1, `${path}[${index}]`)))) : (console.log(
932
+ `[client-6] ${indent}processObjectRecursively: processing object with keys:`,
933
+ Object.keys(obj)
934
+ ), Object.entries(obj).reduce((processed, [key, value]) => {
924
935
  const currentPath = `${path}.${key}`;
925
- console.log(`[client-5] ${indent}processObjectRecursively: processing key '${key}' at path '${currentPath}'`);
936
+ console.log(
937
+ `[client-6] ${indent}processObjectRecursively: processing key '${key}' at path '${currentPath}'`
938
+ );
926
939
  try {
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));
940
+ isDecideField(value) ? (console.log(
941
+ `[client-6] ${indent}processObjectRecursively: '${key}' is a decide field, resolving...`
942
+ ), processed[key] = resolveDecideField(value, decideParameters), console.log(
943
+ `[client-6] ${indent}processObjectRecursively: '${key}' resolved to:`,
944
+ processed[key]
945
+ )) : (console.log(
946
+ `[client-6] ${indent}processObjectRecursively: '${key}' is not a decide field, recursing...`
947
+ ), processed[key] = processObjectRecursively(value, decideParameters, depth + 1, currentPath));
928
948
  } catch (error) {
929
- console.warn(`[client-5] ${indent}processObjectRecursively: Failed to process decide field '${key}':`, error), processed[key] = value;
949
+ console.warn(
950
+ `[client-6] ${indent}processObjectRecursively: Failed to process decide field '${key}':`,
951
+ error
952
+ ), processed[key] = value;
930
953
  }
931
954
  return processed;
932
955
  }, {}));
933
956
  }
934
957
  function processDecideFields(data, decideParameters) {
935
- console.log("[client-5] === DECIDE FIELD PROCESSING START ==="), console.log("[client-5] processDecideFields: analyzing response structure:", {
958
+ console.log("[client-6] === DECIDE FIELD PROCESSING START ==="), console.log("[client-6] processDecideFields: analyzing response structure:", {
936
959
  dataType: typeof data,
937
960
  isObject: typeof data == "object" && data !== null,
938
961
  hasResultsKey: typeof data == "object" && data !== null && "result" in data,
@@ -943,13 +966,16 @@ function processDecideFields(data, decideParameters) {
943
966
  const countDecideFields = (obj, path = "") => {
944
967
  obj == null || typeof obj != "object" || (Array.isArray(obj) ? obj.forEach((item, index) => countDecideFields(item, `${path}[${index}]`)) : Object.entries(obj).forEach(([key, value]) => {
945
968
  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);
969
+ isDecideField(value) ? (decideFieldCount++, console.log(
970
+ `[client-6] processDecideFields: Found decide field at path '${currentPath}':`,
971
+ {
972
+ default: value.default,
973
+ conditionsCount: value.conditions.length
974
+ }
975
+ )) : countDecideFields(value, currentPath);
950
976
  }));
951
977
  };
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:", {
978
+ console.log("[client-6] processDecideFields: scanning for decide fields..."), countDecideFields(data), console.log(`[client-6] processDecideFields: found ${decideFieldCount} decide fields in response`), console.log("[client-6] processDecideFields: entry parameters:", {
953
979
  decideParameters,
954
980
  hasAudience: !!decideParameters?.audience,
955
981
  audience: decideParameters?.audience,
@@ -958,14 +984,17 @@ function processDecideFields(data, decideParameters) {
958
984
  dataPreview: typeof data == "object" && data !== null ? JSON.stringify(data, null, 2).substring(0, 500) + (JSON.stringify(data, null, 2).length > 500 ? "..." : "") : data
959
985
  });
960
986
  try {
961
- console.log("[client-5] processDecideFields: starting recursive processing...");
987
+ console.log("[client-6] processDecideFields: starting recursive processing...");
962
988
  const result = processObjectRecursively(data, decideParameters);
963
- return console.log("[client-5] processDecideFields: processing completed successfully"), console.log("[client-5] processDecideFields: result preview:", {
989
+ return console.log("[client-6] processDecideFields: processing completed successfully"), console.log("[client-6] processDecideFields: result preview:", {
964
990
  resultType: typeof result,
965
991
  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;
992
+ }), console.log("[client-6] === DECIDE FIELD PROCESSING END ==="), result;
967
993
  } catch (error) {
968
- return console.warn("[client-5] processDecideFields: processing failed, returning original data:", error), console.log("[client-5] === DECIDE FIELD PROCESSING END (ERROR) ==="), data;
994
+ return console.warn(
995
+ "[client-6] processDecideFields: processing failed, returning original data:",
996
+ error
997
+ ), console.log("[client-6] === DECIDE FIELD PROCESSING END (ERROR) ==="), data;
969
998
  }
970
999
  }
971
1000
  const encodeQueryString = ({
@@ -989,7 +1018,7 @@ const encodeQueryString = ({
989
1018
  skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
990
1019
  }), 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;
991
1020
  function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
992
- console.log("[client-5] _fetch called with:", {
1021
+ console.log("[client-6] _fetch called with:", {
993
1022
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
994
1023
  params: _params,
995
1024
  options: {
@@ -1002,16 +1031,18 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1002
1031
  ..._stega || {},
1003
1032
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
1004
1033
  } : _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:", {
1034
+ console.log("[client-6] === HTTP RESPONSE TO DECIDE PROCESSING ==="), console.log("[client-6] processDecideResponse: received response for processing:", {
1006
1035
  responseType: typeof response,
1007
1036
  responseKeys: typeof response == "object" && response !== null ? Object.keys(response) : null,
1008
1037
  responsePreview: typeof response == "object" && response !== null ? JSON.stringify(response, null, 2).substring(0, 300) + (JSON.stringify(response, null, 2).length > 300 ? "..." : "") : response,
1009
1038
  audience: options.decideParameters?.audience,
1010
1039
  decideParameters: options.decideParameters,
1011
1040
  hasDecideParameters: !!options.decideParameters
1012
- }), console.log("[client-5] processDecideResponse: calling processDecideFields...");
1041
+ }), console.log("[client-6] processDecideResponse: calling processDecideFields...");
1013
1042
  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;
1043
+ return console.log(
1044
+ "[client-6] processDecideResponse: decide processing complete, returning processed data"
1045
+ ), console.log("[client-6] === HTTP RESPONSE TO DECIDE PROCESSING COMPLETE ==="), processedData;
1015
1046
  }, { cache, next, ...opts } = {
1016
1047
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
1017
1048
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
@@ -1023,7 +1054,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1023
1054
  // or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
1024
1055
  returnQuery: options.filterResponse === !1 && options.returnQuery !== !1
1025
1056
  }, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(client, httpRequest, "query", { query, params }, reqOpts);
1026
- return console.log("[client-5] _fetch: pipeline setup, stega.enabled:", stega.enabled), stega.enabled ? $request.pipe(
1057
+ return console.log("[client-6] _fetch: pipeline setup, stega.enabled:", stega.enabled), stega.enabled ? $request.pipe(
1027
1058
  operators.combineLatestWith(
1028
1059
  rxjs.from(
1029
1060
  Promise.resolve().then(function() {
@@ -1037,16 +1068,18 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1037
1068
  ),
1038
1069
  operators.map(
1039
1070
  ([res, stegaEncodeSourceMap]) => {
1040
- console.log("[client-5] _fetch: stega path - processing response");
1041
- const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega), mappedResponse = mapResponse({ ...res, result });
1042
- return console.log("[client-5] _fetch: stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
1071
+ console.log("[client-6] _fetch: stega path - processing response");
1072
+ const processedResult = processDecideFields(res.result, options.decideParameters), result = stegaEncodeSourceMap(processedResult, res.resultSourceMap, stega), mappedResponse = mapResponse({ ...res, result });
1073
+ return console.log(
1074
+ "[client-6] _fetch: stega path - decide processing completed before stega encoding"
1075
+ ), mappedResponse;
1043
1076
  }
1044
1077
  )
1045
1078
  ) : $request.pipe(
1046
1079
  operators.map((res) => {
1047
- console.log("[client-5] _fetch: non-stega path - processing response");
1080
+ console.log("[client-6] _fetch: non-stega path - processing response");
1048
1081
  const mappedResponse = mapResponse(res);
1049
- return console.log("[client-5] _fetch: non-stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
1082
+ return console.log("[client-6] _fetch: non-stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
1050
1083
  })
1051
1084
  );
1052
1085
  }
@@ -1189,7 +1222,7 @@ function _action(client, httpRequest, actions, options) {
1189
1222
  );
1190
1223
  }
1191
1224
  function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
1192
- console.log("[client-5] _dataRequest called with:", {
1225
+ console.log("[client-6] _dataRequest called with:", {
1193
1226
  endpoint,
1194
1227
  body: endpoint === "query" ? {
1195
1228
  query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
@@ -1223,7 +1256,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
1223
1256
  useAbortSignal: options.useAbortSignal,
1224
1257
  useCdn: options.useCdn
1225
1258
  };
1226
- return console.log("[client-5] _dataRequest calling _requestObservable with reqOptions:", {
1259
+ return console.log("[client-6] _dataRequest calling _requestObservable with reqOptions:", {
1227
1260
  ...reqOptions,
1228
1261
  decideParameters: reqOptions.decideParameters,
1229
1262
  perspective: reqOptions.perspective,
@@ -1256,7 +1289,7 @@ function _create(client, httpRequest, doc, op, options = {}) {
1256
1289
  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);
1257
1290
  function _requestObservable(client, httpRequest, options) {
1258
1291
  const uri = options.url || options.uri, config = client.config();
1259
- console.log("[client-5] _requestObservable called with options:", {
1292
+ console.log("[client-6] _requestObservable called with options:", {
1260
1293
  uri,
1261
1294
  method: options.method,
1262
1295
  decideParameters: options.decideParameters,
@@ -1277,28 +1310,28 @@ function _requestObservable(client, httpRequest, options) {
1277
1310
  }, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
1278
1311
  perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
1279
1312
  const decideParametersOption = options.decideParameters || config.decideParameters;
1280
- console.log("[client-5] Processing decideParameters:", {
1313
+ console.log("[client-6] Processing decideParameters:", {
1281
1314
  optionsDecideParameters: options.decideParameters,
1282
1315
  configDecideParameters: config.decideParameters,
1283
1316
  finalDecideParametersOption: decideParametersOption
1284
1317
  }), decideParametersOption && typeof decideParametersOption == "object" ? (console.log(
1285
- "[client-5] DecideParameters received - keeping for response processing only:",
1318
+ "[client-6] DecideParameters received - keeping for response processing only:",
1286
1319
  decideParametersOption
1287
1320
  ), console.log(
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 });
1321
+ "[client-6] DecideParameters will be preserved for response processing but not sent in HTTP request"
1322
+ )) : console.log("[client-6] 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 });
1290
1323
  }
1291
1324
  const finalOptions = Object.assign({}, options, {
1292
1325
  url: _getUrl(client, uri, useCdn)
1293
1326
  });
1294
- console.log("[client-5] Final options before requestOptions call:", {
1327
+ console.log("[client-6] Final options before requestOptions call:", {
1295
1328
  url: finalOptions.url,
1296
1329
  decideParameters: finalOptions.decideParameters,
1297
1330
  query: finalOptions.query,
1298
1331
  method: finalOptions.method
1299
1332
  });
1300
1333
  const reqOptions = requestOptions(config, finalOptions);
1301
- console.log("[client-5] Final reqOptions from requestOptions:", {
1334
+ console.log("[client-6] Final reqOptions from requestOptions:", {
1302
1335
  method: reqOptions.method,
1303
1336
  headers: reqOptions.headers,
1304
1337
  query: reqOptions.query
@@ -2524,7 +2557,7 @@ class ObservableSanityClient {
2524
2557
  });
2525
2558
  }
2526
2559
  fetch(query, params, options) {
2527
- return console.log("[client-5] ObservableSanityClient.fetch called with:", {
2560
+ return console.log("[client-6] ObservableSanityClient.fetch called with:", {
2528
2561
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2529
2562
  params,
2530
2563
  options: {
@@ -2798,7 +2831,7 @@ class SanityClient {
2798
2831
  });
2799
2832
  }
2800
2833
  fetch(query, params, options) {
2801
- return console.log("[client-5] SanityClient.fetch called with:", {
2834
+ return console.log("[client-6] SanityClient.fetch called with:", {
2802
2835
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2803
2836
  params,
2804
2837
  options: {