{"version":3,"sources":["../src/LiveKitAPI.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { AgentDispatchClient } from './AgentDispatchClient.js';\nimport type { ClientOptions } from './ClientOptions.js';\nimport { ConnectorClient } from './ConnectorClient.js';\nimport { EgressClient } from './EgressClient.js';\nimport { IngressClient } from './IngressClient.js';\nimport { RoomServiceClient } from './RoomServiceClient.js';\nimport { SipClient } from './SipClient.js';\n\n/** Server host and non-auth options, shared by both authentication modes. */\ninterface LiveKitAPICommonOptions {\n /** Server host, including protocol. Falls back to the `LIVEKIT_URL` env var. */\n host?: string;\n /** Optional timeout, in seconds, for all server requests. */\n requestTimeout?: number;\n /**\n * Whether to fail over to alternative regions on retryable errors (LiveKit\n * Cloud hosts only). Defaults to true; set to false to disable.\n */\n failover?: boolean;\n}\n\n/** API key and secret authentication (recommended for backend use). */\ninterface ApiKeyAuth {\n /** API key. Falls back to the `LIVEKIT_API_KEY` env var. */\n apiKey?: string;\n /** API secret. Falls back to the `LIVEKIT_API_SECRET` env var. */\n secret?: string;\n token?: never;\n}\n\n/** Pre-signed token authentication (client-side use; no secret required). */\ninterface TokenAuth {\n /** Pre-signed token, sent verbatim. Falls back to the `LIVEKIT_TOKEN` env var. */\n token: string;\n apiKey?: never;\n secret?: never;\n}\n\n/**\n * Options for {@link LiveKitAPI}. Provide either an `apiKey` and `secret` or a\n * pre-signed `token` — the two modes are mutually exclusive. Any omitted value\n * falls back to its environment variable (`LIVEKIT_URL`, `LIVEKIT_API_KEY`,\n * `LIVEKIT_API_SECRET`, `LIVEKIT_TOKEN`).\n */\nexport type LiveKitAPIOptions = LiveKitAPICommonOptions & (ApiKeyAuth | TokenAuth);\n\n/**\n * A single entry point to every LiveKit server API, exposing each service\n * through a property, e.g. `api.room.createRoom(...)`.\n *\n * @example\n * ```ts\n * const api = new LiveKitAPI({ apiKey, secret }); // or new LiveKitAPI() to read from env\n * await api.room.createRoom({ name: 'my-room' });\n * ```\n */\nexport class LiveKitAPI {\n private readonly _room: RoomServiceClient;\n\n private readonly _egress: EgressClient;\n\n private readonly _ingress: IngressClient;\n\n private readonly _sip: SipClient;\n\n private readonly _agentDispatch: AgentDispatchClient;\n\n private readonly _connector: ConnectorClient;\n\n /**\n * @param options - server host, credentials, and client options; each value\n * falls back to its environment variable when omitted.\n */\n constructor(options: LiveKitAPIOptions = {}) {\n const host = options.host || process.env.LIVEKIT_URL;\n if (!host) {\n throw new Error('host is required (pass it or set LIVEKIT_URL)');\n }\n const { apiKey, secret } = options;\n // Only fall back to LIVEKIT_TOKEN when no explicit credentials were given, so\n // an ambient token can't silently override a passed-in api key and secret.\n const token = options.token || (apiKey || secret ? undefined : process.env.LIVEKIT_TOKEN);\n if (!token && !(apiKey ?? process.env.LIVEKIT_API_KEY)) {\n throw new Error('either a token or an API key and secret are required');\n }\n\n const clientOptions: ClientOptions = {\n requestTimeout: options.requestTimeout,\n failover: options.failover,\n token,\n };\n this._room = new RoomServiceClient(host, apiKey, secret, clientOptions);\n this._egress = new EgressClient(host, apiKey, secret, clientOptions);\n this._ingress = new IngressClient(host, apiKey, secret, clientOptions);\n this._sip = new SipClient(host, apiKey, secret, clientOptions);\n this._agentDispatch = new AgentDispatchClient(host, apiKey, secret, clientOptions);\n this._connector = new ConnectorClient(host, apiKey, secret, clientOptions);\n }\n\n get room(): RoomServiceClient {\n return this._room;\n }\n\n get egress(): EgressClient {\n return this._egress;\n }\n\n get ingress(): IngressClient {\n return this._ingress;\n }\n\n get sip(): SipClient {\n return this._sip;\n }\n\n get agentDispatch(): AgentDispatchClient {\n return this._agentDispatch;\n }\n\n get connector(): ConnectorClient {\n return this._connector;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iCAAoC;AAEpC,6BAAgC;AAChC,0BAA6B;AAC7B,2BAA8B;AAC9B,+BAAkC;AAClC,uBAA0B;AAkDnB,MAAM,WA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