@sanity/client 7.20.0 → 7.22.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.
@@ -804,6 +804,32 @@ export declare interface ClientConfig {
804
804
  * Lineage token for recursion control
805
805
  */
806
806
  lineage?: string
807
+ /**
808
+ * A custom request handler that intercepts all HTTP requests made by the client.
809
+ *
810
+ * Useful for logging, adding custom headers, refreshing auth tokens, rate limiting, etc.
811
+ *
812
+ * When using `withConfig()`, the new handler **replaces** the previous one (it does not
813
+ * wrap it). To compose handlers, you can chain them manually:
814
+ *
815
+ * ```ts
816
+ * const parent = createClient({...config, _requestHandler: handlerA})
817
+ * const child = parent.withConfig({
818
+ * _requestHandler: (req, defaultRequester) =>
819
+ * handlerB(req, (opts) => handlerA(opts, defaultRequester)),
820
+ * })
821
+ * ```
822
+ *
823
+ * Setting `_requestHandler` to `undefined` via `withConfig()` removes the handler.
824
+ *
825
+ * Note: This only applies to HTTP requests. Real-time listener connections
826
+ * (`client.listen()`) use EventSource and are not intercepted by this handler.
827
+ *
828
+ * @internal
829
+ * @deprecated Don't use outside of Sanity internals
830
+ * @see {@link RequestHandler}
831
+ */
832
+ _requestHandler?: RequestHandler
807
833
  }
808
834
 
809
835
  declare type ClientConfigResource =
@@ -829,6 +855,7 @@ export declare class ClientError extends Error {
829
855
  response: ErrorProps['response']
830
856
  statusCode: ErrorProps['statusCode']
831
857
  responseBody: ErrorProps['responseBody']
858
+ traceId: ErrorProps['traceId']
832
859
  details: ErrorProps['details']
833
860
  constructor(res: Any, context?: HttpContext)
834
861
  }
@@ -1489,6 +1516,7 @@ export declare interface ErrorProps {
1489
1516
  response: Any
1490
1517
  statusCode: number
1491
1518
  responseBody: Any
1519
+ traceId?: string
1492
1520
  details: Any
1493
1521
  }
1494
1522
 
@@ -1688,7 +1716,11 @@ export declare type FitMode = 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'p
1688
1716
  * @returns A formatted error message string.
1689
1717
  * @public
1690
1718
  */
1691
- export declare function formatQueryParseError(error: QueryParseError, tag?: string | null): string
1719
+ export declare function formatQueryParseError(
1720
+ error: QueryParseError,
1721
+ tag?: string | null,
1722
+ traceId?: string,
1723
+ ): string
1692
1724
 
1693
1725
  /** @beta */
1694
1726
  declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
@@ -2318,6 +2350,7 @@ export declare class LiveClient {
2318
2350
  events({
2319
2351
  includeDrafts,
2320
2352
  tag: _tag,
2353
+ waitFor,
2321
2354
  }?: {
2322
2355
  includeDrafts?: boolean
2323
2356
  /**
@@ -2326,6 +2359,11 @@ export declare class LiveClient {
2326
2359
  * @defaultValue `undefined`
2327
2360
  */
2328
2361
  tag?: string
2362
+ /**
2363
+ * Delays events until after a Sanity Function has processed them and called the callback endpoint.
2364
+ * When omitted, events are delivered immediately.
2365
+ */
2366
+ waitFor?: 'function'
2329
2367
  }): Observable<LiveEvent>
2330
2368
  }
2331
2369
 
@@ -4951,6 +4989,44 @@ export declare interface ReplaceVersionAction {
4951
4989
  */
4952
4990
  export declare const requester: Requester
4953
4991
 
4992
+ /**
4993
+ * A function that intercepts HTTP requests made by the client.
4994
+ *
4995
+ * Receives the resolved request options, a `defaultRequester` function that
4996
+ * executes the request through the normal pipeline, and a `client` instance
4997
+ * without a `_requestHandler` (to avoid recursive interception).
4998
+ *
4999
+ * The consumer can:
5000
+ * - Modify request options before calling `defaultRequester`
5001
+ * - Transform the response stream (e.g. via `pipe`)
5002
+ * - Skip `defaultRequester` entirely and return a custom Observable
5003
+ * - Use `client` to make additional requests (e.g. refresh an auth token on 401)
5004
+ *
5005
+ * When set via `withConfig()`, the new handler **replaces** (not wraps) the previous one.
5006
+ *
5007
+ * Note: This only applies to HTTP requests. Real-time listener connections
5008
+ * (`client.listen()`) use EventSource and are not intercepted by this handler.
5009
+ *
5010
+ * @param request - The resolved request options including `url`
5011
+ * @param defaultRequester - Executes the request through the normal pipeline
5012
+ * @param client - A client instance with the same configuration but without a `_requestHandler`,
5013
+ * useful for making side requests (e.g. token refresh) without triggering the handler recursively
5014
+ *
5015
+ * @internal
5016
+ * @deprecated Don't use outside of Sanity internals
5017
+ */
5018
+ export declare type RequestHandler = (
5019
+ request: RequestOptions & {
5020
+ url: string
5021
+ },
5022
+ defaultRequester: (
5023
+ options: RequestOptions & {
5024
+ url: string
5025
+ },
5026
+ ) => Observable<HttpRequestEvent>,
5027
+ client: SanityClient,
5028
+ ) => Observable<HttpRequestEvent>
5029
+
4954
5030
  /** @internal */
4955
5031
  export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
4956
5032
  url?: string
@@ -5991,6 +6067,7 @@ export declare class ServerError extends Error {
5991
6067
  response: ErrorProps['response']
5992
6068
  statusCode: ErrorProps['statusCode']
5993
6069
  responseBody: ErrorProps['responseBody']
6070
+ traceId: ErrorProps['traceId']
5994
6071
  details: ErrorProps['details']
5995
6072
  constructor(res: Any)
5996
6073
  }
@@ -804,6 +804,32 @@ export declare interface ClientConfig {
804
804
  * Lineage token for recursion control
805
805
  */
806
806
  lineage?: string
807
+ /**
808
+ * A custom request handler that intercepts all HTTP requests made by the client.
809
+ *
810
+ * Useful for logging, adding custom headers, refreshing auth tokens, rate limiting, etc.
811
+ *
812
+ * When using `withConfig()`, the new handler **replaces** the previous one (it does not
813
+ * wrap it). To compose handlers, you can chain them manually:
814
+ *
815
+ * ```ts
816
+ * const parent = createClient({...config, _requestHandler: handlerA})
817
+ * const child = parent.withConfig({
818
+ * _requestHandler: (req, defaultRequester) =>
819
+ * handlerB(req, (opts) => handlerA(opts, defaultRequester)),
820
+ * })
821
+ * ```
822
+ *
823
+ * Setting `_requestHandler` to `undefined` via `withConfig()` removes the handler.
824
+ *
825
+ * Note: This only applies to HTTP requests. Real-time listener connections
826
+ * (`client.listen()`) use EventSource and are not intercepted by this handler.
827
+ *
828
+ * @internal
829
+ * @deprecated Don't use outside of Sanity internals
830
+ * @see {@link RequestHandler}
831
+ */
832
+ _requestHandler?: RequestHandler
807
833
  }
808
834
 
809
835
  declare type ClientConfigResource =
@@ -829,6 +855,7 @@ export declare class ClientError extends Error {
829
855
  response: ErrorProps['response']
830
856
  statusCode: ErrorProps['statusCode']
831
857
  responseBody: ErrorProps['responseBody']
858
+ traceId: ErrorProps['traceId']
832
859
  details: ErrorProps['details']
833
860
  constructor(res: Any, context?: HttpContext)
834
861
  }
@@ -1489,6 +1516,7 @@ export declare interface ErrorProps {
1489
1516
  response: Any
1490
1517
  statusCode: number
1491
1518
  responseBody: Any
1519
+ traceId?: string
1492
1520
  details: Any
1493
1521
  }
1494
1522
 
@@ -1688,7 +1716,11 @@ export declare type FitMode = 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'p
1688
1716
  * @returns A formatted error message string.
1689
1717
  * @public
1690
1718
  */
1691
- export declare function formatQueryParseError(error: QueryParseError, tag?: string | null): string
1719
+ export declare function formatQueryParseError(
1720
+ error: QueryParseError,
1721
+ tag?: string | null,
1722
+ traceId?: string,
1723
+ ): string
1692
1724
 
1693
1725
  /** @beta */
1694
1726
  declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
@@ -2318,6 +2350,7 @@ export declare class LiveClient {
2318
2350
  events({
2319
2351
  includeDrafts,
2320
2352
  tag: _tag,
2353
+ waitFor,
2321
2354
  }?: {
2322
2355
  includeDrafts?: boolean
2323
2356
  /**
@@ -2326,6 +2359,11 @@ export declare class LiveClient {
2326
2359
  * @defaultValue `undefined`
2327
2360
  */
2328
2361
  tag?: string
2362
+ /**
2363
+ * Delays events until after a Sanity Function has processed them and called the callback endpoint.
2364
+ * When omitted, events are delivered immediately.
2365
+ */
2366
+ waitFor?: 'function'
2329
2367
  }): Observable<LiveEvent>
2330
2368
  }
2331
2369
 
@@ -4951,6 +4989,44 @@ export declare interface ReplaceVersionAction {
4951
4989
  */
4952
4990
  export declare const requester: Requester
4953
4991
 
4992
+ /**
4993
+ * A function that intercepts HTTP requests made by the client.
4994
+ *
4995
+ * Receives the resolved request options, a `defaultRequester` function that
4996
+ * executes the request through the normal pipeline, and a `client` instance
4997
+ * without a `_requestHandler` (to avoid recursive interception).
4998
+ *
4999
+ * The consumer can:
5000
+ * - Modify request options before calling `defaultRequester`
5001
+ * - Transform the response stream (e.g. via `pipe`)
5002
+ * - Skip `defaultRequester` entirely and return a custom Observable
5003
+ * - Use `client` to make additional requests (e.g. refresh an auth token on 401)
5004
+ *
5005
+ * When set via `withConfig()`, the new handler **replaces** (not wraps) the previous one.
5006
+ *
5007
+ * Note: This only applies to HTTP requests. Real-time listener connections
5008
+ * (`client.listen()`) use EventSource and are not intercepted by this handler.
5009
+ *
5010
+ * @param request - The resolved request options including `url`
5011
+ * @param defaultRequester - Executes the request through the normal pipeline
5012
+ * @param client - A client instance with the same configuration but without a `_requestHandler`,
5013
+ * useful for making side requests (e.g. token refresh) without triggering the handler recursively
5014
+ *
5015
+ * @internal
5016
+ * @deprecated Don't use outside of Sanity internals
5017
+ */
5018
+ export declare type RequestHandler = (
5019
+ request: RequestOptions & {
5020
+ url: string
5021
+ },
5022
+ defaultRequester: (
5023
+ options: RequestOptions & {
5024
+ url: string
5025
+ },
5026
+ ) => Observable<HttpRequestEvent>,
5027
+ client: SanityClient,
5028
+ ) => Observable<HttpRequestEvent>
5029
+
4954
5030
  /** @internal */
4955
5031
  export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
4956
5032
  url?: string
@@ -5991,6 +6067,7 @@ export declare class ServerError extends Error {
5991
6067
  response: ErrorProps['response']
5992
6068
  statusCode: ErrorProps['statusCode']
5993
6069
  responseBody: ErrorProps['responseBody']
6070
+ traceId: ErrorProps['traceId']
5994
6071
  details: ErrorProps['details']
5995
6072
  constructor(res: Any)
5996
6073
  }
package/dist/stega.d.cts CHANGED
@@ -804,6 +804,32 @@ export declare interface ClientConfig {
804
804
  * Lineage token for recursion control
805
805
  */
806
806
  lineage?: string
807
+ /**
808
+ * A custom request handler that intercepts all HTTP requests made by the client.
809
+ *
810
+ * Useful for logging, adding custom headers, refreshing auth tokens, rate limiting, etc.
811
+ *
812
+ * When using `withConfig()`, the new handler **replaces** the previous one (it does not
813
+ * wrap it). To compose handlers, you can chain them manually:
814
+ *
815
+ * ```ts
816
+ * const parent = createClient({...config, _requestHandler: handlerA})
817
+ * const child = parent.withConfig({
818
+ * _requestHandler: (req, defaultRequester) =>
819
+ * handlerB(req, (opts) => handlerA(opts, defaultRequester)),
820
+ * })
821
+ * ```
822
+ *
823
+ * Setting `_requestHandler` to `undefined` via `withConfig()` removes the handler.
824
+ *
825
+ * Note: This only applies to HTTP requests. Real-time listener connections
826
+ * (`client.listen()`) use EventSource and are not intercepted by this handler.
827
+ *
828
+ * @internal
829
+ * @deprecated Don't use outside of Sanity internals
830
+ * @see {@link RequestHandler}
831
+ */
832
+ _requestHandler?: RequestHandler
807
833
  }
808
834
 
809
835
  declare type ClientConfigResource =
@@ -829,6 +855,7 @@ export declare class ClientError extends Error {
829
855
  response: ErrorProps['response']
830
856
  statusCode: ErrorProps['statusCode']
831
857
  responseBody: ErrorProps['responseBody']
858
+ traceId: ErrorProps['traceId']
832
859
  details: ErrorProps['details']
833
860
  constructor(res: Any, context?: HttpContext)
834
861
  }
@@ -1489,6 +1516,7 @@ export declare interface ErrorProps {
1489
1516
  response: Any
1490
1517
  statusCode: number
1491
1518
  responseBody: Any
1519
+ traceId?: string
1492
1520
  details: Any
1493
1521
  }
1494
1522
 
@@ -1688,7 +1716,11 @@ export declare type FitMode = 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'p
1688
1716
  * @returns A formatted error message string.
1689
1717
  * @public
1690
1718
  */
1691
- export declare function formatQueryParseError(error: QueryParseError, tag?: string | null): string
1719
+ export declare function formatQueryParseError(
1720
+ error: QueryParseError,
1721
+ tag?: string | null,
1722
+ traceId?: string,
1723
+ ): string
1692
1724
 
1693
1725
  /** @beta */
1694
1726
  declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
@@ -2318,6 +2350,7 @@ export declare class LiveClient {
2318
2350
  events({
2319
2351
  includeDrafts,
2320
2352
  tag: _tag,
2353
+ waitFor,
2321
2354
  }?: {
2322
2355
  includeDrafts?: boolean
2323
2356
  /**
@@ -2326,6 +2359,11 @@ export declare class LiveClient {
2326
2359
  * @defaultValue `undefined`
2327
2360
  */
2328
2361
  tag?: string
2362
+ /**
2363
+ * Delays events until after a Sanity Function has processed them and called the callback endpoint.
2364
+ * When omitted, events are delivered immediately.
2365
+ */
2366
+ waitFor?: 'function'
2329
2367
  }): Observable<LiveEvent>
2330
2368
  }
2331
2369
 
@@ -4951,6 +4989,44 @@ export declare interface ReplaceVersionAction {
4951
4989
  */
4952
4990
  export declare const requester: Requester
4953
4991
 
4992
+ /**
4993
+ * A function that intercepts HTTP requests made by the client.
4994
+ *
4995
+ * Receives the resolved request options, a `defaultRequester` function that
4996
+ * executes the request through the normal pipeline, and a `client` instance
4997
+ * without a `_requestHandler` (to avoid recursive interception).
4998
+ *
4999
+ * The consumer can:
5000
+ * - Modify request options before calling `defaultRequester`
5001
+ * - Transform the response stream (e.g. via `pipe`)
5002
+ * - Skip `defaultRequester` entirely and return a custom Observable
5003
+ * - Use `client` to make additional requests (e.g. refresh an auth token on 401)
5004
+ *
5005
+ * When set via `withConfig()`, the new handler **replaces** (not wraps) the previous one.
5006
+ *
5007
+ * Note: This only applies to HTTP requests. Real-time listener connections
5008
+ * (`client.listen()`) use EventSource and are not intercepted by this handler.
5009
+ *
5010
+ * @param request - The resolved request options including `url`
5011
+ * @param defaultRequester - Executes the request through the normal pipeline
5012
+ * @param client - A client instance with the same configuration but without a `_requestHandler`,
5013
+ * useful for making side requests (e.g. token refresh) without triggering the handler recursively
5014
+ *
5015
+ * @internal
5016
+ * @deprecated Don't use outside of Sanity internals
5017
+ */
5018
+ export declare type RequestHandler = (
5019
+ request: RequestOptions & {
5020
+ url: string
5021
+ },
5022
+ defaultRequester: (
5023
+ options: RequestOptions & {
5024
+ url: string
5025
+ },
5026
+ ) => Observable<HttpRequestEvent>,
5027
+ client: SanityClient,
5028
+ ) => Observable<HttpRequestEvent>
5029
+
4954
5030
  /** @internal */
4955
5031
  export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
4956
5032
  url?: string
@@ -5991,6 +6067,7 @@ export declare class ServerError extends Error {
5991
6067
  response: ErrorProps['response']
5992
6068
  statusCode: ErrorProps['statusCode']
5993
6069
  responseBody: ErrorProps['responseBody']
6070
+ traceId: ErrorProps['traceId']
5994
6071
  details: ErrorProps['details']
5995
6072
  constructor(res: Any)
5996
6073
  }
package/dist/stega.d.ts CHANGED
@@ -804,6 +804,32 @@ export declare interface ClientConfig {
804
804
  * Lineage token for recursion control
805
805
  */
806
806
  lineage?: string
807
+ /**
808
+ * A custom request handler that intercepts all HTTP requests made by the client.
809
+ *
810
+ * Useful for logging, adding custom headers, refreshing auth tokens, rate limiting, etc.
811
+ *
812
+ * When using `withConfig()`, the new handler **replaces** the previous one (it does not
813
+ * wrap it). To compose handlers, you can chain them manually:
814
+ *
815
+ * ```ts
816
+ * const parent = createClient({...config, _requestHandler: handlerA})
817
+ * const child = parent.withConfig({
818
+ * _requestHandler: (req, defaultRequester) =>
819
+ * handlerB(req, (opts) => handlerA(opts, defaultRequester)),
820
+ * })
821
+ * ```
822
+ *
823
+ * Setting `_requestHandler` to `undefined` via `withConfig()` removes the handler.
824
+ *
825
+ * Note: This only applies to HTTP requests. Real-time listener connections
826
+ * (`client.listen()`) use EventSource and are not intercepted by this handler.
827
+ *
828
+ * @internal
829
+ * @deprecated Don't use outside of Sanity internals
830
+ * @see {@link RequestHandler}
831
+ */
832
+ _requestHandler?: RequestHandler
807
833
  }
808
834
 
809
835
  declare type ClientConfigResource =
@@ -829,6 +855,7 @@ export declare class ClientError extends Error {
829
855
  response: ErrorProps['response']
830
856
  statusCode: ErrorProps['statusCode']
831
857
  responseBody: ErrorProps['responseBody']
858
+ traceId: ErrorProps['traceId']
832
859
  details: ErrorProps['details']
833
860
  constructor(res: Any, context?: HttpContext)
834
861
  }
@@ -1489,6 +1516,7 @@ export declare interface ErrorProps {
1489
1516
  response: Any
1490
1517
  statusCode: number
1491
1518
  responseBody: Any
1519
+ traceId?: string
1492
1520
  details: Any
1493
1521
  }
1494
1522
 
@@ -1688,7 +1716,11 @@ export declare type FitMode = 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'p
1688
1716
  * @returns A formatted error message string.
1689
1717
  * @public
1690
1718
  */
1691
- export declare function formatQueryParseError(error: QueryParseError, tag?: string | null): string
1719
+ export declare function formatQueryParseError(
1720
+ error: QueryParseError,
1721
+ tag?: string | null,
1722
+ traceId?: string,
1723
+ ): string
1692
1724
 
1693
1725
  /** @beta */
1694
1726
  declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
@@ -2318,6 +2350,7 @@ export declare class LiveClient {
2318
2350
  events({
2319
2351
  includeDrafts,
2320
2352
  tag: _tag,
2353
+ waitFor,
2321
2354
  }?: {
2322
2355
  includeDrafts?: boolean
2323
2356
  /**
@@ -2326,6 +2359,11 @@ export declare class LiveClient {
2326
2359
  * @defaultValue `undefined`
2327
2360
  */
2328
2361
  tag?: string
2362
+ /**
2363
+ * Delays events until after a Sanity Function has processed them and called the callback endpoint.
2364
+ * When omitted, events are delivered immediately.
2365
+ */
2366
+ waitFor?: 'function'
2329
2367
  }): Observable<LiveEvent>
2330
2368
  }
2331
2369
 
@@ -4951,6 +4989,44 @@ export declare interface ReplaceVersionAction {
4951
4989
  */
4952
4990
  export declare const requester: Requester
4953
4991
 
4992
+ /**
4993
+ * A function that intercepts HTTP requests made by the client.
4994
+ *
4995
+ * Receives the resolved request options, a `defaultRequester` function that
4996
+ * executes the request through the normal pipeline, and a `client` instance
4997
+ * without a `_requestHandler` (to avoid recursive interception).
4998
+ *
4999
+ * The consumer can:
5000
+ * - Modify request options before calling `defaultRequester`
5001
+ * - Transform the response stream (e.g. via `pipe`)
5002
+ * - Skip `defaultRequester` entirely and return a custom Observable
5003
+ * - Use `client` to make additional requests (e.g. refresh an auth token on 401)
5004
+ *
5005
+ * When set via `withConfig()`, the new handler **replaces** (not wraps) the previous one.
5006
+ *
5007
+ * Note: This only applies to HTTP requests. Real-time listener connections
5008
+ * (`client.listen()`) use EventSource and are not intercepted by this handler.
5009
+ *
5010
+ * @param request - The resolved request options including `url`
5011
+ * @param defaultRequester - Executes the request through the normal pipeline
5012
+ * @param client - A client instance with the same configuration but without a `_requestHandler`,
5013
+ * useful for making side requests (e.g. token refresh) without triggering the handler recursively
5014
+ *
5015
+ * @internal
5016
+ * @deprecated Don't use outside of Sanity internals
5017
+ */
5018
+ export declare type RequestHandler = (
5019
+ request: RequestOptions & {
5020
+ url: string
5021
+ },
5022
+ defaultRequester: (
5023
+ options: RequestOptions & {
5024
+ url: string
5025
+ },
5026
+ ) => Observable<HttpRequestEvent>,
5027
+ client: SanityClient,
5028
+ ) => Observable<HttpRequestEvent>
5029
+
4954
5030
  /** @internal */
4955
5031
  export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
4956
5032
  url?: string
@@ -5991,6 +6067,7 @@ export declare class ServerError extends Error {
5991
6067
  response: ErrorProps['response']
5992
6068
  statusCode: ErrorProps['statusCode']
5993
6069
  responseBody: ErrorProps['responseBody']
6070
+ traceId: ErrorProps['traceId']
5994
6071
  details: ErrorProps['details']
5995
6072
  constructor(res: Any)
5996
6073
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "7.20.0",
3
+ "version": "7.22.0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -130,7 +130,7 @@
130
130
  },
131
131
  "dependencies": {
132
132
  "@sanity/eventsource": "^5.0.2",
133
- "get-it": "^8.7.0",
133
+ "get-it": "^8.7.2",
134
134
  "nanoid": "^3.3.11",
135
135
  "rxjs": "^7.0.0"
136
136
  },
@@ -43,6 +43,7 @@ import type {
43
43
  RawQuerylessQueryResponse,
44
44
  RawQueryResponse,
45
45
  RawRequestOptions,
46
+ RequestOptions,
46
47
  SanityDocument,
47
48
  SanityDocumentStub,
48
49
  SingleActionResult,
@@ -87,6 +88,7 @@ export class ObservableSanityClient {
87
88
  * Private properties
88
89
  */
89
90
  #clientConfig: InitializedClientConfig
91
+ #originalHttpRequest: HttpRequest
90
92
  #httpRequest: HttpRequest
91
93
 
92
94
  /**
@@ -97,7 +99,22 @@ export class ObservableSanityClient {
97
99
  constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
98
100
  this.config(config)
99
101
 
100
- this.#httpRequest = httpRequest
102
+ this.#originalHttpRequest = httpRequest
103
+ const requestHandler = config._requestHandler
104
+
105
+ this.#httpRequest = requestHandler
106
+ ? (() => {
107
+ let bareClient: SanityClient | undefined
108
+ const wrapped: HttpRequest = (options, requester) => {
109
+ const opts = options as RequestOptions & {url: string}
110
+ if (!bareClient) {
111
+ bareClient = new SanityClient(httpRequest, {...config, _requestHandler: undefined})
112
+ }
113
+ return requestHandler(opts, (o) => httpRequest(o, requester), bareClient)
114
+ }
115
+ return wrapped
116
+ })()
117
+ : httpRequest
101
118
 
102
119
  this.assets = new ObservableAssetsClient(this, this.#httpRequest)
103
120
  this.datasets = new ObservableDatasetsClient(this, this.#httpRequest)
@@ -117,7 +134,7 @@ export class ObservableSanityClient {
117
134
  * Clone the client - returns a new instance
118
135
  */
119
136
  clone(): ObservableSanityClient {
120
- return new ObservableSanityClient(this.#httpRequest, this.config())
137
+ return new ObservableSanityClient(this.#originalHttpRequest, this.config())
121
138
  }
122
139
 
123
140
  /**
@@ -150,7 +167,7 @@ export class ObservableSanityClient {
150
167
  */
151
168
  withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient {
152
169
  const thisConfig = this.config()
153
- return new ObservableSanityClient(this.#httpRequest, {
170
+ return new ObservableSanityClient(this.#originalHttpRequest, {
154
171
  ...thisConfig,
155
172
  ...newConfig,
156
173
  stega: {
@@ -1128,6 +1145,7 @@ export class SanityClient {
1128
1145
  * Private properties
1129
1146
  */
1130
1147
  #clientConfig: InitializedClientConfig
1148
+ #originalHttpRequest: HttpRequest
1131
1149
  #httpRequest: HttpRequest
1132
1150
 
1133
1151
  /**
@@ -1138,7 +1156,21 @@ export class SanityClient {
1138
1156
  constructor(httpRequest: HttpRequest, config: ClientConfig = defaultConfig) {
1139
1157
  this.config(config)
1140
1158
 
1141
- this.#httpRequest = httpRequest
1159
+ this.#originalHttpRequest = httpRequest
1160
+ const requestHandler = config._requestHandler
1161
+ this.#httpRequest = requestHandler
1162
+ ? (() => {
1163
+ let bareClient: SanityClient | undefined
1164
+ const wrapped: HttpRequest = (options, requester) => {
1165
+ const opts = options as RequestOptions & {url: string}
1166
+ if (!bareClient) {
1167
+ bareClient = new SanityClient(httpRequest, {...config, _requestHandler: undefined})
1168
+ }
1169
+ return requestHandler(opts, (o) => httpRequest(o, requester), bareClient)
1170
+ }
1171
+ return wrapped
1172
+ })()
1173
+ : httpRequest
1142
1174
 
1143
1175
  this.assets = new AssetsClient(this, this.#httpRequest)
1144
1176
  this.datasets = new DatasetsClient(this, this.#httpRequest)
@@ -1160,7 +1192,7 @@ export class SanityClient {
1160
1192
  * Clone the client - returns a new instance
1161
1193
  */
1162
1194
  clone(): SanityClient {
1163
- return new SanityClient(this.#httpRequest, this.config())
1195
+ return new SanityClient(this.#originalHttpRequest, this.config())
1164
1196
  }
1165
1197
 
1166
1198
  /**
@@ -1197,7 +1229,7 @@ export class SanityClient {
1197
1229
  */
1198
1230
  withConfig(newConfig?: Partial<ClientConfig>): SanityClient {
1199
1231
  const thisConfig = this.config()
1200
- return new SanityClient(this.#httpRequest, {
1232
+ return new SanityClient(this.#originalHttpRequest, {
1201
1233
  ...thisConfig,
1202
1234
  ...newConfig,
1203
1235
  stega: {
package/src/data/live.ts CHANGED
@@ -35,6 +35,7 @@ export class LiveClient {
35
35
  events({
36
36
  includeDrafts = false,
37
37
  tag: _tag,
38
+ waitFor,
38
39
  }: {
39
40
  includeDrafts?: boolean
40
41
  /**
@@ -43,6 +44,11 @@ export class LiveClient {
43
44
  * @defaultValue `undefined`
44
45
  */
45
46
  tag?: string
47
+ /**
48
+ * Delays events until after a Sanity Function has processed them and called the callback endpoint.
49
+ * When omitted, events are delivered immediately.
50
+ */
51
+ waitFor?: 'function'
46
52
  } = {}): Observable<LiveEvent> {
47
53
  const {
48
54
  projectId,
@@ -74,6 +80,9 @@ export class LiveClient {
74
80
  if (includeDrafts) {
75
81
  url.searchParams.set('includeDrafts', 'true')
76
82
  }
83
+ if (waitFor) {
84
+ url.searchParams.set('waitFor', waitFor)
85
+ }
77
86
  const esOptions: EventSourceInit & {headers?: Record<string, string>} = {}
78
87
  if (includeDrafts && withCredentials) {
79
88
  esOptions.withCredentials = true