@sanity/client 7.11.2 → 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.
@@ -780,6 +780,10 @@ export declare interface ClientConfig {
780
780
  * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
781
781
  */
782
782
  stega?: StegaConfig | boolean
783
+ /**
784
+ * Lineage token for recursion control
785
+ */
786
+ lineage?: string
783
787
  }
784
788
 
785
789
  declare type ClientConfigResource =
@@ -780,6 +780,10 @@ export declare interface ClientConfig {
780
780
  * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
781
781
  */
782
782
  stega?: StegaConfig | boolean
783
+ /**
784
+ * Lineage token for recursion control
785
+ */
786
+ lineage?: string
783
787
  }
784
788
 
785
789
  declare type ClientConfigResource =
package/dist/stega.d.cts CHANGED
@@ -780,6 +780,10 @@ export declare interface ClientConfig {
780
780
  * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
781
781
  */
782
782
  stega?: StegaConfig | boolean
783
+ /**
784
+ * Lineage token for recursion control
785
+ */
786
+ lineage?: string
783
787
  }
784
788
 
785
789
  declare type ClientConfigResource =
package/dist/stega.d.ts CHANGED
@@ -780,6 +780,10 @@ export declare interface ClientConfig {
780
780
  * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
781
781
  */
782
782
  stega?: StegaConfig | boolean
783
+ /**
784
+ * Lineage token for recursion control
785
+ */
786
+ lineage?: string
783
787
  }
784
788
 
785
789
  declare type ClientConfigResource =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "7.11.2",
3
+ "version": "7.12.0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -56,6 +56,7 @@ export default function defineCreateClientExports<
56
56
  maxRedirects: 0,
57
57
  maxRetries: config.maxRetries,
58
58
  retryDelay: config.retryDelay,
59
+ lineage: config.lineage,
59
60
  ...options,
60
61
  } as Any),
61
62
  config,
@@ -1,11 +1,28 @@
1
+ import type {Middleware, RequestOptions} from 'get-it'
1
2
  import {agent, debug, headers} from 'get-it/middleware'
2
3
 
3
4
  import {name, version} from '../../package.json'
4
5
 
5
- const middleware = [
6
+ const middleware: Middleware[] = [
6
7
  debug({verbose: true, namespace: 'sanity:client'}),
7
8
  headers({'User-Agent': `${name} ${version}`}),
8
9
 
10
+ // Lineage is used for recursion control/tracing and can be passed either through
11
+ // client constructor or through environent variable.
12
+ // Not used in browser environments.
13
+ {
14
+ processOptions(opts: RequestOptions & {lineage?: string}) {
15
+ const lineage =
16
+ (typeof process !== 'undefined' && process.env.X_SANITY_LINEAGE) || opts.lineage
17
+
18
+ if (lineage) {
19
+ opts.headers = opts.headers || {}
20
+ opts.headers['x-sanity-lineage'] = lineage
21
+ }
22
+ return opts
23
+ },
24
+ },
25
+
9
26
  // Enable keep-alive, and in addition limit the number of sockets that can be opened.
10
27
  // This avoids opening too many connections to the server if someone tries to execute
11
28
  // a bunch of requests in parallel. It's recommended to have a concurrency limit
@@ -58,10 +58,14 @@ function printWarnings(config: {ignoreWarnings?: string | RegExp | Array<string
58
58
  }
59
59
  }
60
60
 
61
+ type HttpRequestConfig = {
62
+ ignoreWarnings?: string | RegExp | Array<string | RegExp>
63
+ }
64
+
61
65
  /** @internal */
62
66
  export function defineHttpRequest(
63
67
  envMiddleware: Middlewares,
64
- config: {ignoreWarnings?: string | RegExp | Array<string | RegExp>} = {},
68
+ config: HttpRequestConfig = {},
65
69
  ): Requester {
66
70
  return getIt([
67
71
  retry({shouldRetry}),
package/src/types.ts CHANGED
@@ -179,6 +179,10 @@ export interface ClientConfig {
179
179
  * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
180
180
  */
181
181
  stega?: StegaConfig | boolean
182
+ /**
183
+ * Lineage token for recursion control
184
+ */
185
+ lineage?: string
182
186
  }
183
187
 
184
188
  /** @public */
@@ -4801,6 +4801,7 @@ ${selectionOpts}`);
4801
4801
  maxRedirects: 0,
4802
4802
  maxRetries: config.maxRetries,
4803
4803
  retryDelay: config.retryDelay,
4804
+ lineage: config.lineage,
4804
4805
  ...options
4805
4806
  }),
4806
4807
  config