@sanity/client
Version:
Client for retrieving, creating and patching data from Sanity.io
185 lines • 19.9 kB
TypeScript
import { d as ResolveStudioUrl, f as StegaConfig, g as StudioUrl, h as StudioBaseUrl, i as ContentSourceMapParsedPathKeyedSegment, l as InitializedStegaConfig, m as StudioBaseRoute, p as StegaConfigRequiredKeys, r as ContentSourceMapParsedPath, s as FilterDefault, u as Logger } from "./types-CfGzbXrl.js";
import { $ as DisconnectEvent, $n as UploadClientConfig, $r as CollaborationCommentFieldValue, $t as QueryWithoutParams, A as ContentSourceMapMappings, Ai as AgentActionPathSegment, An as SanityReference, Ar as ObservableProjectsClient, At as MediaLibraryAssetVersion, B as CreateVersionAction, Bn as TransactionAllDocumentIdsMutationOptions, Br as ObservablePatchBuilder, Bt as MutationSelection, C as ContentSourceMap, Ci as PromptRequest, Cn as SanityDocument, Cr as GenerateTarget, Ct as LiveEventGoAway, D as ContentSourceMapDocuments, Di as AgentActionParam, Dn as SanityProject, Dr as SanityClient, Dt as LiveEventWelcome, E as ContentSourceMapDocumentValueSource, Ei as PatchTarget, En as SanityImagePalette, Er as ObservableSanityClient, Et as LiveEventRestart, F as ContentSourceMapValueMapping, Fi as GroqAgentActionParam, Fn as StackablePerspective, Fr as InvokeFunctionOptions, Ft as Mutation, G as DatasetResponse, Gn as UnarchiveReleaseAction, Gr as ObservablePatch, Gt as PatchOperations, H as DatasetAclMode, Hn as TransactionFirstDocumentIdMutationOptions, Hr as PatchBuilder, Ht as OpenEvent, I as CreateAction, In as StillImageFormat, Ir as InvokeFunctionRequest, It as MutationError, J as DeleteReleaseAction, Jn as UnpublishAction, Jr as types_d_exports, Jt as PublishReleaseAction, K as DatasetsResponse, Kn as UnfilteredResponseQueryOptions, Kr as Patch, Kt as PatchSelection, L as CreateReleaseAction, Ln as StoryboardTransformOptions, Lr as DatasetsClient, Lt as MutationErrorItem, M as ContentSourceMapRemoteDocument, Mi as ConstantAgentActionParam, Mn as ScheduleReleaseAction, Mr as MediaLibraryVideoClient, Mt as MediaLibraryVideoPlaybackTransformations, N as ContentSourceMapSource, Ni as DocumentAgentActionParam, Nn as SingleActionResult, Nr as ObservableMediaLibraryVideoClient, Nt as MultipleActionResult, O as ContentSourceMapLiteralSource, Oi as AgentActionParams, On as SanityProjectMember, Or as ObservableUsersClient, Ot as MediaLibraryAssetDocument, P as ContentSourceMapUnknownSource, Pi as FieldAgentActionParam, Pn as SingleMutationResult, Pr as InvokeFunctionEvent, Pt as MultipleMutationResult, Q as DiscardVersionAction, Qn as UploadBody, Qr as CollaborationCommentDocument, Qt as QueryParseError, R as CreateVariantAction, Rn as SyncTag, Rr as ObservableDatasetsClient, Rt as MutationEvent, S as ClientVariantConditions, Si as TransformTargetInclude, Sn as SanityAssetDocument, Sr as GenerateOperation, St as LiveEvent, T as ContentSourceMapDocumentBase, Ti as PatchOperation, Tn as SanityImageAssetDocument, Tr as GenerateTargetInclude, Tt as LiveEventReconnect, U as DatasetCreateOptions, Un as TransactionFirstDocumentMutationOptions, Ur as Transaction, Ut as PartialExcept, V as CurrentSanityUser, Vn as TransactionAllDocumentsMutationOptions, Vr as ObservableTransaction, Vt as MutationSelectionQueryParams, W as DatasetEditOptions, Wn as TransactionMutationOptions, Wr as BasePatch, Wt as PatchMutationOperation, X as DeleteVariantDefinitionAction, Xn as UnpublishVersionAction, Xr as ObservableCollaborationCommentsClient, Xt as QueryOptions, Y as DeleteVariantAction, Yn as UnpublishVariantAction, Yr as CollaborationCommentsClient, Yt as PublishVariantAction, Z as DiscardAction, Zn as UnscheduleReleaseAction, Zr as CollaborationCommentCreate, Zt as QueryParams, _ as ChannelErrorEvent, _i as ImageDescriptionOperation, _n as Requester, _r as VideoSubtitleInfoPublic, _t as InsertPatch, a as AllDocumentsMutationOptions, ai as CollaborationCommentStatus, an as ReleaseCardinality, ar as VersionAction, at as EditableReleaseDocument, b as ClientReturn, bi as TransformTarget, bn as ResumableListenEventNames, br as WelcomeEvent, bt as ListenOptions, c as Any, ci as CollaborationCommentsListenOptions, cn as ReleaseState, cr as VideoPlaybackInfoItemPublic, ct as ErrorProps, d as AssetMetadataType, di as _listen, dn as ReplaceVersionAction, dr as VideoPlaybackInfoSigned, dt as FirstDocumentMutationOptions, ei as CollaborationCommentMessage, en as RawQueryResponse, er as UploadEvent, et as EXPERIMENTAL_API_WARNING, f as AttributeSet, fi as AssetsClient, fn as RequestHandler, fr as VideoPlaybackTokens, ft as FitMode, g as BaseMutationOptions, gi as TranslateTargetInclude, gn as RequestUrlOptions, gr as VideoSubtitleInfo, gt as InitializedClientConfig, h as BaseActionOptions, hi as TranslateTarget, hn as RequestOptions, hr as VideoRenditionInfoSigned, ht as ImportReleaseAction, i as AllDocumentIdsMutationOptions, ii as CollaborationCommentSelection, in as ReleaseAction, ir as VariantDefinitionAction, it as EditVariantDefinitionAction, j as ContentSourceMapPaths, ji as AgentActionTarget, jn as SanityUser, jr as ProjectsClient, jt as MediaLibraryPlaybackInfoOptions, k as ContentSourceMapMapping, ki as AgentActionPath, kn as SanityQueries, kr as UsersClient, kt as MediaLibraryAssetInstanceIdentifier, l as ApiError, li as CollaborationCommentsRequestOptions, ln as ReleaseType, lr as VideoPlaybackInfoItemSigned, lt as FilteredResponseQueryOptions, m as AuthProviderResponse, mi as TranslateDocument, mn as RequestObservableOptions, mr as VideoRenditionInfoPublic, mt as IdentifiedSanityDocumentStub, n as ActionError, ni as CollaborationCommentRange, nn as RawRequestOptions, nr as UploadResponseEvent, nt as EditReleaseAction, o as AnimatedImageFormat, oi as CollaborationCommentTarget, on as ReleaseDocument, or as VideoPlaybackInfo, ot as EmbeddingsSettings, p as AuthProvider, pi as ObservableAssetsClient, pn as RequestHandlerOptions, pr as VideoRenditionInfo, pt as HttpRequest, q as DeleteAction, qn as UnfilteredResponseWithoutQuery, qr as LiveClient, qt as PublishAction, r as ActionErrorItem, ri as CollaborationCommentReactionShortName, rn as ReconnectEvent, rr as VariantAction, rt as EditVariantAction, s as AnimatedTransformOptions, si as CollaborationCommentUpdate, sn as ReleaseId, sr as VideoPlaybackInfoItem, st as EmbeddingsSettingsBody, t as Action, ti as CollaborationCommentPortableTextBlock, tn as RawQuerylessQueryResponse, tr as UploadProgressEvent, tt as EditAction, u as ArchiveReleaseAction, ui as CollaborationCommentsWriteOptions, un as ReplaceDraftAction, ur as VideoPlaybackInfoPublic, ut as FirstDocumentIdMutationOptions, v as ClientConfig, vi as TransformDocument, vn as ResetEvent, vr as VideoSubtitleInfoSigned, vt as ListenEvent, w as ContentSourceMapDocument, wi as PatchDocument, wn as SanityDocumentStub, wr as GenerateTargetDocument, wt as LiveEventMessage, x as ClientVariant, xi as TransformTargetDocument, xn as ResumableListenOptions, xr as GenerateInstruction, xt as ListenParams, y as ClientPerspective, yi as TransformOperation, yn as ResponseQueryOptions, yr as WelcomeBackEvent, yt as ListenEventName, z as CreateVariantDefinitionAction, zn as ThumbnailTransformOptions, zr as BaseTransaction, zt as MutationOperation } from "./types-DiPF0ENT.js";
import { FetchFunction, RequestOptions as RequestOptions$1, TimeoutErrorLike, isTimeoutError } from "get-it";
import { Observable } from "rxjs";
import { EventSourceConstructor } from "eventsource";
/**
* @internal - it may have breaking changes in any release
*/
declare function validateApiPerspective(perspective: unknown): asserts perspective is ClientPerspective;
/**
* Thrown when the EventSource connection could not be established, or was rejected by the server.
* Transient failures (network drops, 5xx, 408, 429) are reconnected internally and emitted as
* `reconnect` events; a permanent rejection (any other 4xx, eg an expired token) errors the
* stream with this class so consumers can react — check `status` for the rejection code.
*
* @public
*/
declare class ConnectionFailedError extends Error {
readonly name = "ConnectionFailedError";
/**
* HTTP status code of the rejected connection attempt, if known.
* Only set when the EventSource implementation exposes it — the `eventsource`
* package used by the client does (as `code` on its error events), while
* native EventSource implementations (browser and Node.js) do not.
*/
readonly status?: number;
constructor(message?: string, options?: ErrorOptions & {
status?: number;
});
}
/**
* The listener has been told to explicitly disconnect.
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
* eg in the case of a deleted dataset, a blocked project or similar events.
*
* @public
*/
declare class DisconnectError extends Error {
readonly name = "DisconnectError";
readonly reason?: string;
constructor(message: string, reason?: string, options?: ErrorOptions);
}
/**
* The server sent a `channelError` message. Usually indicative of a bad or malformed request
*
* @public
*/
declare class ChannelError extends Error {
readonly name = "ChannelError";
readonly data?: unknown;
constructor(message: string, data: unknown);
}
/**
* The server sent an `error`-event to tell the client that an unexpected error has happened.
*
* @public
*/
declare class MessageError extends Error {
readonly name = "MessageError";
readonly data?: unknown;
constructor(message: string, data: unknown, options?: ErrorOptions);
}
/**
* An error occurred while parsing the message sent by the server as JSON. Should normally not happen.
*
* @public
*/
declare class MessageParseError extends Error {
readonly name = "MessageParseError";
}
/**
* @public
*/
interface ServerSentEvent<Name extends string> {
type: Name;
id?: string;
data?: unknown;
}
/**
* @internal
*/
type EventSourceEvent<Name extends string> = ServerSentEvent<Name>;
/**
* @internal
*/
type EventSourceInstance = InstanceType<EventSourceConstructor>;
/**
* Sanity API specific EventSource handler shared between the listen and live APIs
*
* Since the `EventSource` API is not provided by all environments, this function enables custom initialization of the EventSource instance
* for runtimes that requires polyfilling or custom setup logic (e.g. custom HTTP headers)
* via the passed `initEventSource` function which must return an EventSource instance.
*
* Possible errors to be thrown on the returned observable are:
* - {@link MessageError}
* - {@link MessageParseError}
* - {@link ChannelError}
* - {@link DisconnectError}
* - {@link ConnectionFailedError}
*
* @param initEventSource - A function that returns an EventSource instance or an Observable that resolves to an EventSource instance
* @param events - an array of named events from the API to listen for.
*
* @internal
*/
declare function connectEventSource<EventName extends string>(initEventSource: () => EventSourceInstance | Observable<EventSourceInstance>, events: EventName[]): Observable<EventSourceEvent<EventName>>;
/**
* Shared properties for HTTP errors (eg both ClientError and ServerError)
* Use `isHttpError` for type narrowing and accessing response properties.
*
* @public
*/
interface HttpError {
statusCode: number;
message: string;
response: {
body: unknown;
url: string;
method: string;
headers: Record<string, string>;
statusCode: number;
statusMessage: string | null;
};
}
/**
* Checks if the provided error is an HTTP error.
*
* @param error - The error to check.
* @returns `true` if the error is an HTTP error, `false` otherwise.
* @public
*/
declare function isHttpError(error: unknown): error is HttpError;
/** @public */
declare class ClientError extends Error {
response: ErrorProps['response'];
statusCode: ErrorProps['statusCode'];
responseBody: ErrorProps['responseBody'];
traceId: ErrorProps['traceId'];
details: ErrorProps['details'];
constructor(res: Any, tag?: string);
}
/** @public */
declare class ServerError extends Error {
response: ErrorProps['response'];
statusCode: ErrorProps['statusCode'];
responseBody: ErrorProps['responseBody'];
traceId: ErrorProps['traceId'];
details: ErrorProps['details'];
constructor(res: Any);
}
/** @internal */
declare function isQueryParseError(error: object): error is QueryParseError;
/**
* Formats a GROQ query parse error into a human-readable string.
*
* @param error - The error object containing details about the parse error.
* @param tag - An optional tag to include in the error message.
* @returns A formatted error message string.
* @public
*/
declare function formatQueryParseError(error: QueryParseError, tag?: string | null, traceId?: string): string;
/** @public */
declare class CorsOriginError extends Error {
projectId?: string;
addOriginUrl?: URL;
constructor({ projectId, credentials }?: {
projectId?: string;
credentials?: boolean;
});
}
/** @public */
declare const requester: Requester;
/**
* @remarks
* As of API version `v2025-02-19`, the default perspective used by the client has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
* @public
*/
declare const createClient: (config: ClientConfig) => SanityClient;
/**
* @public
* @deprecated Use the named export `createClient` instead of the `default` export
*/
declare const deprecatedCreateClient: (config: ClientConfig) => SanityClient;
export { Action, ActionError, ActionErrorItem, type AgentActionParam, type AgentActionParams, type AgentActionPath, type AgentActionPathSegment, type AgentActionTarget, AllDocumentIdsMutationOptions, AllDocumentsMutationOptions, AnimatedImageFormat, AnimatedTransformOptions, Any, ApiError, ArchiveReleaseAction, AssetMetadataType, type AssetsClient, AttributeSet, AuthProvider, AuthProviderResponse, BaseActionOptions, BaseMutationOptions, BasePatch, BaseTransaction, ChannelError, ChannelErrorEvent, ClientConfig, ClientError, ClientPerspective, ClientReturn, ClientVariant, ClientVariantConditions, type CollaborationCommentCreate, type CollaborationCommentDocument, type CollaborationCommentFieldValue, type CollaborationCommentMessage, type CollaborationCommentPortableTextBlock, type CollaborationCommentRange, type CollaborationCommentReactionShortName, type CollaborationCommentSelection, type CollaborationCommentStatus, type CollaborationCommentTarget, type CollaborationCommentUpdate, type CollaborationCommentsClient, type CollaborationCommentsListenOptions, type CollaborationCommentsRequestOptions, type CollaborationCommentsWriteOptions, ConnectionFailedError, type ConstantAgentActionParam, ContentSourceMap, ContentSourceMapDocument, ContentSourceMapDocumentBase, ContentSourceMapDocumentValueSource, ContentSourceMapDocuments, ContentSourceMapLiteralSource, ContentSourceMapMapping, ContentSourceMapMappings, type ContentSourceMapParsedPath, type ContentSourceMapParsedPathKeyedSegment, ContentSourceMapPaths, ContentSourceMapRemoteDocument, ContentSourceMapSource, ContentSourceMapUnknownSource, ContentSourceMapValueMapping, types_d_exports as Context, CorsOriginError, CreateAction, CreateReleaseAction, CreateVariantAction, CreateVariantDefinitionAction, CreateVersionAction, CurrentSanityUser, DatasetAclMode, DatasetCreateOptions, DatasetEditOptions, DatasetResponse, type DatasetsClient, DatasetsResponse, DeleteAction, DeleteReleaseAction, DeleteVariantAction, DeleteVariantDefinitionAction, DiscardAction, DiscardVersionAction, DisconnectError, DisconnectEvent, type DocumentAgentActionParam, EXPERIMENTAL_API_WARNING, EditAction, EditReleaseAction, EditVariantAction, EditVariantDefinitionAction, EditableReleaseDocument, EmbeddingsSettings, EmbeddingsSettingsBody, ErrorProps, type EventSourceEvent, type EventSourceInstance, type FieldAgentActionParam, type FilterDefault, FilteredResponseQueryOptions, FirstDocumentIdMutationOptions, FirstDocumentMutationOptions, FitMode, type GenerateInstruction, type GenerateOperation, type GenerateTarget, type GenerateTargetDocument, type GenerateTargetInclude, type GroqAgentActionParam, type HttpError, HttpRequest, IdentifiedSanityDocumentStub, type ImageDescriptionOperation, ImportReleaseAction, InitializedClientConfig, type InitializedStegaConfig, InsertPatch, type InvokeFunctionEvent, type InvokeFunctionOptions, type InvokeFunctionRequest, ListenEvent, ListenEventName, ListenOptions, ListenParams, type LiveClient, LiveEvent, LiveEventGoAway, LiveEventMessage, LiveEventReconnect, LiveEventRestart, LiveEventWelcome, type Logger, MediaLibraryAssetDocument, MediaLibraryAssetInstanceIdentifier, MediaLibraryAssetVersion, MediaLibraryPlaybackInfoOptions, type MediaLibraryVideoClient, MediaLibraryVideoPlaybackTransformations, MessageError, MessageParseError, MultipleActionResult, MultipleMutationResult, Mutation, MutationError, MutationErrorItem, MutationEvent, MutationOperation, MutationSelection, MutationSelectionQueryParams, type ObservableAssetsClient, type ObservableCollaborationCommentsClient, type ObservableDatasetsClient, type ObservableMediaLibraryVideoClient, ObservablePatch, ObservablePatchBuilder, type ObservableProjectsClient, ObservableSanityClient, ObservableTransaction, type ObservableUsersClient, OpenEvent, PartialExcept, Patch, PatchBuilder, type PatchDocument, PatchMutationOperation, type PatchOperation, PatchOperations, PatchSelection, type PatchTarget, type ProjectsClient, type PromptRequest, PublishAction, PublishReleaseAction, PublishVariantAction, QueryOptions, QueryParams, QueryParseError, QueryWithoutParams, RawQueryResponse, RawQuerylessQueryResponse, RawRequestOptions, ReconnectEvent, ReleaseAction, ReleaseCardinality, ReleaseDocument, ReleaseId, ReleaseState, ReleaseType, ReplaceDraftAction, ReplaceVersionAction, RequestHandler, RequestHandlerOptions, RequestObservableOptions, RequestOptions, RequestUrlOptions, Requester, ResetEvent, type ResolveStudioUrl, ResponseQueryOptions, ResumableListenEventNames, ResumableListenOptions, SanityAssetDocument, SanityClient, SanityDocument, SanityDocumentStub, SanityImageAssetDocument, SanityImagePalette, SanityProject, SanityProjectMember, SanityQueries, SanityReference, SanityUser, ScheduleReleaseAction, ServerError, type ServerSentEvent, SingleActionResult, SingleMutationResult, StackablePerspective, type StegaConfig, type StegaConfigRequiredKeys, StillImageFormat, StoryboardTransformOptions, type StudioBaseRoute, type StudioBaseUrl, type StudioUrl, SyncTag, ThumbnailTransformOptions, type TimeoutErrorLike, Transaction, TransactionAllDocumentIdsMutationOptions, TransactionAllDocumentsMutationOptions, TransactionFirstDocumentIdMutationOptions, TransactionFirstDocumentMutationOptions, TransactionMutationOptions, type TransformDocument, type TransformOperation, type TransformTarget, type TransformTargetDocument, type TransformTargetInclude, type TranslateDocument, type TranslateTarget, type TranslateTargetInclude, UnarchiveReleaseAction, UnfilteredResponseQueryOptions, UnfilteredResponseWithoutQuery, UnpublishAction, UnpublishVariantAction, UnpublishVersionAction, UnscheduleReleaseAction, UploadBody, UploadClientConfig, UploadEvent, UploadProgressEvent, UploadResponseEvent, type UsersClient, VariantAction, VariantDefinitionAction, VersionAction, VideoPlaybackInfo, VideoPlaybackInfoItem, VideoPlaybackInfoItemPublic, VideoPlaybackInfoItemSigned, VideoPlaybackInfoPublic, VideoPlaybackInfoSigned, VideoPlaybackTokens, VideoRenditionInfo, VideoRenditionInfoPublic, VideoRenditionInfoSigned, VideoSubtitleInfo, VideoSubtitleInfoPublic, VideoSubtitleInfoSigned, WelcomeBackEvent, WelcomeEvent, type _listen, connectEventSource, createClient, deprecatedCreateClient as default, formatQueryParseError, isHttpError, isQueryParseError, isTimeoutError, requester, validateApiPerspective };
//# sourceMappingURL=index.d.ts.map