@sanity/client 7.2.1 → 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.
package/README.md CHANGED
@@ -27,6 +27,10 @@ export const client = createClient({
27
27
  projectId: 'your-project-id',
28
28
  dataset: 'your-dataset-name',
29
29
  useCdn: true, // set to `false` to bypass the edge cache
30
+ // Set default headers to be included with all requests
31
+ headers: {
32
+ 'X-Custom-Header': 'custom-value'
33
+ },
30
34
  apiVersion: '2025-02-06', // use current date (YYYY-MM-DD) to target the latest API version. Note: this should always be hard coded. Setting API version based on a dynamic value (e.g. new Date()) may break your application at a random point in the future.
31
35
  // token: process.env.SANITY_SECRET_TOKEN // Needed for certain operations like updating content, accessing drafts or using draft perspectives
32
36
  })
@@ -738,7 +738,9 @@ class ObservableTransaction extends BaseTransaction {
738
738
  }
739
739
  const projectHeader = "X-Sanity-Project-ID";
740
740
  function requestOptions(config, overrides = {}) {
741
- const headers = {}, token = overrides.token || config.token;
741
+ const headers = {};
742
+ config.headers && Object.assign(headers, config.headers);
743
+ const token = overrides.token || config.token;
742
744
  token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
743
745
  const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
744
746
  return Object.assign({}, overrides, {