// This file was auto-generated by Fern from our API Definition. import { BearerAuthProvider } from "./auth/BearerAuthProvider.js"; import { mergeHeaders } from "./core/headers.js"; import * as core from "./core/index.js"; import type * as environments from "./environments.js"; export type BaseClientOptions = { environment?: core.Supplier; /** Specify a custom URL to connect the client to. */ baseUrl?: core.Supplier; /** Additional headers to include in requests. */ headers?: Record | null | undefined>; /** The default maximum time to wait for a response in seconds. */ timeoutInSeconds?: number; /** The default number of times to retry the request. Defaults to 2. */ maxRetries?: number; /** Provide a custom fetch implementation. Useful for platforms that don't have a built-in fetch or need a custom implementation. */ fetch?: typeof fetch; /** Configure logging for the client. */ logging?: core.logging.LogConfig | core.logging.Logger; } & BearerAuthProvider.AuthOptions; export interface BaseRequestOptions { /** The maximum time to wait for a response in seconds. */ timeoutInSeconds?: number; /** The number of times to retry the request. Defaults to 2. */ maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; /** Additional query string parameters to include in the request. */ queryParams?: Record; /** Additional headers to include in the request. */ headers?: Record | null | undefined>; } export interface BaseIdempotentRequestOptions { idempotencyKey?: string | undefined; } export type NormalizedClientOptions = T & { logging: core.logging.Logger; authProvider?: core.AuthProvider; }; export type NormalizedClientOptionsWithAuth = NormalizedClientOptions & { authProvider: core.AuthProvider; }; export function normalizeClientOptions( options: T, ): NormalizedClientOptions { const headers = mergeHeaders( { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "agentmail", "X-Fern-SDK-Version": "0.5.53", "User-Agent": "agentmail/0.5.53", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, }, options?.headers, ); return { ...options, logging: core.logging.createLogger(options?.logging), headers, } as NormalizedClientOptions; } export function normalizeClientOptionsWithAuth( options: T, ): NormalizedClientOptionsWithAuth { const normalized = normalizeClientOptions(options) as NormalizedClientOptionsWithAuth; const normalizedWithNoOpAuthProvider = withNoOpAuthProvider(normalized); normalized.authProvider ??= new BearerAuthProvider(normalizedWithNoOpAuthProvider); return normalized; } function withNoOpAuthProvider( options: NormalizedClientOptions, ): NormalizedClientOptionsWithAuth { return { ...options, authProvider: new core.NoOpAuthProvider(), }; }