@dvxch/yandex-music
    Preparing search index...

    Class Request

    Helper for performing requests against the API.

    An instance is created automatically by Client, but may also be pre-configured (custom headers, proxy, timeout) and passed in.

    Index

    Constructors

    Properties

    client?: Client

    The owning client.

    headers: Record<string, string>

    Headers merged into every outgoing request.

    proxyUrl?: string

    Proxy URL applied to every request, if any.

    retries: number

    Retries for transient failures on idempotent requests.

    retryBaseMs: number

    Initial retry backoff in ms.

    retryMaxMs: number

    Maximum retry backoff in ms.

    timeout: number

    Default timeout in milliseconds.

    userAgent: string

    User-Agent sent with every request.

    Methods

    • Perform a DELETE request with a JSON body and return the result.

      Parameters

      • url: string

        Absolute request URL.

      • Optionaljson: JSONValue

        Object serialized as the JSON request body.

      • Optionaltimeout: number

        Optional per-call timeout override (milliseconds).

      Returns Promise<JSONValue | undefined>

      The unwrapped result payload, or undefined for an empty body.

      On any transport or API error.

    • Download a URL straight to a file on disk.

      Streams the response body to disk when the fetch implementation exposes a stream (the global fetch does), so memory stays O(chunk) instead of buffering the whole file and the write overlaps the download. Falls back to buffering on shims without a body stream.

      Parameters

      • url: string

        Absolute request URL.

      • filename: string

        Destination path, including extension.

      • timeout: number = DEFAULT_DOWNLOAD_TIMEOUT_MS

        Optional per-call timeout override (milliseconds).

      Returns Promise<void>

      On any transport or API error.

    • Perform a GET request and return the unwrapped result.

      Parameters

      • url: string

        Absolute request URL.

      • Optionalparams: Params

        Optional query parameters.

      • Optionaltimeout: number

        Optional per-call timeout override (milliseconds).

      • OptionalextraHeaders: Record<string, string>

      Returns Promise<JSONValue | undefined>

      The unwrapped result payload, or undefined for an empty body.

      On any transport or API error.

    post

    • post(
          url: string,
          data?: string | Params,
          timeout?: number,
          extraHeaders?: Record<string, string>,
      ): Promise<JSONValue | undefined>

      Perform a POST request with a form-encoded body and return the result.

      Parameters

      • url: string

        Absolute request URL.

      • Optionaldata: string | Params

        Object (form-encoded) or pre-encoded string body.

      • Optionaltimeout: number

        Optional per-call timeout override (milliseconds).

      • OptionalextraHeaders: Record<string, string>

      Returns Promise<JSONValue | undefined>

      The unwrapped result payload, or undefined for an empty body.

      On any transport or API error.

    • Perform a POST request with a JSON body and return the result.

      Parameters

      • url: string

        Absolute request URL.

      • Optionaljson: JSONValue

        Object serialized as the JSON request body.

      • Optionaltimeout: number

        Optional per-call timeout override (milliseconds).

      Returns Promise<JSONValue | undefined>

      The unwrapped result payload, or undefined for an empty body.

      On any transport or API error.

    • Perform a PUT request with a JSON body and return the result.

      Parameters

      • url: string

        Absolute request URL.

      • Optionaljson: JSONValue

        Object serialized as the JSON request body.

      • Optionaltimeout: number

        Optional per-call timeout override (milliseconds).

      Returns Promise<JSONValue | undefined>

      The unwrapped result payload, or undefined for an empty body.

      On any transport or API error.

    • Stream a GET to a file, racing several mirror URLs and committing to the first that responds — the fastest CDN host wins, cutting tail latency when one mirror is slow. Losing connections are aborted. If the winning stream fails mid-download (or every mirror's headers fail), it falls back to trying the URLs sequentially, so racing never costs robustness.

      Parameters

      • urls: string[]

        Candidate mirror URLs (preference order; used for the fallback).

      • filename: string

        Destination path, including extension.

      • options: { idleTimeoutMs?: number; timeout?: number; transform?: () => Transform } = {}

        timeout (ms) and an optional transform stream factory.

      Returns Promise<void>

      On any transport or API error (after the fallback).

    • Perform a GET request and return the raw response bytes without parsing.

      Used for non-JSON payloads such as download-info XML and audio files.

      Parameters

      • url: string

        Absolute request URL.

      • timeout: number = DEFAULT_DOWNLOAD_TIMEOUT_MS

        Optional per-call timeout override (milliseconds).

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The raw response body.

      On any transport or API error.

    • Set the Authorization header from an OAuth token.

      Parameters

      • token: string

        The OAuth token.

      Returns void

    • Attach a client and, when it carries a token, the authorization header.

      Parameters

      • client: Client

        The client to associate with this transport.

      Returns Client

      The same client, for convenience.

    • Set the Accept-Language header.

      Parameters

      • lang: string

        Language code (one of en, uz, uk, us, ru, kk, hy).

      Returns void

    • Stream a GET response straight to a file, optionally piping it through a transform first (for example an AES-CTR decipher for an encraw stream).

      The whole transfer — including the body read and the transform — runs under a single abort deadline, so a stalled stream is torn down instead of hanging. When the fetch implementation exposes no body stream, it falls back to buffering the bytes, running the transform in memory and writing once.

      Parameters

      • url: string

        Absolute request URL.

      • filename: string

        Destination path, including extension.

      • options: { idleTimeoutMs?: number; timeout?: number; transform?: () => Transform } = {}

        timeout (ms) and an optional transform stream factory (a fresh transform per call, since a transform can't be reused).

      Returns Promise<void>

      On any transport or API error.