@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
112 lines • 4.96 kB
TypeScript
/**
* Zero-config `topology: 'tenant'`: when `@adonis-agora/authkit-client` is booted in the app with its
* `service` configured, its `'authkit.client'` binding answers `tenantOf(resource)` with this app's
* control-plane URL (discovered from the issuer), a service token for the resource (cached, with
* `reset()`) and its partition. Detected by shape, never imported: no dependency on authkit-client.
*
* Merge rule: `{ ...auto, ...config.tenant }`, field by field. Anything set explicitly wins, and
* `tenant: { auto: false }` turns the detection off.
*/
/** What `authkit.client.tenantOf(resource)` answers. */
export interface AuthkitTenant {
url: (() => Promise<string>) & {
refresh?(): Promise<string>;
};
token: (() => Promise<string>) & {
reset?(): void;
};
partition: string;
}
/** The part of the `'authkit.client'` binding this module uses. */
export interface AuthkitTenantClient {
tenantOf(resource: string): AuthkitTenant | Promise<AuthkitTenant>;
}
/** Where a tenant field comes from. */
export type TenantFieldSource = 'explicit' | 'authkit-client (auto)' | 'missing';
export type TenantField = 'url' | 'token' | 'partition';
interface ContainerLike {
hasBinding?(binding: string): boolean;
make(binding: string): Promise<unknown>;
}
/** The fields of a `tenant` block this module reads and fills. */
export interface TenantIdentityFields {
url?: unknown;
token?: unknown;
partition?: unknown;
/** `false`: never fill a field from authkit-client. */
auto?: boolean | undefined;
}
/**
* `@adonis-agora/authkit-client`'s `'authkit.client'` binding when it is booted here AND has
* `tenantOf` (1.1+); an older authkit-client, or none, is `undefined`. A binding that is registered
* but fails to build comes back as `error`.
*/
export declare function authkitTenantClientOf(container: ContainerLike | undefined): Promise<{
client?: AuthkitTenantClient;
error?: string;
}>;
export interface ResolvedTenantIdentity<T> {
/** `{ ...auto, ...explicit }` (only the requested fields are filled). */
tenant: T;
/** Where each requested field came from. */
sources: Partial<Record<TenantField, TenantFieldSource>>;
/** The requested fields nothing supplied. */
missing: TenantField[];
/** Why authkit-client could not supply them (its `tenantOf` threw), when it did. */
authkitError?: string;
/** Whether a usable `authkit.client` (with `tenantOf`) is booted here. */
authkit: boolean;
}
/**
* Fills the missing `fields` of `explicit` from `authkit.client.tenantOf(resource)`. `tenantOf` is
* only called when a field is missing, so an app with every field explicit (or with authkit-client
* for login only, and no `service`) is unaffected.
*/
export declare function resolveTenantIdentity<T extends TenantIdentityFields>(explicit: T | undefined, options: {
container: ContainerLike | undefined;
resource: string;
fields: readonly TenantField[];
}): Promise<ResolvedTenantIdentity<T>>;
/**
* The boot error for a tenant with fields nothing supplied: names them, and both fixes.
*/
export declare function missingTenantFieldsMessage(input: {
lib: string;
configFile: string;
resource: string;
missing: readonly TenantField[];
/** The explicit form to suggest, e.g. `tenant: { url, token, partition }`. */
explicitForm: string;
authkitError?: string | undefined;
autoDisabled?: boolean | undefined;
}): string;
/** A boot error split for a doctor result: the problem, and the fix when the message carries one. */
export declare function splitTenantError(text: string): {
message: string;
fix?: string;
};
/**
* One doctor line of where each field came from, grouped by source:
* `tenant url/token/partition: authkit-client (auto)`, or
* `tenant url: explicit; token/partition: authkit-client (auto)`.
*/
export declare function describeTenantSources(sources: Partial<Record<TenantField, TenantFieldSource>>, order?: readonly TenantField[]): string;
/** The resource media's tenant tokens and control-plane URL are for. */
export declare const MEDIA_TENANT_RESOURCE = "urn:agora:media";
/** A media config with authkit-client's tenant fields filled in, and where each came from. */
export interface ResolvedMediaTenant<C> {
config: C;
/** Only on a tenant. */
sources?: Partial<Record<TenantField, TenantFieldSource>>;
}
/**
* `config` with `tenant.url`/`token`/`partition` filled in from `authkit.client.tenantOf` where
* they are missing (explicit fields win). Anything else than a tenant comes back unchanged. Throws
* the boot error when a field resolves from neither.
*/
export declare function resolveMediaTenant<C extends {
topology?: string | undefined;
tenant?: TenantIdentityFields | undefined;
}>(config: C, container: ContainerLike | undefined): Promise<ResolvedMediaTenant<C>>;
export {};
//# sourceMappingURL=authkit_tenant.d.ts.map