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

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-6] 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-6] 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-6] resolveDecideField: starting resolution:", {
860
+ console.log("[client-8] 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-6] resolveDecideField: audience processing:", {
873
+ if (console.log("[client-8] resolveDecideField: audience processing:", {
886
874
  audience,
887
875
  audienceType: typeof audience,
888
876
  isArray: Array.isArray(audience),
@@ -891,13 +879,13 @@ function resolveDecideField(field, decideParameters) {
891
879
  isNull: audience === null
892
880
  }), !audience || Array.isArray(audience) && audience.length === 0 || audience === "")
893
881
  return console.log(
894
- "[client-6] resolveDecideField: no valid audience, returning default:",
882
+ "[client-8] resolveDecideField: no valid audience, returning default:",
895
883
  field.default
896
884
  ), field.default;
897
- console.log("[client-6] resolveDecideField: searching for matching condition...");
885
+ console.log("[client-8] resolveDecideField: searching for matching condition...");
898
886
  const matchingCondition = field.conditions.find((condition, index) => {
899
887
  const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
900
- return console.log(`[client-6] resolveDecideField: checking condition ${index}:`, {
888
+ return console.log(`[client-8] resolveDecideField: checking condition ${index}:`, {
901
889
  conditionAudience: condition.audience,
902
890
  conditionValue: condition.value,
903
891
  searchAudience: audience,
@@ -905,7 +893,7 @@ function resolveDecideField(field, decideParameters) {
905
893
  isMatch
906
894
  }), isMatch;
907
895
  }), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
908
- return console.log("[client-6] resolveDecideField: resolution complete:", {
896
+ return console.log("[client-8] resolveDecideField: resolution complete:", {
909
897
  matchingCondition: matchingCondition ? {
910
898
  audience: matchingCondition.audience,
911
899
  value: matchingCondition.value
@@ -915,86 +903,28 @@ function resolveDecideField(field, decideParameters) {
915
903
  }), resolvedValue;
916
904
  }
917
905
  function processObjectRecursively(obj, decideParameters, depth = 0, path = "root") {
918
- const indent = " ".repeat(depth);
919
- return console.log(`[client-6] ${indent}processObjectRecursively: processing at path '${path}':`, {
920
- type: typeof obj,
921
- isNull: obj === null,
922
- isUndefined: obj === void 0,
923
- isArray: Array.isArray(obj),
924
- depth,
925
- decideParameters
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]) => {
935
- const currentPath = `${path}.${key}`;
936
- console.log(
937
- `[client-6] ${indent}processObjectRecursively: processing key '${key}' at path '${currentPath}'`
938
- );
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);
939
910
  try {
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));
948
- } catch (error) {
949
- console.warn(
950
- `[client-6] ${indent}processObjectRecursively: Failed to process decide field '${key}':`,
951
- error
952
- ), processed[key] = value;
911
+ isDecide ? (console.log(`[client-8] DECIDE FIELD FOUND: Key: '${key}'`), processed[key] = resolveDecideField(value, decideParameters)) : processed[key] = processObjectRecursively(value, decideParameters, depth + 1, currentPath);
912
+ } catch {
913
+ processed[key] = value;
953
914
  }
954
915
  return processed;
955
- }, {}));
916
+ }, {});
956
917
  }
957
918
  function processDecideFields(data, decideParameters) {
958
- console.log("[client-6] === DECIDE FIELD PROCESSING START ==="), console.log("[client-6] processDecideFields: analyzing response structure:", {
959
- dataType: typeof data,
960
- isObject: typeof data == "object" && data !== null,
961
- hasResultsKey: typeof data == "object" && data !== null && "result" in data,
962
- hasDocumentsKey: typeof data == "object" && data !== null && "documents" in data,
963
- topLevelKeys: typeof data == "object" && data !== null ? Object.keys(data) : null
964
- });
965
- let decideFieldCount = 0;
966
- const countDecideFields = (obj, path = "") => {
967
- obj == null || typeof obj != "object" || (Array.isArray(obj) ? obj.forEach((item, index) => countDecideFields(item, `${path}[${index}]`)) : Object.entries(obj).forEach(([key, value]) => {
968
- const currentPath = path ? `${path}.${key}` : key;
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);
976
- }));
977
- };
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:", {
979
- decideParameters,
980
- hasAudience: !!decideParameters?.audience,
981
- audience: decideParameters?.audience,
982
- audienceType: typeof decideParameters?.audience,
983
- dataType: typeof data,
984
- dataPreview: typeof data == "object" && data !== null ? JSON.stringify(data, null, 2).substring(0, 500) + (JSON.stringify(data, null, 2).length > 500 ? "..." : "") : data
985
- });
919
+ console.log("[client-8] === DECIDE FIELD PROCESSING START ===");
986
920
  try {
987
- console.log("[client-6] processDecideFields: starting recursive processing...");
988
921
  const result = processObjectRecursively(data, decideParameters);
989
- return console.log("[client-6] processDecideFields: processing completed successfully"), console.log("[client-6] processDecideFields: result preview:", {
990
- resultType: typeof result,
991
- resultPreview: typeof result == "object" && result !== null ? JSON.stringify(result, null, 2).substring(0, 500) + (JSON.stringify(result, null, 2).length > 500 ? "..." : "") : result
992
- }), console.log("[client-6] === DECIDE FIELD PROCESSING END ==="), result;
922
+ return console.log("[client-8] === DECIDE FIELD PROCESSING END ==="), result;
993
923
  } catch (error) {
994
924
  return console.warn(
995
- "[client-6] processDecideFields: processing failed, returning original data:",
925
+ "[client-8] processDecideFields: processing failed, returning original data:",
996
926
  error
997
- ), console.log("[client-6] === DECIDE FIELD PROCESSING END (ERROR) ==="), data;
927
+ ), data;
998
928
  }
999
929
  }
1000
930
  const encodeQueryString = ({
@@ -1018,32 +948,10 @@ const encodeQueryString = ({
1018
948
  skipCrossDatasetReferenceValidation: options.skipCrossDatasetReferenceValidation
1019
949
  }), 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;
1020
950
  function _fetch(client, httpRequest, _stega, query, _params = {}, options = {}) {
1021
- console.log("[client-6] _fetch called with:", {
1022
- query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
1023
- params: _params,
1024
- options: {
1025
- ...options,
1026
- decideParameters: options.decideParameters
1027
- },
1028
- stegaEnabled: _stega?.enabled
1029
- });
1030
951
  const stega = "stega" in options ? {
1031
952
  ..._stega || {},
1032
953
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
1033
- } : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) => {
1034
- console.log("[client-6] === HTTP RESPONSE TO DECIDE PROCESSING ==="), console.log("[client-6] processDecideResponse: received response for processing:", {
1035
- responseType: typeof response,
1036
- responseKeys: typeof response == "object" && response !== null ? Object.keys(response) : null,
1037
- responsePreview: typeof response == "object" && response !== null ? JSON.stringify(response, null, 2).substring(0, 300) + (JSON.stringify(response, null, 2).length > 300 ? "..." : "") : response,
1038
- audience: options.decideParameters?.audience,
1039
- decideParameters: options.decideParameters,
1040
- hasDecideParameters: !!options.decideParameters
1041
- }), console.log("[client-6] processDecideResponse: calling processDecideFields...");
1042
- const processedData = processDecideFields(response, options.decideParameters);
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;
1046
- }, { cache, next, ...opts } = {
954
+ } : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, processDecideResponse = (response) => processDecideFields(response, options.decideParameters), { cache, next, ...opts } = {
1047
955
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
1048
956
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
1049
957
  useAbortSignal: typeof options.signal < "u",
@@ -1054,7 +962,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1054
962
  // or `returnQuery` is explicitly set. `true` is the default in Content Lake, so skip if truthy
1055
963
  returnQuery: options.filterResponse === !1 && options.returnQuery !== !1
1056
964
  }, reqOpts = typeof cache < "u" || typeof next < "u" ? { ...opts, fetch: { cache, next } } : opts, $request = _dataRequest(client, httpRequest, "query", { query, params }, reqOpts);
1057
- return console.log("[client-6] _fetch: pipeline setup, stega.enabled:", stega.enabled), stega.enabled ? $request.pipe(
965
+ return stega.enabled ? $request.pipe(
1058
966
  operators.combineLatestWith(
1059
967
  rxjs.from(
1060
968
  Promise.resolve().then(function() {
@@ -1068,18 +976,14 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
1068
976
  ),
1069
977
  operators.map(
1070
978
  ([res, stegaEncodeSourceMap]) => {
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;
979
+ const processedResult = processDecideFields(res.result, options.decideParameters), result = stegaEncodeSourceMap(processedResult, res.resultSourceMap, stega);
980
+ return mapResponse({ ...res, result });
1076
981
  }
1077
982
  )
1078
983
  ) : $request.pipe(
1079
984
  operators.map((res) => {
1080
- console.log("[client-6] _fetch: non-stega path - processing response");
1081
985
  const mappedResponse = mapResponse(res);
1082
- return console.log("[client-6] _fetch: non-stega path - calling processDecideResponse"), processDecideResponse(mappedResponse);
986
+ return processDecideResponse(mappedResponse);
1083
987
  })
1084
988
  );
1085
989
  }
@@ -1222,18 +1126,6 @@ function _action(client, httpRequest, actions, options) {
1222
1126
  );
1223
1127
  }
1224
1128
  function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
1225
- console.log("[client-6] _dataRequest called with:", {
1226
- endpoint,
1227
- body: endpoint === "query" ? {
1228
- query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
1229
- params: body.params
1230
- } : body,
1231
- options: {
1232
- ...options,
1233
- decideParameters: options.decideParameters,
1234
- perspective: options.perspective
1235
- }
1236
- });
1237
1129
  const isMutation = endpoint === "mutate", isAction = endpoint === "actions", isQuery2 = endpoint === "query", strQuery = isMutation || isAction ? "" : encodeQueryString(body), useGet = !isMutation && !isAction && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId, cacheMode } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
1238
1130
  method: useGet ? "GET" : "POST",
1239
1131
  uri,
@@ -1256,15 +1148,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
1256
1148
  useAbortSignal: options.useAbortSignal,
1257
1149
  useCdn: options.useCdn
1258
1150
  };
1259
- return console.log("[client-6] _dataRequest calling _requestObservable with reqOptions:", {
1260
- ...reqOptions,
1261
- decideParameters: reqOptions.decideParameters,
1262
- perspective: reqOptions.perspective,
1263
- body: useGet ? void 0 : endpoint === "query" ? {
1264
- query: body.query?.substring(0, 100) + (body.query?.length > 100 ? "..." : ""),
1265
- params: body.params
1266
- } : body
1267
- }), _requestObservable(client, httpRequest, reqOptions).pipe(
1151
+ return _requestObservable(client, httpRequest, reqOptions).pipe(
1268
1152
  operators.filter(isResponse),
1269
1153
  operators.map(getBody),
1270
1154
  operators.map((res) => {
@@ -1288,16 +1172,7 @@ function _create(client, httpRequest, doc, op, options = {}) {
1288
1172
  }
1289
1173
  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);
1290
1174
  function _requestObservable(client, httpRequest, options) {
1291
- const uri = options.url || options.uri, config = client.config();
1292
- console.log("[client-6] _requestObservable called with options:", {
1293
- uri,
1294
- method: options.method,
1295
- decideParameters: options.decideParameters,
1296
- perspective: options.perspective,
1297
- query: options.query,
1298
- configDecideParameters: config.decideParameters
1299
- });
1300
- const canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
1175
+ const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
1301
1176
  let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
1302
1177
  const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
1303
1178
  if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isQuery(client, uri)) {
@@ -1308,36 +1183,11 @@ function _requestObservable(client, httpRequest, options) {
1308
1183
  perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
1309
1184
  ...options.query
1310
1185
  }, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
1311
- perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
1312
- const decideParametersOption = options.decideParameters || config.decideParameters;
1313
- console.log("[client-6] Processing decideParameters:", {
1314
- optionsDecideParameters: options.decideParameters,
1315
- configDecideParameters: config.decideParameters,
1316
- finalDecideParametersOption: decideParametersOption
1317
- }), decideParametersOption && typeof decideParametersOption == "object" ? (console.log(
1318
- "[client-6] DecideParameters received - keeping for response processing only:",
1319
- decideParametersOption
1320
- ), console.log(
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 });
1186
+ perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), 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 });
1323
1187
  }
1324
1188
  const finalOptions = Object.assign({}, options, {
1325
1189
  url: _getUrl(client, uri, useCdn)
1326
- });
1327
- console.log("[client-6] Final options before requestOptions call:", {
1328
- url: finalOptions.url,
1329
- decideParameters: finalOptions.decideParameters,
1330
- query: finalOptions.query,
1331
- method: finalOptions.method
1332
- });
1333
- const reqOptions = requestOptions(config, finalOptions);
1334
- console.log("[client-6] Final reqOptions from requestOptions:", {
1335
- method: reqOptions.method,
1336
- headers: reqOptions.headers,
1337
- query: reqOptions.query
1338
- // Note: URL is handled separately in the HTTP request
1339
- });
1340
- const request = new rxjs.Observable(
1190
+ }), reqOptions = requestOptions(config, finalOptions), request = new rxjs.Observable(
1341
1191
  (subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
1342
1192
  );
1343
1193
  return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
@@ -2557,7 +2407,7 @@ class ObservableSanityClient {
2557
2407
  });
2558
2408
  }
2559
2409
  fetch(query, params, options) {
2560
- return console.log("[client-6] ObservableSanityClient.fetch called with:", {
2410
+ return console.log("[client-8] ObservableSanityClient.fetch called with:", {
2561
2411
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2562
2412
  params,
2563
2413
  options: {
@@ -2831,7 +2681,7 @@ class SanityClient {
2831
2681
  });
2832
2682
  }
2833
2683
  fetch(query, params, options) {
2834
- return console.log("[client-6] SanityClient.fetch called with:", {
2684
+ return console.log("[client-8] SanityClient.fetch called with:", {
2835
2685
  query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2836
2686
  params,
2837
2687
  options: {