nuxt-safe-runtime-config
Version:
Validate Nuxt runtime config with Standard Schema at build time
57 lines (54 loc) • 2.1 kB
TypeScript
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
type ErrorBehavior = 'throw' | 'warn' | 'ignore';
type SchemaSource = StandardSchemaV1 | string;
interface ValidationOptions {
/** Standard Schema or project-relative path to a default-exported schema module */
$schema?: SchemaSource;
/** Validate runtime config at build time. Default: true */
validateAtBuild?: boolean;
/** Validate runtime config at runtime via Nitro plugin. Default: false */
validateAtRuntime?: boolean;
/** JSON Schema target version. Default: 'draft-2020-12' */
jsonSchemaTarget?: StandardJSONSchemaV1.Target;
/** Behavior when validation fails. Default: 'throw' */
onError?: ErrorBehavior;
}
interface ShelveProviderOptions {
/** Enable Shelve integration. Default: false */
enabled?: boolean;
/** Shelve project name. Fallback: SHELVE_PROJECT → package.json name */
project?: string;
/** Shelve team slug. Fallback: SHELVE_TEAM */
slug?: string;
/** Alias for slug */
team?: string;
/** Environment name. Fallback: SHELVE_ENV → dev?'development':'production' */
environment?: string;
/** Shelve API URL. Default: https://app.shelve.cloud */
url?: string;
/** Fetch secrets at build time. Default: true */
fetchAtBuild?: boolean;
/** Fetch secrets at runtime (cold start). Default: false */
fetchAtRuntime?: boolean;
}
interface ModuleOptions extends ValidationOptions {
/** Shelve integration options */
shelve?: boolean | ShelveProviderOptions;
}
declare module 'nitro/types' {
interface NitroConfig {
safeRuntimeConfig?: ValidationOptions;
}
interface NitroOptions {
safeRuntimeConfig?: ValidationOptions;
}
}
declare module 'nitropack/types' {
interface NitroConfig {
safeRuntimeConfig?: ValidationOptions;
}
interface NitroOptions {
safeRuntimeConfig?: ValidationOptions;
}
}
export type { ErrorBehavior as E, ModuleOptions as M, SchemaSource as S, ValidationOptions as V, ShelveProviderOptions as a };