@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
134 lines • 6.07 kB
TypeScript
import type { HttpContext } from '@adonisjs/core/http';
/** The container binding the registry lives at. */
export declare const AGORA_CONSOLES_BINDING = "agora.consoles";
/** Bound as a VALUE under `'agora.consoles'`. Data only. */
export interface AgoraConsoleRegistry {
readonly version: 1;
readonly entries: AgoraConsoleEntry[];
/**
* Optional, set by an account console (authkit): how a viewer signs out of the app. Every console
* reads it structurally to offer "Sign out" in its sidebar footer. A string is a POST action path.
*/
account?: {
signOut?: string | {
action: string;
} | {
href: string;
};
};
}
/** The icon a console shows in the switcher. An unknown value renders as `generic`. */
export type AgoraConsoleIcon = 'workflow' | 'telescope' | 'media' | 'payments' | 'agent' | 'identity' | 'flags' | 'cms' | 'generic';
/** One hit of a console's global search. */
export interface AgoraConsoleSearchHit {
title: string;
subtitle?: string;
/** Same-origin absolute path (`/media/dashboard#/collections/42`). */
href: string;
}
/** One console the switcher can list. */
export interface AgoraConsoleEntry {
/** `/^[a-z][a-z0-9-]*$/`: `'durable'`, `'telescope'`, … */
id: string;
/** Product title: `'Workflows'`, `'Telescope'`, `'Identity'`. */
title: string;
/** The package behind it, shown under the title (`'@adonis-agora/durable'`). */
package?: string;
icon: AgoraConsoleIcon;
/** Same-origin absolute path of the console shell (`/media/dashboard`). */
path: string;
/** Sort key: durable 10, telescope 20, agent 30, payments 40, media 50, authkit 90. */
order: number;
/** The console's RESOLVED gate (the function its own routes call). Never throws. */
authorize(ctx: HttpContext): Promise<{
allowed: boolean;
reason?: string;
redirectTo?: string;
}>;
/** Global search over this console's data, for a viewer this console already allowed. */
search?(ctx: HttpContext, q: string, limit: number): Promise<AgoraConsoleSearchHit[]>;
}
/** One console as the switcher endpoint returns it. */
export interface VisibleConsole {
id: string;
title: string;
package?: string;
icon: AgoraConsoleIcon;
href: string;
}
/** The answer of `GET <console api>/consoles`. */
export interface VisibleConsoles {
version: 1;
current: string;
consoles: VisibleConsole[];
}
/** The answer of `GET <console api>/consoles/search?q=`. */
export interface ConsoleSearchResults {
version: 1;
q: string;
results: Array<{
id: string;
title: string;
icon: AgoraConsoleIcon;
hits: AgoraConsoleSearchHit[];
}>;
}
/** How long another console's `authorize` (or `search`) may take before it is left out. */
export declare const PROBE_TIMEOUT_MS = 300;
/** Hits per console in a global search. */
export declare const SEARCH_HITS_PER_CONSOLE = 5;
/** Whether `path` is a same-origin absolute path (`/x`, never `//host` or a URL). */
export declare function isSameOriginPath(path: unknown): path is string;
interface ContainerLike {
hasBinding(binding: string): boolean;
bindValue(binding: string, value: unknown): void;
make(binding: string): Promise<unknown>;
}
interface LoggerLike {
warn(message: string): void;
}
/**
* Add a console to the app's switcher registry, creating the registry when this is the first
* console to boot. Consoles call it from their provider's `boot()`; an app can call it too, for a
* console it mounts itself. A registry of another version is left alone; a duplicate id is skipped
* with a warning. Returns whether the entry was added.
*/
export declare function registerAgoraConsole(container: ContainerLike, entry: AgoraConsoleEntry, logger?: LoggerLike): Promise<boolean>;
/** The registry, when one is bound with a version this copy reads. */
export declare function readAgoraConsoles(container: Pick<ContainerLike, 'hasBinding' | 'make'>): Promise<AgoraConsoleRegistry | undefined>;
/** How many consoles other than `selfId` are registered (no `authorize` runs). */
export declare function otherConsoles(registry: AgoraConsoleRegistry | undefined, selfId: string): number;
/**
* The consoles other than `selfId` the viewer may open: every other entry's `authorize` runs in
* parallel, each given {@link PROBE_TIMEOUT_MS}; a timeout, a rejection or any denial hides it. No
* reason is ever returned.
*/
export declare function listVisibleConsoles(registry: AgoraConsoleRegistry | undefined, selfId: string, ctx: HttpContext, timeoutMs?: number): Promise<VisibleConsoles>;
/**
* Global search: `q` goes to every console the viewer may open that has a `search` (this one
* included, the viewer is already in it), in parallel, {@link PROBE_TIMEOUT_MS} each, at most
* {@link SEARCH_HITS_PER_CONSOLE} same-origin hits per console. Consoles with no hit are left out.
*/
export declare function searchConsoles(registry: AgoraConsoleRegistry | undefined, selfId: string, ctx: HttpContext, q: string, timeoutMs?: number): Promise<ConsoleSearchResults>;
/** What {@link mediaConsoleSearch} reads: a record by id, collection totals, and the disk names. */
export interface MediaSearchSource {
find(id: string): Promise<{
id: string;
collection: string;
fileName: string;
} | null>;
/** Every collection with its record count. */
collections(): Promise<Array<{
key: string;
count: number;
}>>;
disks(): string[];
}
/**
* The media console's global search: an exact media record id opens the record, and collection and
* disk names that contain `q` open the collection's records or the disk's library. `base` is the
* console's mount path.
*/
export declare function mediaConsoleSearch(source: (ctx: HttpContext) => Promise<MediaSearchSource>, base: string): (ctx: HttpContext, q: string, limit: number) => Promise<AgoraConsoleSearchHit[]>;
export {};
//# sourceMappingURL=console_switcher.d.ts.map