CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mux--mux-node

Official TypeScript library providing comprehensive client access to Mux's video infrastructure API including asset management, live streaming, analytics, and webhook handling

Overview
Eval results
Files

client-setup.mddocs/

Client Setup

Mux client initialization and configuration options for connecting to the Mux API with various authentication methods and request settings.

Imports

import Mux from "@mux/mux-node";
// or
import { Mux } from "@mux/mux-node";

// Additional imports for advanced configuration
import { type ClientOptions } from "@mux/mux-node";

For CommonJS:

const Mux = require("@mux/mux-node");
// or
const { Mux } = require("@mux/mux-node");

Capabilities

Mux Client Constructor

Creates a new Mux API client with configurable authentication and request options.

/**
 * API Client for interfacing with the Mux API.
 * @param options - Configuration options for the client
 */
constructor(options?: ClientOptions);

interface ClientOptions {
  /** Mux token ID (defaults to MUX_TOKEN_ID environment variable) */
  tokenId?: string | null | undefined;
  /** Mux token secret (defaults to MUX_TOKEN_SECRET environment variable) */
  tokenSecret?: string | null | undefined;
  /** Webhook verification secret (defaults to MUX_WEBHOOK_SECRET environment variable) */
  webhookSecret?: string | null | undefined;
  /** JWT signing key (defaults to MUX_SIGNING_KEY environment variable) */
  jwtSigningKey?: string | null | undefined;
  /** JWT private key (defaults to MUX_PRIVATE_KEY environment variable) */
  jwtPrivateKey?: string | null | undefined;
  /** Authorization token (defaults to MUX_AUTHORIZATION_TOKEN environment variable) */
  authorizationToken?: string | null | undefined;
  /** Override the default base URL for the API (defaults to https://api.mux.com) */
  baseURL?: string | null | undefined;
  /** Request timeout in milliseconds (defaults to 60000) */
  timeout?: number | undefined;
  /** Custom HTTP agent for connection management */
  httpAgent?: Agent | undefined;
  /** Custom fetch function implementation */
  fetch?: Core.Fetch | undefined;
  /** Maximum number of retry attempts (defaults to 2) */
  maxRetries?: number | undefined;
  /** Default headers to include with every request */
  defaultHeaders?: Core.Headers | undefined;
  /** Default query parameters to include with every request */
  defaultQuery?: Core.DefaultQuery | undefined;
}

Usage Examples:

import Mux from "@mux/mux-node";

// Basic initialization with token ID and secret
const mux = new Mux({
  tokenId: "your-token-id",
  tokenSecret: "your-token-secret",
});

// Environment variable initialization (recommended)
const mux = new Mux(); // Uses MUX_TOKEN_ID and MUX_TOKEN_SECRET from env

// Authorization token authentication
const mux = new Mux({
  authorizationToken: "your-auth-token",
});

// Custom configuration
const mux = new Mux({
  tokenId: process.env.MUX_TOKEN_ID,
  tokenSecret: process.env.MUX_TOKEN_SECRET,
  baseURL: "https://api-staging.mux.com",
  timeout: 30000,
  maxRetries: 5,
  defaultHeaders: {
    "X-Custom-Header": "custom-value",
  },
});

Static Properties

Access to static constants and utility methods on the Mux class.

/** Default request timeout in milliseconds */
static DEFAULT_TIMEOUT: number;

/** Convert data to File object for uploads */
static toFile: typeof toFile;

/** Create File from file system path */
static fileFromPath: typeof fileFromPath;

Error Classes

Static access to all Mux error classes for error handling and type checking.

static MuxError: typeof MuxError;
static APIError: typeof APIError;
static APIConnectionError: typeof APIConnectionError;
static APIConnectionTimeoutError: typeof APIConnectionTimeoutError;
static APIUserAbortError: typeof APIUserAbortError;
static NotFoundError: typeof NotFoundError;
static ConflictError: typeof ConflictError;
static RateLimitError: typeof RateLimitError;
static BadRequestError: typeof BadRequestError;
static AuthenticationError: typeof AuthenticationError;
static InternalServerError: typeof InternalServerError;
static PermissionDeniedError: typeof PermissionDeniedError;
static UnprocessableEntityError: typeof UnprocessableEntityError;

Resource Access

Access to all API resources through the initialized client instance.

/** Video operations including assets, live streams, uploads, and playback */
video: Video;

/** Analytics, metrics, and monitoring data */
data: Data;

/** System-level operations including signing keys and utilities */
system: System;

/** Webhook signature verification and event parsing */
webhooks: Webhooks;

/** JWT token signing for secure access */
jwt: Jwt;

Authentication Methods

Token ID and Secret Authentication

Primary authentication method using Mux token pairs with automatic Basic authentication header generation.

const mux = new Mux({
  tokenId: "your-token-id",
  tokenSecret: "your-token-secret",
});

// Or use environment variables
// MUX_TOKEN_ID=your-token-id
// MUX_TOKEN_SECRET=your-token-secret
const mux = new Mux();

Authorization Token Authentication

Alternative authentication using bearer tokens for simplified authentication workflows.

const mux = new Mux({
  authorizationToken: "your-bearer-token",
});

// Or use environment variable
// MUX_AUTHORIZATION_TOKEN=your-bearer-token
const mux = new Mux();

Configuration Options

Network Configuration

const mux = new Mux({
  // Custom API endpoint
  baseURL: "https://api-staging.mux.com",

  // Request timeout (milliseconds)
  timeout: 30000,

  // Retry configuration
  maxRetries: 3,

  // Custom HTTP agent
  httpAgent: new Agent({
    keepAlive: true,
    maxSockets: 10,
  }),
});

Default Headers and Query Parameters

const mux = new Mux({
  // Headers added to every request
  defaultHeaders: {
    "X-Custom-Header": "value",
    "User-Agent": "MyApp/1.0",
  },

  // Query parameters added to every request
  defaultQuery: {
    "version": "2024-01",
  },
});

Custom Fetch Implementation

import fetch from "node-fetch";

const mux = new Mux({
  // Custom fetch for specific environments
  fetch: fetch as any,
});

Types

// Core types referenced in ClientOptions
namespace Core {
  /** Custom fetch function interface */
  export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;

  /** HTTP headers record type */
  export type Headers = Record<string, string | null | undefined>;

  /** Default query parameters type */
  export type DefaultQuery = Record<string, string | undefined>;

  /** Request configuration options */
  export interface RequestOptions {
    timeout?: number;
    httpAgent?: Agent;
    signal?: AbortSignal;
    idempotencyKey?: string;
  }
}

/** HTTP Agent interface for connection management */
interface Agent {
  keepAlive?: boolean;
  keepAliveMsecs?: number;
  maxSockets?: number;
  maxFreeSockets?: number;
  timeout?: number;
  scheduling?: "lifo" | "fifo";
}

/** Environment variables used by the SDK */
interface Environment {
  MUX_TOKEN_ID?: string;
  MUX_TOKEN_SECRET?: string;
  MUX_WEBHOOK_SECRET?: string;
  MUX_SIGNING_KEY?: string;
  MUX_PRIVATE_KEY?: string;
  MUX_AUTHORIZATION_TOKEN?: string;
  MUX_BASE_URL?: string;
}

Install with Tessl CLI

npx tessl i tessl/npm-mux--mux-node

docs

analytics-metrics.md

client-setup.md

data.md

delivery-usage.md

error-handling.md

index.md

jwt-signing.md

jwt.md

live-streaming.md

playback-control.md

system-operations.md

system.md

transcription-vocabularies.md

upload-utilities.md

video-assets.md

video-playback.md

video-uploads.md

video.md

web-inputs.md

webhooks.md

tile.json