@vercel/microfrontends
Version:
Defines configuration and utilities for microfrontends development
155 lines (148 loc) • 4.92 kB
TypeScript
import { a as ApplicationId, P as PathGroup, D as DefaultApplication$1, b as ChildApplication$1, A as Application$1, C as Config } from './types-1cec43e6.js';
import { H as HostConfig, L as LocalHostConfig, A as ApplicationOverrideConfig, O as OverridesConfig } from './types-1fb60496.js';
interface ClientApplication {
routing?: PathGroup[];
default?: boolean;
}
interface ClientConfig {
applications: Record<ApplicationId, ClientApplication>;
}
interface MicrofrontendConfigClientOptions {
removeFlaggedPaths?: boolean;
}
declare class MicrofrontendConfigClient {
applications: ClientConfig['applications'];
pathCache: Record<string, string>;
private readonly serialized;
constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions);
/**
* Create a new `MicrofrontendConfigClient` from a JSON string.
* Config must be passed in to remain framework agnostic
*/
static fromEnv(config: string | undefined, opts?: MicrofrontendConfigClientOptions): MicrofrontendConfigClient;
isEqual(other: MicrofrontendConfigClient): boolean;
getApplicationNameForPath(path: string): string | null;
serialize(): ClientConfig;
}
interface HostOptions {
isLocal?: boolean;
}
declare class Host {
protocol: 'http' | 'https';
host: string;
port?: number;
local: boolean | undefined;
constructor(hostConfig: HostConfig | string, options?: HostOptions);
protected static parseUrl(url: string, defaultProtocol?: string): {
protocol: Host['protocol'];
host: string;
port?: number;
};
private static getMicrofrontendsError;
isLocal(): boolean;
toString(): string;
toUrl(): URL;
}
/**
* A Host subclass with defaults for locally running applications
*/
declare class LocalHost extends Host {
constructor({ appName, local, }: {
appName: string;
local?: string | number | LocalHostConfig;
});
}
declare class Application {
readonly default: boolean;
name: string;
development: {
local: LocalHost;
fallback?: Host;
};
fallback?: Host;
packageName?: string;
overrides?: {
environment?: Host;
};
readonly serialized: Application$1;
constructor(name: string, { app, overrides, isDefault, }: {
app: Application$1;
overrides?: ApplicationOverrideConfig;
isDefault?: boolean;
});
isDefault(): boolean;
getAssetPrefix(): string;
getAutomationBypassEnvVarName(): string;
serialize(): Application$1;
}
declare class DefaultApplication extends Application {
readonly default = true;
fallback: Host;
constructor(name: string, { app, overrides, }: {
app: DefaultApplication$1;
overrides?: ApplicationOverrideConfig;
});
getAssetPrefix(): string;
}
declare class ChildApplication extends Application {
readonly default = false;
routing: PathGroup[];
constructor(name: string, { app, overrides, }: {
app: ChildApplication$1;
overrides?: ApplicationOverrideConfig;
});
static validate(name: string, app: ChildApplication$1): void;
}
/**
* A class to manage the microfrontends configuration.
*/
declare class MicrofrontendConfigIsomorphic {
config: Config;
defaultApplication: DefaultApplication;
childApplications: Record<string, ChildApplication>;
overrides?: OverridesConfig;
options?: Config['options'];
private readonly serialized;
constructor({ config, overrides, }: {
config: Config;
overrides?: OverridesConfig;
});
static validate(config: string | Config): Config;
static fromEnv({ cookies, }: {
cookies?: {
name: string;
value: string;
}[];
}): MicrofrontendConfigIsomorphic;
isOverridesDisabled(): boolean;
getConfig(): Config;
getApplicationsByType(): {
defaultApplication?: DefaultApplication;
applications: ChildApplication[];
};
getChildApplications(): ChildApplication[];
getAllApplications(): (DefaultApplication | ChildApplication)[];
getApplication(name: string): DefaultApplication | ChildApplication;
hasApplication(name: string): boolean;
getApplicationByProjectName(projectName: string): DefaultApplication | ChildApplication | undefined;
/**
* Returns the default application.
*/
getDefaultApplication(): DefaultApplication;
/**
* Returns the configured port for the local proxy
*/
getLocalProxyPort(): number;
/**
* Serializes the class back to the Schema type.
*
* NOTE: This is used when writing the config to disk and must always match the input Schema
*/
toSchemaJson(): Config;
toClientConfig(): MicrofrontendConfigClient;
serialize(): {
config: Config;
overrides?: OverridesConfig;
};
}
export { MicrofrontendConfigIsomorphic };