@sanity/client 7.11.2-audience-decide.4 → 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.
@@ -854,14 +854,14 @@ function requestOptions(config, overrides = {}) {
854
854
  });
855
855
  }
856
856
  function isDecideField(value) {
857
- console.log("isDecideField: checking value:", {
857
+ console.log("[client-5] 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("isDecideField: result:", {
864
+ return console.log("[client-5] 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("resolveDecideField: starting resolution:", {
872
+ console.log("[client-5] 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("resolveDecideField: audience processing:", {
885
+ if (console.log("[client-5] resolveDecideField: audience processing:", {
886
886
  audience,
887
887
  audienceType: typeof audience,
888
888
  isArray: Array.isArray(audience),
@@ -890,11 +890,11 @@ 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("resolveDecideField: no valid audience, returning default:", field.default), field.default;
894
- console.log("resolveDecideField: searching for matching condition...");
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
895
  const matchingCondition = field.conditions.find((condition, index) => {
896
896
  const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
897
- return console.log(`resolveDecideField: checking condition ${index}:`, {
897
+ return console.log(`[client-5] resolveDecideField: checking condition ${index}:`, {
898
898
  conditionAudience: condition.audience,
899
899
  conditionValue: condition.value,
900
900
  searchAudience: audience,
@@ -902,7 +902,7 @@ function resolveDecideField(field, decideParameters) {
902
902
  isMatch
903
903
  }), isMatch;
904
904
  }), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
905
- return console.log("resolveDecideField: resolution complete:", {
905
+ return console.log("[client-5] resolveDecideField: resolution complete:", {
906
906
  matchingCondition: matchingCondition ? {
907
907
  audience: matchingCondition.audience,
908
908
  value: matchingCondition.value
@@ -913,26 +913,26 @@ function resolveDecideField(field, decideParameters) {
913
913
  }
914
914
  function processObjectRecursively(obj, decideParameters, depth = 0, path = "root") {
915
915
  const indent = " ".repeat(depth);
916
- return console.log(`${indent}processObjectRecursively: processing at path '${path}':`, {
916
+ return console.log(`[client-5] ${indent}processObjectRecursively: processing at path '${path}':`, {
917
917
  type: typeof obj,
918
918
  isNull: obj === null,
919
919
  isUndefined: obj === void 0,
920
920
  isArray: Array.isArray(obj),
921
921
  depth,
922
922
  decideParameters
923
- }), obj == null || typeof obj != "object" ? (console.log(`${indent}processObjectRecursively: returning primitive/null value:`, obj), obj) : Array.isArray(obj) ? (console.log(`${indent}processObjectRecursively: processing array with ${obj.length} items`), obj.map((item, index) => (console.log(`${indent}processObjectRecursively: processing array item ${index}`), processObjectRecursively(item, decideParameters, depth + 1, `${path}[${index}]`)))) : (console.log(`${indent}processObjectRecursively: processing object with keys:`, Object.keys(obj)), Object.entries(obj).reduce((processed, [key, value]) => {
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
924
  const currentPath = `${path}.${key}`;
925
- console.log(`${indent}processObjectRecursively: processing key '${key}' at path '${currentPath}'`);
925
+ console.log(`[client-5] ${indent}processObjectRecursively: processing key '${key}' at path '${currentPath}'`);
926
926
  try {
927
- isDecideField(value) ? (console.log(`${indent}processObjectRecursively: '${key}' is a decide field, resolving...`), processed[key] = resolveDecideField(value, decideParameters), console.log(`${indent}processObjectRecursively: '${key}' resolved to:`, processed[key])) : (console.log(`${indent}processObjectRecursively: '${key}' is not a decide field, recursing...`), processed[key] = processObjectRecursively(value, decideParameters, depth + 1, currentPath));
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));
928
928
  } catch (error) {
929
- console.warn(`${indent}processObjectRecursively: 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;
930
930
  }
931
931
  return processed;
932
932
  }, {}));
933
933
  }
934
934
  function processDecideFields(data, decideParameters) {
935
- console.log("=== DECIDE FIELD PROCESSING START ==="), console.log("processDecideFields: analyzing response structure:", {
935
+ console.log("[client-5] === DECIDE FIELD PROCESSING START ==="), console.log("[client-5] processDecideFields: analyzing response structure:", {
936
936
  dataType: typeof data,
937
937
  isObject: typeof data == "object" && data !== null,
938
938
  hasResultsKey: typeof data == "object" && data !== null && "result" in data,
@@ -943,13 +943,13 @@ function processDecideFields(data, decideParameters) {
943
943
  const countDecideFields = (obj, path = "") => {
944
944
  obj == null || typeof obj != "object" || (Array.isArray(obj) ? obj.forEach((item, index) => countDecideFields(item, `${path}[${index}]`)) : Object.entries(obj).forEach(([key, value]) => {
945
945
  const currentPath = path ? `${path}.${key}` : key;
946
- isDecideField(value) ? (decideFieldCount++, console.log(`processDecideFields: Found decide field at path '${currentPath}':`, {
946
+ isDecideField(value) ? (decideFieldCount++, console.log(`[client-5] processDecideFields: Found decide field at path '${currentPath}':`, {
947
947
  default: value.default,
948
948
  conditionsCount: value.conditions.length
949
949
  })) : countDecideFields(value, currentPath);
950
950
  }));
951
951
  };
952
- console.log("processDecideFields: scanning for decide fields..."), countDecideFields(data), console.log(`processDecideFields: found ${decideFieldCount} decide fields in response`), console.log("processDecideFields: entry parameters:", {
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
953
  decideParameters,
954
954
  hasAudience: !!decideParameters?.audience,
955
955
  audience: decideParameters?.audience,
@@ -958,14 +958,14 @@ function processDecideFields(data, decideParameters) {
958
958
  dataPreview: typeof data == "object" && data !== null ? JSON.stringify(data, null, 2).substring(0, 500) + (JSON.stringify(data, null, 2).length > 500 ? "..." : "") : data
959
959
  });
960
960
  try {
961
- console.log("processDecideFields: starting recursive processing...");
961
+ console.log("[client-5] processDecideFields: starting recursive processing...");
962
962
  const result = processObjectRecursively(data, decideParameters);
963
- return console.log("processDecideFields: processing completed successfully"), console.log("processDecideFields: result preview:", {
963
+ return console.log("[client-5] processDecideFields: processing completed successfully"), console.log("[client-5] processDecideFields: result preview:", {
964
964
  resultType: typeof result,
965
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("=== DECIDE FIELD PROCESSING END ==="), result;
966
+ }), console.log("[client-5] === DECIDE FIELD PROCESSING END ==="), result;
967
967
  } catch (error) {
968
- return console.warn("processDecideFields: processing failed, returning original data:", error), console.log("=== DECIDE FIELD PROCESSING END (ERROR) ==="), data;
968
+ return console.warn("[client-5] processDecideFields: processing failed, returning original data:", error), console.log("[client-5] === DECIDE FIELD PROCESSING END (ERROR) ==="), data;
969
969
  }
970
970
  }
971
971
  const encodeQueryString = ({
@@ -989,7 +989,7 @@ const encodeQueryString = ({
989
989
  skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
990
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;
991
991
  function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
992
- console.log("_fetch called with:", {
992
+ console.log("[client-5] _fetch called with:", {
993
993
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
994
994
  params: _params,
995
995
  options: {
@@ -1002,16 +1002,16 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1002
1002
  ..._stega || {},
1003
1003
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
1004
1004
  } : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) => {
1005
- console.log("=== HTTP RESPONSE TO DECIDE PROCESSING ==="), console.log("processDecideResponse: received response for processing:", {
1005
+ console.log("[client-5] === HTTP RESPONSE TO DECIDE PROCESSING ==="), console.log("[client-5] processDecideResponse: received response for processing:", {
1006
1006
  responseType: typeof response,
1007
1007
  responseKeys: typeof response == "object" && response !== null ? Object.keys(response) : null,
1008
1008
  responsePreview: typeof response == "object" && response !== null ? JSON.stringify(response, null, 2).substring(0, 300) + (JSON.stringify(response, null, 2).length > 300 ? "..." : "") : response,
1009
1009
  audience: options.decideParameters?.audience,
1010
1010
  decideParameters: options.decideParameters,
1011
1011
  hasDecideParameters: !!options.decideParameters
1012
- }), console.log("processDecideResponse: calling processDecideFields...");
1012
+ }), console.log("[client-5] processDecideResponse: calling processDecideFields...");
1013
1013
  const processedData = processDecideFields(response, options.decideParameters);
1014
- return console.log("processDecideResponse: decide processing complete, returning processed data"), console.log("=== HTTP RESPONSE TO DECIDE PROCESSING COMPLETE ==="), processedData;
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
1015
  }, { cache, next, ...opts } = {
1016
1016
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
1017
1017
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
@@ -1023,7 +1023,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1023
1023
  // or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
1024
1024
  returnQuery: options.filterResponse === !1 && options.returnQuery !== !1
1025
1025
  }, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(client, httpRequest, "query", { query, params }, reqOpts);
1026
- return console.log("_fetch: pipeline setup, stega.enabled:", stega.enabled), stega.enabled ? $request.pipe(
1026
+ return console.log("[client-5] _fetch: pipeline setup, stega.enabled:", stega.enabled), stega.enabled ? $request.pipe(
1027
1027
  operators.combineLatestWith(
1028
1028
  rxjs.from(
1029
1029
  Promise.resolve().then(function() {
@@ -1037,16 +1037,16 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1037
1037
  ),
1038
1038
  operators.map(
1039
1039
  ([res, stegaEncodeSourceMap]) => {
1040
- console.log("_fetch: stega path - processing response");
1040
+ console.log("[client-5] _fetch: stega path - processing response");
1041
1041
  const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega), mappedResponse = mapResponse({ ...res, result });
1042
- return console.log("_fetch: stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
1042
+ return console.log("[client-5] _fetch: stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
1043
1043
  }
1044
1044
  )
1045
1045
  ) : $request.pipe(
1046
1046
  operators.map((res) => {
1047
- console.log("_fetch: non-stega path - processing response");
1047
+ console.log("[client-5] _fetch: non-stega path - processing response");
1048
1048
  const mappedResponse = mapResponse(res);
1049
- return console.log("_fetch: non-stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
1049
+ return console.log("[client-5] _fetch: non-stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
1050
1050
  })
1051
1051
  );
1052
1052
  }
@@ -1189,7 +1189,7 @@ function _action(client, httpRequest, actions, options) {
1189
1189
  );
1190
1190
  }
1191
1191
  function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
1192
- console.log("_dataRequest called with:", {
1192
+ console.log("[client-5] _dataRequest called with:", {
1193
1193
  endpoint,
1194
1194
  body: endpoint === "query" ? {
1195
1195
  query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
@@ -1223,7 +1223,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
1223
1223
  useAbortSignal: options.useAbortSignal,
1224
1224
  useCdn: options.useCdn
1225
1225
  };
1226
- return console.log("_dataRequest calling _requestObservable with reqOptions:", {
1226
+ return console.log("[client-5] _dataRequest calling _requestObservable with reqOptions:", {
1227
1227
  ...reqOptions,
1228
1228
  decideParameters: reqOptions.decideParameters,
1229
1229
  perspective: reqOptions.perspective,
@@ -1256,7 +1256,7 @@ function _create(client, httpRequest, doc, op, options = {}) {
1256
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);
1257
1257
  function _requestObservable(client, httpRequest, options) {
1258
1258
  const uri = options.url || options.uri, config = client.config();
1259
- console.log("_requestObservable called with options:", {
1259
+ console.log("[client-5] _requestObservable called with options:", {
1260
1260
  uri,
1261
1261
  method: options.method,
1262
1262
  decideParameters: options.decideParameters,
@@ -1277,28 +1277,28 @@ function _requestObservable(client, httpRequest, options) {
1277
1277
  }, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
1278
1278
  perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
1279
1279
  const decideParametersOption = options.decideParameters || config.decideParameters;
1280
- console.log("Processing decideParameters:", {
1280
+ console.log("[client-5] Processing decideParameters:", {
1281
1281
  optionsDecideParameters: options.decideParameters,
1282
1282
  configDecideParameters: config.decideParameters,
1283
1283
  finalDecideParametersOption: decideParametersOption
1284
1284
  }), decideParametersOption && typeof decideParametersOption == "object" ? (console.log(
1285
- "DecideParameters received - keeping for response processing only:",
1285
+ "[client-5] DecideParameters received - keeping for response processing only:",
1286
1286
  decideParametersOption
1287
1287
  ), console.log(
1288
- "DecideParameters will be preserved for response processing but not sent in HTTP request"
1289
- )) : 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 });
1290
1290
  }
1291
1291
  const finalOptions = Object.assign({}, options, {
1292
1292
  url: _getUrl(client, uri, useCdn)
1293
1293
  });
1294
- console.log("Final options before requestOptions call:", {
1294
+ console.log("[client-5] Final options before requestOptions call:", {
1295
1295
  url: finalOptions.url,
1296
1296
  decideParameters: finalOptions.decideParameters,
1297
1297
  query: finalOptions.query,
1298
1298
  method: finalOptions.method
1299
1299
  });
1300
1300
  const reqOptions = requestOptions(config, finalOptions);
1301
- console.log("Final reqOptions from requestOptions:", {
1301
+ console.log("[client-5] Final reqOptions from requestOptions:", {
1302
1302
  method: reqOptions.method,
1303
1303
  headers: reqOptions.headers,
1304
1304
  query: reqOptions.query
@@ -2524,7 +2524,7 @@ class ObservableSanityClient {
2524
2524
  });
2525
2525
  }
2526
2526
  fetch(query, params, options) {
2527
- return console.log("ObservableSanityClient.fetch called with:", {
2527
+ return console.log("[client-5] ObservableSanityClient.fetch called with:", {
2528
2528
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2529
2529
  params,
2530
2530
  options: {
@@ -2798,7 +2798,7 @@ class SanityClient {
2798
2798
  });
2799
2799
  }
2800
2800
  fetch(query, params, options) {
2801
- return console.log("SanityClient.fetch called with:", {
2801
+ return console.log("[client-5] SanityClient.fetch called with:", {
2802
2802
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2803
2803
  params,
2804
2804
  options: {