UNPKG

@vercel/microfrontends

Version:

Defines configuration and utilities for microfrontends development

68 lines (65 loc) 3.36 kB
import { MiddlewareConfig, NextRequest, NextFetchEvent } from 'next/server.js'; import { MicrofrontendConfigIsomorphic } from '../config.js'; import '../types-c9f15465.js'; import '../types-b970b583.js'; import '../types-bee19651.js'; /** Replaces path wildcards (if they exist) with synthesized paths. */ declare function expandWildcards(path: string): string[]; declare function loadMicrofrontendConfigForEdge(path: string): MicrofrontendConfigIsomorphic; declare function getAllChildApplicationNames(mfConfig: MicrofrontendConfigIsomorphic): string[]; declare function getLaunchedPathsForApp(mfConfig: MicrofrontendConfigIsomorphic, appName: string): string[]; declare function getFlaggedPathsForApp(mfConfig: MicrofrontendConfigIsomorphic, appName: string): string[]; /** * Returns a list of examples for all paths in microfrontends.json. */ declare function getAllMicrofrontendPaths(mfConfig: MicrofrontendConfigIsomorphic): string[]; /** * A test to ensure that middleware is configured to work correctly with * microfrontends. Passing this test does NOT guarantee middleware is set up * correctly, but this should find many common problems. This should only be run * on the application marked as "default" in the microfrontend config. If a * configuration issue is found, this will throw an exception (this ensures it * works with any test framework). * * For example, if a microfrontend is configured to serve "/my/path" then the * default application should not contain any matcher that matches "/my/path". */ declare function validateMiddlewareConfig(middlewareConfig: MiddlewareConfig, microfrontendConfigOrPath: string | MicrofrontendConfigIsomorphic, extraProductionMatches?: string[]): void; /** * Ensures that middleware rewrites to the correct path for flagged paths. * IMPORTANT: you must enable the necessary flags before calling this function. */ declare function validateMiddlewareOnFlaggedPaths(microfrontendConfigOrPath: string | MicrofrontendConfigIsomorphic, middleware: (request: NextRequest, event: NextFetchEvent) => Promise<Response | undefined>): Promise<void>; /** * Validates that the given paths route to the correct microfrontend. * The `routesToTest` parameter is a record mapping the application name * to a list a paths (with an optional flag) that should be routed to that * application. If an issue is found, this will throw an exception so that * it can be used with any test framework. * * For example: * * ```ts * { * 'microfrontend-a': ['/a/path', '/a/longer/path'], * 'microfrontend-b': ['/b/path'], * 'microfrontend-c': [ * '/c/path', * { * 'path': '/c/flagged', * 'flag': 'my-flag', * } * ], * } * ``` * * This ensures: * - `/a/path` and `/a/longer/path` get routed to `microfrontend-a` * - `/b/path` gets routed to `microfrontend-b` * - `/c/flagged` gets routed to `microfrontend-c` if `my-flag` is enabled. */ declare function validateRouting(microfrontendConfigOrPath: string | MicrofrontendConfigIsomorphic, routesToTest: Record<string, (string | { path: string; flag: string; })[]>): void; export { expandWildcards, getAllChildApplicationNames, getAllMicrofrontendPaths, getFlaggedPathsForApp, getLaunchedPathsForApp, loadMicrofrontendConfigForEdge, validateMiddlewareConfig, validateMiddlewareOnFlaggedPaths, validateRouting };