@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.
package/dist/index.cjs CHANGED
@@ -682,80 +682,6 @@ function requestOptions(config2, overrides = {}) {
682
682
  fetch: typeof overrides.fetch == "object" && typeof config2.fetch == "object" ? { ...config2.fetch, ...overrides.fetch } : overrides.fetch || config2.fetch
683
683
  });
684
684
  }
685
- function isDecideField(value) {
686
- return value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
687
- }
688
- function resolveDecideField(field, decideParameters) {
689
- console.log("[client-8] resolveDecideField: starting resolution:", {
690
- field: {
691
- default: field.default,
692
- conditionsCount: field.conditions.length,
693
- conditions: field.conditions.map((c, i) => ({
694
- index: i,
695
- audience: c.audience,
696
- value: c.value
697
- }))
698
- },
699
- decideParameters
700
- });
701
- const audience = decideParameters?.audience;
702
- if (console.log("[client-8] resolveDecideField: audience processing:", {
703
- audience,
704
- audienceType: typeof audience,
705
- isArray: Array.isArray(audience),
706
- isEmpty: Array.isArray(audience) ? audience.length === 0 : audience === "",
707
- isUndefined: audience === void 0,
708
- isNull: audience === null
709
- }), !audience || Array.isArray(audience) && audience.length === 0 || audience === "")
710
- return console.log(
711
- "[client-8] resolveDecideField: no valid audience, returning default:",
712
- field.default
713
- ), field.default;
714
- console.log("[client-8] resolveDecideField: searching for matching condition...");
715
- const matchingCondition = field.conditions.find((condition, index) => {
716
- const isMatch = Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience;
717
- return console.log(`[client-8] resolveDecideField: checking condition ${index}:`, {
718
- conditionAudience: condition.audience,
719
- conditionValue: condition.value,
720
- searchAudience: audience,
721
- isArraySearch: Array.isArray(audience),
722
- isMatch
723
- }), isMatch;
724
- }), resolvedValue = matchingCondition ? matchingCondition.value : field.default;
725
- return console.log("[client-8] resolveDecideField: resolution complete:", {
726
- matchingCondition: matchingCondition ? {
727
- audience: matchingCondition.audience,
728
- value: matchingCondition.value
729
- } : null,
730
- resolvedValue,
731
- usedDefault: !matchingCondition
732
- }), resolvedValue;
733
- }
734
- function processObjectRecursively(obj, decideParameters, depth = 0, path = "root") {
735
- return obj == null || typeof obj != "object" ? obj : Array.isArray(obj) ? obj.map(
736
- (item, index) => processObjectRecursively(item, decideParameters, depth + 1, `${path}[${index}]`)
737
- ) : Object.entries(obj).reduce((processed, [key, value]) => {
738
- const currentPath = `${path}.${key}`, isDecide = isDecideField(value);
739
- try {
740
- isDecide ? (console.log(`[client-8] DECIDE FIELD FOUND: Key: '${key}'`), processed[key] = resolveDecideField(value, decideParameters)) : processed[key] = processObjectRecursively(value, decideParameters, depth + 1, currentPath);
741
- } catch {
742
- processed[key] = value;
743
- }
744
- return processed;
745
- }, {});
746
- }
747
- function processDecideFields(data, decideParameters) {
748
- console.log("[client-8] === DECIDE FIELD PROCESSING START ===");
749
- try {
750
- const result = processObjectRecursively(data, decideParameters);
751
- return console.log("[client-8] === DECIDE FIELD PROCESSING END ==="), result;
752
- } catch (error) {
753
- return console.warn(
754
- "[client-8] processDecideFields: processing failed, returning original data:",
755
- error
756
- ), data;
757
- }
758
- }
759
685
  const encodeQueryString = ({
760
686
  query,
761
687
  params = {},
@@ -780,7 +706,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
780
706
  const stega = "stega" in options ? {
781
707
  ..._stega || {},
782
708
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
783
- } : _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 } = {
709
+ } : _stega, params = stega.enabled ? stegaClean.stegaClean(_params) : _params, mapResponse = options.filterResponse === !1 ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
784
710
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
785
711
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
786
712
  useAbortSignal: typeof options.signal < "u",
@@ -805,16 +731,11 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
805
731
  ),
806
732
  operators.map(
807
733
  ([res, stegaEncodeSourceMap]) => {
808
- const processedResult = processDecideFields(res.result, options.decideParameters), result = stegaEncodeSourceMap(processedResult, res.resultSourceMap, stega);
734
+ const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
809
735
  return mapResponse({ ...res, result });
810
736
  }
811
737
  )
812
- ) : $request.pipe(
813
- operators.map((res) => {
814
- const mappedResponse = mapResponse(res);
815
- return processDecideResponse(mappedResponse);
816
- })
817
- );
738
+ ) : $request.pipe(operators.map(mapResponse));
818
739
  }
819
740
  function _getDocument(client, httpRequest, id, opts = {}) {
820
741
  const docId = (() => {
@@ -967,7 +888,6 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
967
888
  tag,
968
889
  returnQuery,
969
890
  perspective: options.perspective,
970
- decideParameters: options.decideParameters,
971
891
  resultSourceMap: options.resultSourceMap,
972
892
  lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
973
893
  cacheMode,
@@ -1014,9 +934,12 @@ function _requestObservable(client, httpRequest, options) {
1014
934
  }, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
1015
935
  perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = !1, config.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 });
1016
936
  }
1017
- const finalOptions = Object.assign({}, options, {
1018
- url: _getUrl(client, uri, useCdn)
1019
- }), reqOptions = requestOptions(config$1, finalOptions), request = new rxjs.Observable(
937
+ const reqOptions = requestOptions(
938
+ config$1,
939
+ Object.assign({}, options, {
940
+ url: _getUrl(client, uri, useCdn)
941
+ })
942
+ ), request = new rxjs.Observable(
1020
943
  (subscriber) => httpRequest(reqOptions, config$1.requester).subscribe(subscriber)
1021
944
  );
1022
945
  return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
@@ -2236,17 +2159,7 @@ class ObservableSanityClient {
2236
2159
  });
2237
2160
  }
2238
2161
  fetch(query, params, options) {
2239
- return console.log("[client-8] ObservableSanityClient.fetch called with:", {
2240
- query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2241
- params,
2242
- options: {
2243
- ...options,
2244
- decideParameters: options?.decideParameters
2245
- },
2246
- clientConfig: {
2247
- decideParameters: this.#clientConfig.decideParameters
2248
- }
2249
- }), _fetch(
2162
+ return _fetch(
2250
2163
  this,
2251
2164
  this.#httpRequest,
2252
2165
  this.#clientConfig.stega,
@@ -2510,17 +2423,7 @@ class SanityClient {
2510
2423
  });
2511
2424
  }
2512
2425
  fetch(query, params, options) {
2513
- return console.log("[client-8] SanityClient.fetch called with:", {
2514
- query: query.substring(0, 100) + (query.length > 100 ? "..." : ""),
2515
- params,
2516
- options: {
2517
- ...options,
2518
- decideParameters: options?.decideParameters
2519
- },
2520
- clientConfig: {
2521
- decideParameters: this.#clientConfig.decideParameters
2522
- }
2523
- }), rxjs.lastValueFrom(
2426
+ return rxjs.lastValueFrom(
2524
2427
  _fetch(
2525
2428
  this,
2526
2429
  this.#httpRequest,
@@ -2769,6 +2672,7 @@ function defineCreateClientExports(envMiddleware, ClassConstructor) {
2769
2672
  maxRedirects: 0,
2770
2673
  maxRetries: config2.maxRetries,
2771
2674
  retryDelay: config2.retryDelay,
2675
+ lineage: config2.lineage,
2772
2676
  ...options
2773
2677
  }),
2774
2678
  config2
@@ -2780,10 +2684,19 @@ function defineDeprecatedCreateClient(createClient2) {
2780
2684
  return config.printNoDefaultExport(), createClient2(config$1);
2781
2685
  };
2782
2686
  }
2783
- var name = "@sanity/client", version = "7.11.2-audience-decide.8";
2687
+ var name = "@sanity/client", version = "7.12.0";
2784
2688
  const middleware = [
2785
2689
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
2786
2690
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),
2691
+ // Lineage is used for recursion control/tracing and can be passed either through
2692
+ // client constructor or through environent variable.
2693
+ // Not used in browser environments.
2694
+ {
2695
+ processOptions(opts) {
2696
+ const lineage = typeof process < "u" && process.env.X_SANITY_LINEAGE || opts.lineage;
2697
+ return lineage && (opts.headers = opts.headers || {}, opts.headers["x-sanity-lineage"] = lineage), opts;
2698
+ }
2699
+ },
2787
2700
  // Enable keep-alive, and in addition limit the number of sockets that can be opened.
2788
2701
  // This avoids opening too many connections to the server if someone tries to execute
2789
2702
  // a bunch of requests in parallel. It's recommended to have a concurrency limit