import { Plugin } from 'vite'; interface StagoConfigPluginOptions { /** * Path to Stago module config file, relative to Vite root. * @default "stago.config.ts" */ configFile?: string; /** * Fail build when config is missing/invalid. * @default true */ strict?: boolean; /** * Also nest a full copy of the build output into a version directory, for * CI/CD pipelines (e.g. 云效内置 OSS 上传组件) that always upload a fixed * local directory as-is to a fixed remote prefix, with no way to inject * the module version into the upload path per-run. * * - `true`: for app modules, nest into `//` (e.g. * `dist/1.2.0/`). Point the pipeline's local-directory setting straight * at `outDir` (e.g. `dist`). Note this uploads `outDir`'s own flat root * files (kept for npm packaging / the non-CDN `/module-assets` fallback) * *again* on every deploy, wasting bandwidth/storage — prefer the string * form below when `outDir` is also used for npm packaging. For api-only * modules, `true` is ignored with a warning because flat CDN output * requires an explicit subdirectory. * - a string, e.g. `'cdn'`: for app modules, nest into * `///` (e.g. `dist/cdn/1.2.0/`). For api-only * modules, copy flat into `//` with no version segment, * so each deployment overwrites the same CDN prefix. Point the pipeline's * local directory at `/` — a name fixed once at * pipeline-setup time, independent of the version — so only the CDN copy * ever lives there and nothing else gets uploaded. * Also auto-slims the npm pack to `module.json` + `api.js` (+ map); * browser assets (`remoteEntry.js`, `assets/`, …) stay on disk for the * CDN nest but are not published — requires MODULE_CDN_BASE_URL in * production (do not rely on `/module-assets` for such packages). * * The nested copy is automatically excluded from npm publishes (a * `.npmignore` is written at `outDir` root at build time) — no manual * `.npmignore`/`files` setup needed, and it works even when this * module's own `package.json` declares `"files": ["dist"]`. Server-only * artifacts (`api.js`) stay on the flat `outDir` for npm / the API host * and are omitted from the nest so they are not uploaded to public CDN/OSS. * @default false */ versionedDist?: boolean | string; } /** * Vite plugin that generates module.json from stago.config.ts * * @description Reads stago.config.ts during build, converts to module.json format, * and writes to dist directory. This ensures npm packages contain the module * configuration needed by the registration service. * * @example * ```typescript * // vite.config.ts * import { stagoConfigPlugin } from '@stago/sdk/vite' * * export default defineConfig({ * plugins: [ * stagoConfigPlugin() * ] * }) * ``` */ declare function stagoConfigPlugin(options?: StagoConfigPluginOptions): Plugin; interface StagoApiPluginOptions { /** * Path to Stago module config file, relative to Vite root. * @default "stago.config.ts" */ configFile?: string; /** * Output file name. * @default "api.js" */ outputFileName?: string; } /** * Vite plugin that bundles API handlers into dist/api.js * * @description Reads api.handlers path from stago.config.ts, * bundles the handlers using esbuild, and outputs to dist/api.js. * This enables stago to dynamically load and execute module APIs. * * @example * ```typescript * // vite.config.ts * import { stagoConfigPlugin, stagoApiPlugin } from '@stago/sdk/vite' * * export default defineConfig({ * plugins: [ * stagoConfigPlugin(), * stagoApiPlugin() // Bundle handlers to dist/api.js * ] * }) * ``` */ declare function stagoApiPlugin(options?: StagoApiPluginOptions): Plugin; /** 网关透传给模块 API 的用户;字段与 live.employees 一一对应:id / phone / name */ interface ModuleRequestUser { id: number; phone: string; name: string | null; roles: string[]; } interface StagoDevApiPluginOptions { /** * API 入口(Vite SSR 路径,如 `/src/handlers/index.ts`) * @default 'src/handlers/index.ts' */ apiEntry?: string; /** 是否打印请求日志,默认 true */ logRequests?: boolean; /** 是否打印 SQL 日志,默认 true(可用 DB_LOG_SQL=false 关闭) */ logSql?: boolean; /** * 仅在显式传入时,对未带 x-stago-user 的请求注入该用户。 * 默认不注入(curl / 无头请求的 handler.user 为 null)。 * 需要默认开发用户时可写:`devUser: DEFAULT_DEV_MODULE_REQUEST_USER`(从 `@stago/sdk/dev` 导入)。 */ devUser?: ModuleRequestUser; } /** * Vite 插件:开发模式在 Vite Dev Server 内挂载 Elysia 模块 API(支持 HMR) */ declare function stagoDevApiPlugin(options?: StagoDevApiPluginOptions): Plugin; export { type StagoApiPluginOptions, type StagoConfigPluginOptions, type StagoDevApiPluginOptions, stagoApiPlugin, stagoConfigPlugin, stagoDevApiPlugin };