UNPKG

@adonis-agora/media

Version:

Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a

71 lines • 3.33 kB
import { Readable } from 'node:stream'; import type { MediaConfig } from '../define_config.js'; import { MediaControlPlaneError } from '../errors.js'; import { type TenantTokenSource } from './auth.js'; /** * Where the control plane is: its base URL including the prefix (`https://hub.example.com/_media`), * or a function that resolves it, such as `controlPlaneUrl({ issuer, resource: 'urn:agora:media' })` * from `@adonis-agora/authkit-client` (looked up again through its `refresh()` after a connection * error). */ export type ControlPlaneUrlSource = string | ((() => Promise<string>) & { refresh?: () => Promise<string>; }); export interface MediaTenantClientOptions { url: ControlPlaneUrlSource; /** This app's name on the control plane (sent as `x-media-app`; the token decides). */ partition: string; token: TenantTokenSource; /** Per request (reads, deletes). Default 10000. */ timeoutMs?: number; /** Per upload. Default 120000. */ uploadTimeoutMs?: number; /** Retries of a read after a network error or a 5xx. Default 1. Writes are never retried. */ retries?: number; fetch?: typeof fetch; } export interface TenantRequest { method?: string; query?: Record<string, string | number | boolean | undefined>; headers?: Record<string, string>; /** A buffer or a stream (streamed as is, never buffered here). */ body?: Uint8Array | Readable | string; /** A person's own access token instead of this app's service token. */ bearer?: string; /** Upload timeout instead of the read one. */ upload?: boolean; } /** * The HTTP client of a media tenant: this app's service token on every call (a fresh one once after * a `401`), reads retried after a network error or a `5xx`, writes never retried, every failure a * {@link MediaControlPlaneError} (`503` when the control plane did not answer). */ export declare class MediaTenantClient { #private; readonly partition: string; constructor(options: MediaTenantClientOptions); /** The control plane's base URL (resolved through discovery when it is a function). */ baseUrl(): Promise<string>; /** The last resolved base URL, without I/O. */ get url(): string | undefined; /** * One call. Answers the response when it is a 2xx or a 304; anything else is thrown as a * {@link MediaControlPlaneError} carrying the control plane's status and code. */ request(path: string, request?: TenantRequest): Promise<Response>; /** A JSON call. */ json<T>(path: string, request?: TenantRequest): Promise<T>; } /** A failed answer as an error: the control plane's own code and message when it sent them. */ export declare function failureOf(response: Response, what: string): Promise<MediaControlPlaneError>; /** A response body as a Node stream. */ export declare function nodeStreamOf(response: Response): Readable; /** The client a tenant config describes. */ export declare function tenantClientOf(config: MediaConfig, options?: { fetch?: typeof fetch; }): MediaTenantClient; /** The client `accounts` describes (a standalone app's account files), or none. */ export declare function accountsClientOf(config: MediaConfig, options?: { fetch?: typeof fetch; }): MediaTenantClient | undefined; //# sourceMappingURL=tenant_client.d.ts.map