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

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.
@@ -853,80 +853,6 @@ function requestOptions(config, overrides = {}) {
853
853
  fetch: typeof overrides.fetch == "object" && typeof config.fetch == "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
854
854
  });
855
855
  }
856
- function isDecideField(value) {
857
- return value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
858
- }
859
- function resolveDecideField(field, decideParameters) {
860
- console.log("[client-8] resolveDecideField: starting resolution:", {
861
- field: {
862
- default: field.default,
863
- conditionsCount: field.conditions.length,
864
- conditions: field.conditions.map((c, i) => ({
865
- index: i,
866
- audience: c.audience,
867
- value: c.value
868
- }))
869
- },
870
- decideParameters
871
- });
872
- const audience = decideParameters?.audience;
873
- if (console.log("[client-8] resolveDecideField: audience processing:", {
874
- audience,
875
- audienceType: typeof audience,
876
- isArray: Array.isArray(audience),
877
- isEmpty: Array.isArray(audience) ? audience.length === 0 : audience === "",
878
- isUndefined: audience === void 0,
879
- isNull: audience === null
880
- }), !audience || Array.isArray(audience) && audience.length === 0 || audience === "")
881
- return console.log(
882
- "[client-8] resolveDecideField: no valid audience, returning default:",
883
- field.default
884
- ), field.default;
885
- console.log("[client-8] resolveDecideField: searching for matching condition...");
886
- const matchingCondition = field.conditions.find((condition, index) => {
887
- const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
888
- return console.log(`[client-8] resolveDecideField: checking condition ${index}:`, {
889
- conditionAudience: condition.audience,
890
- conditionValue: condition.value,
891
- searchAudience: audience,
892
- isArraySearch: Array.isArray(audience),
893
- isMatch
894
- }), isMatch;
895
- }), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
896
- return console.log("[client-8] resolveDecideField: resolution complete:", {
897
- matchingCondition: matchingCondition ? {
898
- audience: matchingCondition.audience,
899
- value: matchingCondition.value
900
- } : null,
901
- resolvedValue,
902
- usedDefault: !matchingCondition
903
- }), resolvedValue;
904
- }
905
- function processObjectRecursively(obj, decideParameters, depth = 0, path = "root") {
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
- try {
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;
914
- }
915
- return processed;
916
- }, {});
917
- }
918
- function processDecideFields(data, decideParameters) {
919
- console.log("[client-8] === DECIDE FIELD PROCESSING START ===");
920
- try {
921
- const result = processObjectRecursively(data, decideParameters);
922
- return console.log("[client-8] === DECIDE FIELD PROCESSING END ==="), result;
923
- } catch (error) {
924
- return console.warn(
925
- "[client-8] processDecideFields: processing failed, returning original data:",
926
- error
927
- ), data;
928
- }
929
- }
930
856
  const encodeQueryString = ({
931
857
  query,
932
858
  params = {},
@@ -951,7 +877,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
951
877
  const stega = "stega" in options ? {
952
878
  ..._stega || {},
953
879
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
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 } = {
880
+ } : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
955
881
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
956
882
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
957
883
  useAbortSignal: typeof options.signal < "u",
@@ -976,16 +902,11 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
976
902
  ),
977
903
  operators.map(
978
904
  ([res, stegaEncodeSourceMap]) => {
979
- const processedResult = processDecideFields(res.result, options.decideParameters), result = stegaEncodeSourceMap(processedResult, res.resultSourceMap, stega);
905
+ const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
980
906
  return mapResponse({ ...res, result });
981
907
  }
982
908
  )
983
- ) : $request.pipe(
984
- operators.map((res) => {
985
- const mappedResponse = mapResponse(res);
986
- return processDecideResponse(mappedResponse);
987
- })
988
- );
909
+ ) : $request.pipe(operators.map(mapResponse));
989
910
  }
990
911
  function _getDocument(client, httpRequest, id, opts = {}) {
991
912
  const docId = (() => {
@@ -1138,7 +1059,6 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
1138
1059
  tag,
1139
1060
  returnQuery,
1140
1061
  perspective: options.perspective,
1141
- decideParameters: options.decideParameters,
1142
1062
  resultSourceMap: options.resultSourceMap,
1143
1063
  lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
1144
1064
  cacheMode,
@@ -1185,9 +1105,12 @@ function _requestObservable(client, httpRequest, options) {
1185
1105
  }, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
1186
1106
  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 });
1187
1107
  }
1188
- const finalOptions = Object.assign({}, options, {
1189
- url: _getUrl(client, uri, useCdn)
1190
- }), reqOptions = requestOptions(config, finalOptions), request = new rxjs.Observable(
1108
+ const reqOptions = requestOptions(
1109
+ config,
1110
+ Object.assign({}, options, {
1111
+ url: _getUrl(client, uri, useCdn)
1112
+ })
1113
+ ), request = new rxjs.Observable(
1191
1114
  (subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
1192
1115
  );
1193
1116
  return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
@@ -2407,17 +2330,7 @@ class ObservableSanityClient {
2407
2330
  });
2408
2331
  }
2409
2332
  fetch(query, params, options) {
2410
- return console.log("[client-8] ObservableSanityClient.fetch called with:", {
2411
- query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2412
- params,
2413
- options: {
2414
- ...options,
2415
- decideParameters: options?.decideParameters
2416
- },
2417
- clientConfig: {
2418
- decideParameters: this.#clientConfig.decideParameters
2419
- }
2420
- }), _fetch(
2333
+ return _fetch(
2421
2334
  this,
2422
2335
  this.#httpRequest,
2423
2336
  this.#clientConfig.stega,
@@ -2681,17 +2594,7 @@ class SanityClient {
2681
2594
  });
2682
2595
  }
2683
2596
  fetch(query, params, options) {
2684
- return console.log("[client-8] SanityClient.fetch called with:", {
2685
- query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2686
- params,
2687
- options: {
2688
- ...options,
2689
- decideParameters: options?.decideParameters
2690
- },
2691
- clientConfig: {
2692
- decideParameters: this.#clientConfig.decideParameters
2693
- }
2694
- }), rxjs.lastValueFrom(
2597
+ return rxjs.lastValueFrom(
2695
2598
  _fetch(
2696
2599
  this,
2697
2600
  this.#httpRequest,
@@ -2940,6 +2843,7 @@ function defineCreateClientExports(envMiddleware2, ClassConstructor) {
2940
2843
  maxRedirects: 0,
2941
2844
  maxRetries: config.maxRetries,
2942
2845
  retryDelay: config.retryDelay,
2846
+ lineage: config.lineage,
2943
2847
  ...options
2944
2848
  }),
2945
2849
  config