@sanity/client 7.2.2 → 7.3.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.
@@ -621,6 +621,12 @@ export declare interface ClientConfig {
621
621
  * Optional request tag prefix for all request tags
622
622
  */
623
623
  requestTagPrefix?: string
624
+ /**
625
+ * Optional default headers to include with all requests
626
+ *
627
+ * @remarks request-specific headers will override any default headers with the same name.
628
+ */
629
+ headers?: Record<string, string>
624
630
  ignoreBrowserTokenWarning?: boolean
625
631
  withCredentials?: boolean
626
632
  allowReconfigure?: boolean
@@ -1753,6 +1759,12 @@ export declare interface InitializedClientConfig extends ClientConfig {
1753
1759
  * The fully initialized stega config, can be used to check if stega is enabled
1754
1760
  */
1755
1761
  stega: InitializedStegaConfig
1762
+ /**
1763
+ * Default headers to include with all requests
1764
+ *
1765
+ * @remarks request-specific headers will override any default headers with the same name.
1766
+ */
1767
+ headers?: Record<string, string>
1756
1768
  }
1757
1769
 
1758
1770
  /**
@@ -621,6 +621,12 @@ export declare interface ClientConfig {
621
621
  * Optional request tag prefix for all request tags
622
622
  */
623
623
  requestTagPrefix?: string
624
+ /**
625
+ * Optional default headers to include with all requests
626
+ *
627
+ * @remarks request-specific headers will override any default headers with the same name.
628
+ */
629
+ headers?: Record<string, string>
624
630
  ignoreBrowserTokenWarning?: boolean
625
631
  withCredentials?: boolean
626
632
  allowReconfigure?: boolean
@@ -1753,6 +1759,12 @@ export declare interface InitializedClientConfig extends ClientConfig {
1753
1759
  * The fully initialized stega config, can be used to check if stega is enabled
1754
1760
  */
1755
1761
  stega: InitializedStegaConfig
1762
+ /**
1763
+ * Default headers to include with all requests
1764
+ *
1765
+ * @remarks request-specific headers will override any default headers with the same name.
1766
+ */
1767
+ headers?: Record<string, string>
1756
1768
  }
1757
1769
 
1758
1770
  /**
package/dist/stega.d.cts CHANGED
@@ -621,6 +621,12 @@ export declare interface ClientConfig {
621
621
  * Optional request tag prefix for all request tags
622
622
  */
623
623
  requestTagPrefix?: string
624
+ /**
625
+ * Optional default headers to include with all requests
626
+ *
627
+ * @remarks request-specific headers will override any default headers with the same name.
628
+ */
629
+ headers?: Record<string, string>
624
630
  ignoreBrowserTokenWarning?: boolean
625
631
  withCredentials?: boolean
626
632
  allowReconfigure?: boolean
@@ -1753,6 +1759,12 @@ export declare interface InitializedClientConfig extends ClientConfig {
1753
1759
  * The fully initialized stega config, can be used to check if stega is enabled
1754
1760
  */
1755
1761
  stega: InitializedStegaConfig
1762
+ /**
1763
+ * Default headers to include with all requests
1764
+ *
1765
+ * @remarks request-specific headers will override any default headers with the same name.
1766
+ */
1767
+ headers?: Record<string, string>
1756
1768
  }
1757
1769
 
1758
1770
  /**
package/dist/stega.d.ts CHANGED
@@ -621,6 +621,12 @@ export declare interface ClientConfig {
621
621
  * Optional request tag prefix for all request tags
622
622
  */
623
623
  requestTagPrefix?: string
624
+ /**
625
+ * Optional default headers to include with all requests
626
+ *
627
+ * @remarks request-specific headers will override any default headers with the same name.
628
+ */
629
+ headers?: Record<string, string>
624
630
  ignoreBrowserTokenWarning?: boolean
625
631
  withCredentials?: boolean
626
632
  allowReconfigure?: boolean
@@ -1753,6 +1759,12 @@ export declare interface InitializedClientConfig extends ClientConfig {
1753
1759
  * The fully initialized stega config, can be used to check if stega is enabled
1754
1760
  */
1755
1761
  stega: InitializedStegaConfig
1762
+ /**
1763
+ * Default headers to include with all requests
1764
+ *
1765
+ * @remarks request-specific headers will override any default headers with the same name.
1766
+ */
1767
+ headers?: Record<string, string>
1756
1768
  }
1757
1769
 
1758
1770
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "7.2.2",
3
+ "version": "7.3.0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -7,6 +7,10 @@ const projectHeader = 'X-Sanity-Project-ID'
7
7
  export function requestOptions(config: Any, overrides: Any = {}): Omit<RequestOptions, 'url'> {
8
8
  const headers: Any = {}
9
9
 
10
+ if (config.headers) {
11
+ Object.assign(headers, config.headers)
12
+ }
13
+
10
14
  const token = overrides.token || config.token
11
15
  if (token) {
12
16
  headers.Authorization = `Bearer ${token}`
package/src/types.ts CHANGED
@@ -102,6 +102,14 @@ export interface ClientConfig {
102
102
  * Optional request tag prefix for all request tags
103
103
  */
104
104
  requestTagPrefix?: string
105
+
106
+ /**
107
+ * Optional default headers to include with all requests
108
+ *
109
+ * @remarks request-specific headers will override any default headers with the same name.
110
+ */
111
+ headers?: Record<string, string>
112
+
105
113
  ignoreBrowserTokenWarning?: boolean
106
114
  withCredentials?: boolean
107
115
  allowReconfigure?: boolean
@@ -173,6 +181,12 @@ export interface InitializedClientConfig extends ClientConfig {
173
181
  * The fully initialized stega config, can be used to check if stega is enabled
174
182
  */
175
183
  stega: InitializedStegaConfig
184
+ /**
185
+ * Default headers to include with all requests
186
+ *
187
+ * @remarks request-specific headers will override any default headers with the same name.
188
+ */
189
+ headers?: Record<string, string>
176
190
  }
177
191
 
178
192
  /** @public */
@@ -2695,7 +2695,9 @@ ${selectionOpts}`);
2695
2695
  }
2696
2696
  const projectHeader = "X-Sanity-Project-ID";
2697
2697
  function requestOptions(config, overrides = {}) {
2698
- const headers = {}, token = overrides.token || config.token;
2698
+ const headers = {};
2699
+ config.headers && Object.assign(headers, config.headers);
2700
+ const token = overrides.token || config.token;
2699
2701
  token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
2700
2702
  const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
2701
2703
  return Object.assign({}, overrides, {