Skip to content

core

@infobloxopen/devedge-ufe-core is the mechanism-only contract for a devedge micro-frontend. It defines the lifecycle types, the loud nav-group validation, the read-only session seam and its auth primitives, and the manifest types. It has no runtime dependencies and nothing product-specific.

Import from @infobloxopen/devedge-ufe-core.

Exports

SymbolKindSummary
MicrofrontendDescriptorinterfaceIdentifies a micro-frontend: an id and an entry.
HostPropsinterfaceThe props a host passes to a micro-frontend; carries the session.
MicrofrontendModuleinterfaceThe lifecycle contract: bootstrap, mount, unmount.
NavItemTypetypeThe allowed nav-item shapes (menuItem, tab, and others).
NavContributioninterfaceA nav item a micro-frontend contributes, including its group.
GroupRegistryinterfaceThe set of valid nav groups; known() and has().
staticGroupRegistryfunctionBuilds a GroupRegistry from a fixed list of groups.
validateNavContributionfunctionValidates one contribution against a registry; returns a result.
assertNavContributionsfunctionValidates many contributions; throws on the first invalid group.
ClaimsinterfaceToken claims; sub and arbitrary fields.
SessionEventtypeAn auth event: token acquired, token expired, or signed out.
SessionProviderinterfaceThe read-only session seam a micro-frontend consumes.
AuthEventBusinterfacePublishes and subscribes to SessionEvents.
createAuthEventBusfunctionBuilds an in-memory AuthEventBus.
AuthedFetchOptionsinterfaceOptions for createAuthedFetch, including allowedOrigins.
createAuthedFetchfunctionWraps fetch to attach the bearer token and retry once on 401.
StubSessionProviderclassA SessionProvider with a fixed token, for tests.
UfeExportinterfaceAn entry a micro-frontend exports, such as a ufe-application.
UfeManifestinterfaceThe manifest: nav items, routes, and exports.
defineManifestfunctionValidates a manifest shape at import time and returns it.

Lifecycle

A micro-frontend is a MicrofrontendModule. The host drives it through three methods, passing HostProps to each.

interface MicrofrontendDescriptor {
  id: string;
  entry: string;
}

interface HostProps {
  session: SessionProvider;
  [k: string]: unknown;
}

interface MicrofrontendModule {
  descriptor: MicrofrontendDescriptor;
  bootstrap(props: HostProps): Promise<void>;
  mount(props: HostProps): Promise<void>;
  unmount(props: HostProps): Promise<void>;
}

Nav validation

A NavContribution names the group it belongs to. A GroupRegistry holds the set of valid groups. Validation checks the contribution’s group against the registry.

type NavItemType =
  | 'menuItem' | 'tabParent' | 'tab' | 'tabButton'
  | 'tabLink' | 'headerMenu' | 'dropdownTab';

interface NavContribution {
  name: string;
  path: string;
  group: string;
  type: NavItemType;
  weight?: number;
  access?: unknown;
}

interface GroupRegistry {
  known(): readonly string[];
  has(group: string): boolean;
}

function staticGroupRegistry(groups: readonly string[]): GroupRegistry;
function validateNavContribution(
  c: NavContribution, reg: GroupRegistry, opts?: NavValidationOptions,
): NavValidationResult;
function assertNavContributions(
  cs: NavContribution[], reg: GroupRegistry, opts?: NavValidationOptions,
): void;

assertNavContributions throws on the first contribution whose group is not in the registry, and the error names the unknown group and the valid ones. See Why nav validation is loud for the reasoning.

Session seam

SessionProvider is the read-only view a micro-frontend receives. It can read the token and claims, subscribe to auth events, and request login or logout. It cannot construct a session.

interface Claims {
  sub?: string;
  [k: string]: unknown;
}

type SessionEvent =
  | { type: 'token_acquired'; token: string; expiresAt: number | null }
  | { type: 'token_expired' }
  | { type: 'signed_out' };

interface SessionProvider {
  getToken(): Promise<string>;
  getClaims?(): Promise<Claims | null>;
  subscribe(fn: (e: SessionEvent) => void): () => void;
  login(): Promise<void>;
  logout(): Promise<void>;
}

Auth primitives

createAuthedFetch wraps a fetch implementation so that every request carries the bearer token from the session. On a 401 it triggers login and retries the request once.

interface AuthedFetchOptions {
  allowedOrigins?: string[];
}

function createAuthedFetch(
  session: SessionProvider,
  base?: typeof fetch,
  opts?: AuthedFetchOptions,
): typeof fetch;

interface AuthEventBus {
  publish(e: SessionEvent): void;
  subscribe(fn: (e: SessionEvent) => void): () => void;
}
function createAuthEventBus(): AuthEventBus;

StubSessionProvider is a SessionProvider implementation with a fixed token and claims, for use in tests.

class StubSessionProvider implements SessionProvider {
  constructor(opts?: { token?: string; claims?: Claims | null });
}

Manifest

defineManifest validates a manifest’s shape when the module is imported, so a malformed manifest fails at import or build time instead of at runtime.

interface UfeExport {
  id: string;
  entry: string;
  type: 'ufe-application' | string;
}

interface UfeManifest {
  navItems: NavContribution[];
  routes: string[];
  exports: UfeExport[];
  searchObjects?: unknown[];
}

function defineManifest(m: UfeManifest): UfeManifest;