@sanity/client
Advanced tools
+2
-2
| { | ||
| "name": "@sanity/client", | ||
| "version": "7.20.0", | ||
| "version": "7.21.0", | ||
| "description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -133,3 +133,3 @@ "keywords": [ | ||
| "@sanity/eventsource": "^5.0.2", | ||
| "get-it": "^8.7.0", | ||
| "get-it": "^8.7.2", | ||
| "nanoid": "^3.3.11", | ||
@@ -136,0 +136,0 @@ "rxjs": "^7.0.0" |
+9
-0
@@ -38,2 +38,3 @@ import {catchError, mergeMap, Observable, of} from 'rxjs' | ||
| tag: _tag, | ||
| waitFor, | ||
| }: { | ||
@@ -47,2 +48,7 @@ includeDrafts?: boolean | ||
| tag?: string | ||
| /** | ||
| * Delays events until after a Sanity Function has processed them and called the callback endpoint. | ||
| * When omitted, events are delivered immediately. | ||
| */ | ||
| waitFor?: 'function' | ||
| } = {}): Observable<LiveEvent> { | ||
@@ -79,2 +85,5 @@ const { | ||
| } | ||
| if (waitFor) { | ||
| url.searchParams.set('waitFor', waitFor) | ||
| } | ||
| const esOptions: EventSourceInit & {headers?: Record<string, string>} = {} | ||
@@ -81,0 +90,0 @@ if (includeDrafts && withCredentials) { |
+61
-0
@@ -5,3 +5,5 @@ // deno-lint-ignore-file no-empty-interface | ||
| import type {Requester} from 'get-it' | ||
| import type {Observable} from 'rxjs' | ||
| import type {SanityClient} from './SanityClient' | ||
| import type {InitializedStegaConfig, StegaConfig} from './stega/types' | ||
@@ -207,2 +209,29 @@ | ||
| lineage?: string | ||
| /** | ||
| * A custom request handler that intercepts all HTTP requests made by the client. | ||
| * | ||
| * Useful for logging, adding custom headers, refreshing auth tokens, rate limiting, etc. | ||
| * | ||
| * When using `withConfig()`, the new handler **replaces** the previous one (it does not | ||
| * wrap it). To compose handlers, you can chain them manually: | ||
| * | ||
| * ```ts | ||
| * const parent = createClient({...config, _requestHandler: handlerA}) | ||
| * const child = parent.withConfig({ | ||
| * _requestHandler: (req, defaultRequester) => | ||
| * handlerB(req, (opts) => handlerA(opts, defaultRequester)), | ||
| * }) | ||
| * ``` | ||
| * | ||
| * Setting `_requestHandler` to `undefined` via `withConfig()` removes the handler. | ||
| * | ||
| * Note: This only applies to HTTP requests. Real-time listener connections | ||
| * (`client.listen()`) use EventSource and are not intercepted by this handler. | ||
| * | ||
| * @internal | ||
| * @deprecated Don't use outside of Sanity internals | ||
| * @see {@link RequestHandler} | ||
| */ | ||
| _requestHandler?: RequestHandler | ||
| } | ||
@@ -417,2 +446,34 @@ | ||
| /** | ||
| * A function that intercepts HTTP requests made by the client. | ||
| * | ||
| * Receives the resolved request options, a `defaultRequester` function that | ||
| * executes the request through the normal pipeline, and a `client` instance | ||
| * without a `_requestHandler` (to avoid recursive interception). | ||
| * | ||
| * The consumer can: | ||
| * - Modify request options before calling `defaultRequester` | ||
| * - Transform the response stream (e.g. via `pipe`) | ||
| * - Skip `defaultRequester` entirely and return a custom Observable | ||
| * - Use `client` to make additional requests (e.g. refresh an auth token on 401) | ||
| * | ||
| * When set via `withConfig()`, the new handler **replaces** (not wraps) the previous one. | ||
| * | ||
| * Note: This only applies to HTTP requests. Real-time listener connections | ||
| * (`client.listen()`) use EventSource and are not intercepted by this handler. | ||
| * | ||
| * @param request - The resolved request options including `url` | ||
| * @param defaultRequester - Executes the request through the normal pipeline | ||
| * @param client - A client instance with the same configuration but without a `_requestHandler`, | ||
| * useful for making side requests (e.g. token refresh) without triggering the handler recursively | ||
| * | ||
| * @internal | ||
| * @deprecated Don't use outside of Sanity internals | ||
| */ | ||
| export type RequestHandler = ( | ||
| request: RequestOptions & {url: string}, | ||
| defaultRequester: (options: RequestOptions & {url: string}) => Observable<HttpRequestEvent>, | ||
| client: SanityClient, | ||
| ) => Observable<HttpRequestEvent> | ||
| /** @internal */ | ||
@@ -419,0 +480,0 @@ export interface RequestObservableOptions extends Omit<RequestOptions, 'url'> { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
5026317
1.03%59087
0.81%Updated