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

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,22 +854,10 @@ function requestOptions(config, overrides = {}) {
854
854
  });
855
855
  }
856
856
  function isDecideField(value) {
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;
857
+ return value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
870
858
  }
871
859
  function resolveDecideField(field, decideParameters) {
872
- console.log("[client-5] resolveDecideField: starting resolution:", {
860
+ console.log("[client-6] resolveDecideField: starting resolution:", {
873
861
  field: {
874
862
  default: field.default,
875
863
  conditionsCount: field.conditions.length,
@@ -882,7 +870,7 @@ function resolveDecideField(field, decideParameters) {
882
870
  decideParameters
883
871
  });
884
872
  const audience = decideParameters?.audience;
885
- if (console.log("[client-5] resolveDecideField: audience processing:", {
873
+ if (console.log("[client-6] resolveDecideField: audience processing:", {
886
874
  audience,
887
875
  audienceType: typeof audience,
888
876
  isArray: Array.isArray(audience),
@@ -890,11 +878,14 @@ function resolveDecideField(field, decideParameters) {
890
878
  isUndefined: audience === void 0,
891
879
  isNull: audience === null
892
880
  }), !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...");
881
+ return console.log(
882
+ "[client-6] resolveDecideField: no valid audience, returning default:",
883
+ field.default
884
+ ), field.default;
885
+ console.log("[client-6] resolveDecideField: searching for matching condition...");
895
886
  const matchingCondition = field.conditions.find((condition, index) => {
896
887
  const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
897
- return console.log(`[client-5] resolveDecideField: checking condition ${index}:`, {
888
+ return console.log(`[client-6] resolveDecideField: checking condition ${index}:`, {
898
889
  conditionAudience: condition.audience,
899
890
  conditionValue: condition.value,
900
891
  searchAudience: audience,
@@ -902,7 +893,7 @@ function resolveDecideField(field, decideParameters) {
902
893
  isMatch
903
894
  }), isMatch;
904
895
  }), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
905
- return console.log("[client-5] resolveDecideField: resolution complete:", {
896
+ return console.log("[client-6] resolveDecideField: resolution complete:", {
906
897
  matchingCondition: matchingCondition ? {
907
898
  audience: matchingCondition.audience,
908
899
  value: matchingCondition.value
@@ -912,60 +903,26 @@ function resolveDecideField(field, decideParameters) {
912
903
  }), resolvedValue;
913
904
  }
914
905
  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}'`);
906
+ return obj == null || typeof obj != "object" ? obj : Array.isArray(obj) ? obj.map(
907
+ (item, index) => processObjectRecursively(item, decideParameters, depth + 1, `${path}[${index}]`)
908
+ ) : Object.entries(obj).reduce((processed, [key, value]) => {
909
+ const currentPath = `${path}.${key}`, isDecide = isDecideField(value);
910
+ console.log(`[client-6] Key: '${key}', isDecideField: ${isDecide}`);
926
911
  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));
928
- } catch (error) {
929
- console.warn(`[client-5] ${indent}processObjectRecursively: Failed to process decide field '${key}':`, error), processed[key] = value;
912
+ isDecide ? processed[key] = resolveDecideField(value, decideParameters) : processed[key] = processObjectRecursively(value, decideParameters, depth + 1, currentPath);
913
+ } catch {
914
+ processed[key] = value;
930
915
  }
931
916
  return processed;
932
- }, {}));
917
+ }, {});
933
918
  }
934
919
  function processDecideFields(data, decideParameters) {
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
- });
920
+ console.log("[client-6] === DECIDE FIELD PROCESSING START ===");
960
921
  try {
961
- console.log("[client-5] processDecideFields: starting recursive processing...");
962
922
  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;
923
+ return console.log("[client-6] === DECIDE FIELD PROCESSING END ==="), result;
967
924
  } 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;
925
+ return console.warn("[client-6] processDecideFields: processing failed, returning original data:", error), data;
969
926
  }
970
927
  }
971
928
  const encodeQueryString = ({
@@ -989,7 +946,7 @@ const encodeQueryString = ({
989
946
  skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
990
947
  }), 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
948
  function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
992
- console.log("[client-5] _fetch called with:", {
949
+ console.log("[client-6] _fetch called with:", {
993
950
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
994
951
  params: _params,
995
952
  options: {
@@ -1002,16 +959,18 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1002
959
  ..._stega || {},
1003
960
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
1004
961
  } : _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:", {
962
+ console.log("[client-6] === HTTP RESPONSE TO DECIDE PROCESSING ==="), console.log("[client-6] processDecideResponse: received response for processing:", {
1006
963
  responseType: typeof response,
1007
964
  responseKeys: typeof response == "object" && response !== null ? Object.keys(response) : null,
1008
965
  responsePreview: typeof response == "object" && response !== null ? JSON.stringify(response, null, 2).substring(0, 300) + (JSON.stringify(response, null, 2).length > 300 ? "..." : "") : response,
1009
966
  audience: options.decideParameters?.audience,
1010
967
  decideParameters: options.decideParameters,
1011
968
  hasDecideParameters: !!options.decideParameters
1012
- }), console.log("[client-5] processDecideResponse: calling processDecideFields...");
969
+ }), console.log("[client-6] processDecideResponse: calling processDecideFields...");
1013
970
  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;
971
+ return console.log(
972
+ "[client-6] processDecideResponse: decide processing complete, returning processed data"
973
+ ), console.log("[client-6] === HTTP RESPONSE TO DECIDE PROCESSING COMPLETE ==="), processedData;
1015
974
  }, { cache, next, ...opts } = {
1016
975
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
1017
976
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
@@ -1023,7 +982,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1023
982
  // or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
1024
983
  returnQuery: options.filterResponse === !1 && options.returnQuery !== !1
1025
984
  }, 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(
985
+ return console.log("[client-6] _fetch: pipeline setup, stega.enabled:", stega.enabled), stega.enabled ? $request.pipe(
1027
986
  operators.combineLatestWith(
1028
987
  rxjs.from(
1029
988
  Promise.resolve().then(function() {
@@ -1037,16 +996,18 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1037
996
  ),
1038
997
  operators.map(
1039
998
  ([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);
999
+ console.log("[client-6] _fetch: stega path - processing response");
1000
+ const processedResult = processDecideFields(res.result, options.decideParameters), result = stegaEncodeSourceMap(processedResult, res.resultSourceMap, stega), mappedResponse = mapResponse({ ...res, result });
1001
+ return console.log(
1002
+ "[client-6] _fetch: stega path - decide processing completed before stega encoding"
1003
+ ), mappedResponse;
1043
1004
  }
1044
1005
  )
1045
1006
  ) : $request.pipe(
1046
1007
  operators.map((res) => {
1047
- console.log("[client-5] _fetch: non-stega path - processing response");
1008
+ console.log("[client-6] _fetch: non-stega path - processing response");
1048
1009
  const mappedResponse = mapResponse(res);
1049
- return console.log("[client-5] _fetch: non-stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
1010
+ return console.log("[client-6] _fetch: non-stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
1050
1011
  })
1051
1012
  );
1052
1013
  }
@@ -1189,7 +1150,7 @@ function _action(client, httpRequest, actions, options) {
1189
1150
  );
1190
1151
  }
1191
1152
  function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
1192
- console.log("[client-5] _dataRequest called with:", {
1153
+ console.log("[client-6] _dataRequest called with:", {
1193
1154
  endpoint,
1194
1155
  body: endpoint === "query" ? {
1195
1156
  query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
@@ -1223,7 +1184,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
1223
1184
  useAbortSignal: options.useAbortSignal,
1224
1185
  useCdn: options.useCdn
1225
1186
  };
1226
- return console.log("[client-5] _dataRequest calling _requestObservable with reqOptions:", {
1187
+ return console.log("[client-6] _dataRequest calling _requestObservable with reqOptions:", {
1227
1188
  ...reqOptions,
1228
1189
  decideParameters: reqOptions.decideParameters,
1229
1190
  perspective: reqOptions.perspective,
@@ -1256,7 +1217,7 @@ function _create(client, httpRequest, doc, op, options = {}) {
1256
1217
  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
1218
  function _requestObservable(client, httpRequest, options) {
1258
1219
  const uri = options.url || options.uri, config = client.config();
1259
- console.log("[client-5] _requestObservable called with options:", {
1220
+ console.log("[client-6] _requestObservable called with options:", {
1260
1221
  uri,
1261
1222
  method: options.method,
1262
1223
  decideParameters: options.decideParameters,
@@ -1277,28 +1238,28 @@ function _requestObservable(client, httpRequest, options) {
1277
1238
  }, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
1278
1239
  perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
1279
1240
  const decideParametersOption = options.decideParameters || config.decideParameters;
1280
- console.log("[client-5] Processing decideParameters:", {
1241
+ console.log("[client-6] Processing decideParameters:", {
1281
1242
  optionsDecideParameters: options.decideParameters,
1282
1243
  configDecideParameters: config.decideParameters,
1283
1244
  finalDecideParametersOption: decideParametersOption
1284
1245
  }), decideParametersOption && typeof decideParametersOption == "object" ? (console.log(
1285
- "[client-5] DecideParameters received - keeping for response processing only:",
1246
+ "[client-6] DecideParameters received - keeping for response processing only:",
1286
1247
  decideParametersOption
1287
1248
  ), 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 });
1249
+ "[client-6] DecideParameters will be preserved for response processing but not sent in HTTP request"
1250
+ )) : 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
1251
  }
1291
1252
  const finalOptions = Object.assign({}, options, {
1292
1253
  url: _getUrl(client, uri, useCdn)
1293
1254
  });
1294
- console.log("[client-5] Final options before requestOptions call:", {
1255
+ console.log("[client-6] Final options before requestOptions call:", {
1295
1256
  url: finalOptions.url,
1296
1257
  decideParameters: finalOptions.decideParameters,
1297
1258
  query: finalOptions.query,
1298
1259
  method: finalOptions.method
1299
1260
  });
1300
1261
  const reqOptions = requestOptions(config, finalOptions);
1301
- console.log("[client-5] Final reqOptions from requestOptions:", {
1262
+ console.log("[client-6] Final reqOptions from requestOptions:", {
1302
1263
  method: reqOptions.method,
1303
1264
  headers: reqOptions.headers,
1304
1265
  query: reqOptions.query
@@ -2524,7 +2485,7 @@ class ObservableSanityClient {
2524
2485
  });
2525
2486
  }
2526
2487
  fetch(query, params, options) {
2527
- return console.log("[client-5] ObservableSanityClient.fetch called with:", {
2488
+ return console.log("[client-6] ObservableSanityClient.fetch called with:", {
2528
2489
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2529
2490
  params,
2530
2491
  options: {
@@ -2798,7 +2759,7 @@ class SanityClient {
2798
2759
  });
2799
2760
  }
2800
2761
  fetch(query, params, options) {
2801
- return console.log("[client-5] SanityClient.fetch called with:", {
2762
+ return console.log("[client-6] SanityClient.fetch called with:", {
2802
2763
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2803
2764
  params,
2804
2765
  options: {