import { m as SanityConfig, s as DocumentResource, t as SanityInstance } from "../createSanityInstance--Lrldto8.js";
import { n as StateSource, r as BoundStoreAction } from "../createStateSourceAction-CICvr0ZE.js";
import { Bt as SetFavoriteInput, Et as GetUsersOptions, G as getQueryKey, Ii as ProjectAccessErrorDetails, Li as getProjectAccessErrorDetails, Rt as FavoriteDocumentContext, _a as MutationResult, ar as getTopicState, ct as PreviewValue, da as CacheTag, di as parseCommentsOptionsKey, dr as ApplicationStatus, fa as CacheWriter, fr as ApplicationStatusUpdate, ga as MutationDefinition, ha as FetcherSnapshot, li as getCommentsOptionsKey, ma as FetcherDefinition, or as resolveTopic, pa as Fetcher, q as parseQueryKey, r as ApplicationBase, st as PreviewQueryResult, ti as createLogger, va as defineFetcher, xr as MessageBusTopics, ya as defineMutation, zi as getSignInMethodLabel, zt as FavoriteStatusResponse } from "../applications-DowvM7CN.js";
import { _ as installMessageBus, n as InstallMessageBusOptions, o as MessageBusConnection, v as isMessageBusEnvironment, y as resetMessageBus } from "../bus-ClLO0kQU.js";
import { ClientError, SanityClient } from "@sanity/client";
import { Observable } from "rxjs";
import { CurrentUser } from "@sanity/types";
/**
 * The origin an application is served from, or `null` when it has neither an external URL nor
 * a slug to derive one from. Callers treat `null` as "nothing to load" rather than failing the
 * whole list on one bad record.
 *
 * @internal
 */
export declare function getApplicationOrigin(application: Pick<ApplicationBase, 'externalUrl' | 'slug' | 'isSingleton' | 'organizationId'>): string | null;
/**
 * Returns `true` when the config indicates the SDK is running inside a Studio.
 *
 * @internal
 */
export declare function isStudioConfig(config: SanityConfig): boolean;
/** @internal */
type ApiErrorBody = {
  error?: {
    type?: string;
    description?: string;
    projectID?: unknown;
    userID?: unknown;
  };
  type?: string;
  description?: string;
  message?: string;
};
/** @internal Extracts the structured API error body from a ClientError, if present. */
export declare function getClientErrorApiBody(error: ClientError): ApiErrorBody | undefined;
interface DashboardMessageBusState {
  connection?: MessageBusConnection;
}
/**
 * Returns the message bus connection for this instance, connecting on first call.
 *
 * @remarks
 * One connection is made per {@link SanityInstance}, carrying that window's
 * module identity. The first caller wins; later callers get the cached
 * connection. When no host bus is installed it returns `undefined` without
 * caching, so a later call retries once a host installs the bus.
 * @internal
 */
export declare const getDashboardMessageBus: BoundStoreAction<DashboardMessageBusState, [moduleId?: string | undefined], MessageBusConnection<MessageBusTopics> | undefined>;
/**
 * Returns the instance's message bus connection, or throws when no dashboard host has
 * installed a bus. `action` names what the caller was about to do, e.g. `read topic "x"`.
 * @internal
 */
export declare function requireDashboardMessageBus(instance: SanityInstance, action: string): MessageBusConnection;
/**
 * Returns whether a dashboard hosts the instance, over Comlink or an installed message bus.
 *
 * @remarks
 * Answers "does a host own this session", not "has this instance connected yet". Callers
 * such as the login redirect run before {@link getDashboardMessageBus} has been called for
 * the instance, so this must not depend on the connection state.
 * @internal
 */
export declare function isDashboardEnvironment(instance: SanityInstance): boolean;
/**
 * A state source for whether a document is favorited, matched against the `favorites.documents`
 * the dashboard message bus host publishes. The message bus counterpart to the Comlink
 * {@link favorites} fetcher.
 *
 * @remarks
 * Returns `undefined` until the host publishes `applications.capabilities` and, while it provides
 * `favorites`, `favorites.documents`; use {@link resolveBusFavorite} to wait for them. Returns
 * `false` when the host does not provide `favorites` or the `favorites.documents` read fails.
 * A favorite is identified by its published document ID, type, resource and `schemaName`
 * (workspace), like in Dashboard.
 * @internal
 */
export declare function getBusFavoriteState(instance: SanityInstance, context: FavoriteDocumentContext): StateSource<boolean | undefined>;
/**
 * Resolves once {@link getBusFavoriteState} has the next value it waits for: the host's
 * capabilities first, then its `favorites.documents`.
 *
 * @internal
 */
export declare function resolveBusFavorite(instance: SanityInstance): Promise<void>;
/**
 * Sets a document's favorite state over the dashboard message bus. The message bus counterpart
 * to `setFavorite`; the host keeps `favorites.documents` current, so there is no cache to
 * invalidate.
 *
 * @internal
 */
export declare const setBusFavorite: (instance: SanityInstance, input: SetFavoriteInput) => Promise<MutationResult<FavoriteStatusResponse>>;
/**
 * Generates a GROQ projection for preview data without requiring a schema.
 * Uses common field names to make educated guesses about which fields to use.
 *
 * @internal
 */
export declare const PREVIEW_PROJECTION: string;
/**
 * Transforms a projection result (with titleCandidates, subtitleCandidates, media)
 * into a PreviewValue (with title, subtitle, media).
 *
 * @param projectionResult - The raw projection result from GROQ
 * @param instance - The Sanity instance to use for client configuration
 * @param resource - Data resource for the preview
 * @internal
 */
export declare function transformProjectionToPreview(instance: SanityInstance, projectionResult: PreviewQueryResult, resource?: DocumentResource): PreviewValue;
/**
 * Manages telemetry for a single SDK instance.
 *
 * Wraps `@sanity/telemetry`'s batched store with SDK-specific concerns:
 * consent caching, session lifecycle events, and hook usage tracking.
 * The `environment` is captured at construction time and recorded in
 * the event context so downstream pipelines can distinguish dev and
 * production sessions.
 *
 * @internal
 */
interface TelemetryManager {
  /**
   * Eagerly resolve and cache the user's consent status.
   * Returns true only when the user has explicitly opted in (`granted`).
   * Call this before logging any events to avoid buffering events that
   * will be dropped on the first flush.
   */
  checkConsent(): Promise<boolean>;
  /** Log a "SDK Session Started" event */
  logSessionStarted(data: {
    projectId: string;
    perspective: string;
  }): void;
  /** Log a "SDK Hook Mounted" event (deduplicated per hook name) */
  logHookFirstUsed(hookName: string): void;
  /** Log a "SDK Error" event */
  logError(errorType: string, hookName: string): void;
  /** Log a "SDK Session Ended" event and tear down the store */
  endSession(): void;
  /** Tear down the store without logging a session-end event */
  dispose(): void;
  /** The set of hook names used during this session */
  readonly hooksUsed: ReadonlySet<string>;
}
/**
 * Initializes telemetry for a SDK instance if the runtime environment
 * qualifies. The environment is resolved by `getTelemetryEnvironment()`:
 *
 * - `'development'` — local dev servers (`localhost` / `127.0.0.1`, or
 *   Node with `NODE_ENV=development`). This is the original opt-in
 *   surface.
 * - `'production'` — apps deployed to Sanity-controlled domains
 *   (e.g. `*.sanity.studio`, the dashboard). End users are
 *   authenticated Sanity users with Populus consent records, so we
 *   apply the same consent gate as the Studio's `telemetry-sink`.
 *
 * Apps on customer-controlled domains return `null` and skip telemetry
 * entirely.
 *
 * `telemetryManager` and `clientStore` are dynamically imported so the
 * telemetry code path stays out of production bundles for apps that
 * don't qualify. Only the lightweight environment check runs at boot.
 *
 * The `projectId` must be passed explicitly because the resource
 * configuration is typically set by the React layer after the
 * instance has already been created.
 *
 * @internal
 */
export declare function initTelemetry(instance: SanityInstance, projectId: string): void;
/**
 * Retrieves the telemetry manager for an instance, if one exists.
 * Returns undefined when telemetry is disabled or not yet initialized.
 *
 * @internal
 */
export declare function getTelemetryManager(instance: SanityInstance): TelemetryManager | undefined;
/**
 * Record a hook name for an instance. If the telemetry manager is
 * already initialized the event is logged immediately. Otherwise
 * the name is buffered and flushed when init completes.
 *
 * @internal
 */
export declare function trackHookMounted(instance: SanityInstance, hookName: string): void;
/** @internal */
export declare const getUsersKey: (instance: SanityInstance, { resourceType, organizationId, batchSize, projectId, userId }?: GetUsersOptions) => string;
/** @internal */
export declare const parseUsersKey: (key: string) => {
  batchSize: number;
  resourceType?: "organization" | "project";
  projectId?: string;
  organizationId?: string;
  userId?: string;
};
/**
 * Creates a GROQ search filter string (`[@] match text::query("...")`)
 * from a raw search query string.
 *
 * It applies wildcard ('*') logic to the last eligible token and escapes
 * backslashes and double quotes within the search term.
 *
 * If the input query is empty or only whitespace, it returns an empty string.
 *
 * @param query - The raw input search string.
 * @returns The GROQ search filter string, or an empty string.
 * @internal
 */
export declare function createGroqSearchFilter(query: string): string;
/**
 * Generates a random ID of the given length from the alphabet `[a-zA-Z0-9]`, the same shape
 * `@sanity/client` and Sanity Studio use for short IDs such as release IDs.
 *
 * Ported from `@sanity/client`'s `generateReleaseId`, which uses rejection sampling to keep
 * the output unbiased. Uses `crypto.getRandomValues`, which unlike `crypto.randomUUID` is
 * also available on insecure origins (plain http).
 *
 * @internal
 */
export declare function randomId(length?: number): string;
/**
 * Generates a random v4 UUID.
 *
 * Prefers the native `crypto.randomUUID`, which is only available in secure contexts
 * (https, localhost). Falls back to deriving the UUID from `crypto.getRandomValues`,
 * which has no such restriction, so ID generation also works when an app is served over
 * plain http, e.g. when testing from a phone on a local network.
 *
 * @internal
 */
export declare function randomUuid(): string;
/**
 * Creates a shallow copy containing only the provided properties.
 *
 * @internal
 */
export declare function pickProperties<T extends object, K extends keyof T>(value: T, keys: readonly K[]): Pick<T, K>;
/**
 * Compares values deeply across the plain object, array, map, and set shapes used by the SDK.
 * This helper is intended for acyclic SDK data structures and does not guard against circular
 * references.
 *
 * @internal
 */
export declare function isDeepEqual<T>(left: T, right: T): boolean;
export { type ApiErrorBody, type ApplicationStatus, type ApplicationStatusUpdate, type CacheTag, type CacheWriter, type Fetcher, type FetcherDefinition, type FetcherSnapshot, type InstallMessageBusOptions, type MutationDefinition, type MutationResult, type ProjectAccessErrorDetails, createLogger, defineFetcher, defineMutation, getCommentsOptionsKey, getProjectAccessErrorDetails, getQueryKey, getSignInMethodLabel, getTopicState, installMessageBus, isMessageBusEnvironment, parseCommentsOptionsKey, parseQueryKey, resetMessageBus, resolveTopic };
//# sourceMappingURL=_internal.d.ts.map