import type { CookieSerializeOptions } from "@fastify/cookie"; import type { FastifyViewOptions } from "@fastify/view"; import type { WebsocketPluginOptions } from "@fastify/websocket"; import type { Span } from "@opentelemetry/api"; import type { Instrumentation } from "@opentelemetry/instrumentation"; import type { MetricReader } from "@opentelemetry/sdk-metrics"; import type { SpanExporter } from "@opentelemetry/sdk-trace-base"; import type { AdapterConfig } from "@tweedegolf/storage-abstraction"; import type { Cache, Store } from "cache-manager"; import { type FastifyServerOptions } from "fastify"; import type { RedisOptions } from "ioredis"; import type { LoggerOptions } from "pino"; import type { PrettyOptions } from "pino-pretty"; import type { DataSourceOptions, DeepPartial } from "typeorm"; import type { TelemetryResourceDetector } from "./constants"; import { AssetServingMode } from "./constants"; import type { EnvInterrogator } from "./env"; import type { OperationQueueOptions } from "./operation-queue"; import type { StarscreamServer } from "./types"; export declare const workspaceRoot: string; /** * One logical database that this server can connect to * Optionally includes a subset of settings under the `utility` key, which will be used for maintenance tasks * Optionally includes a list of `replicas` which will be used for read-only queries */ export type DatabaseConfig = DataSourceOptions & { /** * Manage this database with a different set of connection settings, allowing for raise timeouts or alternative user permissions etc * @default undefined **/ utility?: DataSourceOptions; /** * A superuser connection to this database, which will be used for maintenance tasks in development * @default undefined **/ superuser?: DataSourceOptions; /** * A list of read-only replicas of this database * @default [] **/ replicas?: DataSourceOptions[]; /** * Create this database with starscream's command line helpers like `pnpm scream schema:create` and run migrations with `pnpm scream migrations:run` * @default true **/ runTasks?: boolean; /** * A map of oids to types that should be registered for this database. */ oids?: Record; }; /** * The built configuration for the entire Starscream app. Is produced by merging the framework defaults with the values in `starscream.config.ts` under the `always` key and the key for the current environment. Has things like `Config.port`, `Config.database.host`, etc. Stores application-specific configuration at `Config.app`. */ export interface EnvironmentConfig { /** * The configuration files that were loaded and merged together to create this config. * @example * ['/path/to/starscream.config.ts', '/path/to/starscream.config.local.ts'] */ paths: string[]; /** * The current environment this process is running under. * @example * Config.env.name * @example * Config.env.developmentOrTestLike() **/ env: EnvInterrogator; /** * The port this starscream server should listen on * @default 3000 */ port: number; /** * The IP address this starscream server should listen on * @default 127.0.0.1 */ address: string; /** * A string name for this starscream server used in emitted logs and traces */ serviceName: string; /** * Configures the root level logger used by Starscream and all Fastify plugins * @see pino.LoggerOptions */ log: LoggerOptions & { pretty?: PrettyOptions; }; structuredLogging: boolean; /** * A duration in ms that will apply to boot plugins and route plugins executed during boot. The server will fail to boot and throw a timeout error if any individual plugin takes longer than this. * * __Note__: This value is different than the `fastify.pluginTimeout` configuration option. Fastify's internal timeout is uniformly applied to all registered plugins, *including* starscream's meta plugins that register a bunch of children. So, we recommend setting this one to the actual timeout you wish to apply to your route and boot plugins, and setting that one higher, so that starscream itself doesn't trigger the timeout and instead your plugins do. * * @example 5 * 1000 * @default 10_000 (10s) */ appPluginTimeout: number | null; /** * Governs if and how this starscream server serves web assets like JavaScript, CSS, images, etc. * @see AssetServingMode */ assets: { mode: AssetServingMode; } | false; /** * Governs if and how this starscream server renders server side HTML with the @fastify/view template engine. */ views: Partial | false; /** * Governs if and how this starscream server should connect to a database. Can be set to `false` to disable database connectivity altogether, or a database connection object for TypeORM * @see typeorm.ConnectionOptions */ database: false | { /** A set of database configuration options to always apply to every connection */ always?: DataSourceOptions; /** The main database configuration */ main: DatabaseConfig; /** A list of other database configurations for connecting to other shards */ [key: string]: DatabaseConfig | undefined; }; /** * Should this starscream server use a session plugin from fastify to support `request.session` */ sessions: boolean; /** * A map of key directories on the server's filesystem. */ dirs: { /** The root most directory of the project. The monorepo root if using a monorepo. */ workspaceRoot: string; /** The root directory of the server side aspect of a full stack project. */ backendPackageRoot: string; /** The root directory of Starscream's code on disk */ starscreamCoreRoot: string; /** A folder to store temporary files managed by the framework */ tmp: string; /** The base path to find `.ejs` files or similar for rendering views */ views: string; /** A list of directories containing files that need to be loaded every time the server boots */ boot: string[]; /** A list of directories containing route handler and route plugin files named using Starscream's file-based routing syntax. */ routes: string[]; /** The root directory that webpack or other asset managers are writing assets and the asset manifests to. */ assets: string; }; /** Governs if and with what certificates this server should serve HTTPS requests. */ https: { key: string | Buffer; cert: string | Buffer; } | null; /** What default web protocol to use for requests */ defaultProtocol?: "http" | "https"; /** * Raw options to pass to the Fastify server when creating it * @see FastifyServerOptions */ fastify: FastifyServerOptions; /** * Governs if this starscream server should emit tracing data using OpenTelemetry * Starscream couples directly to the OpenTelemetry API and SDK, emitting traces and offering a variety of tracing helpers. * * @see telemetry.ts */ tracing: { /** Enable trace collecting and exporting */ enabled: boolean; /** Thunked function to get a trace exporter for wiring up the OpenTelemetry SDK */ exporter?: SpanExporter | ((config: EnvironmentConfig) => SpanExporter); /** * Optional function to pass to govern if tracing should be enabled for incoming URLs. If passed, evaluated for each request, and tracing is disabled if the function returns false. **/ traceIncomingURL?: (url: string) => boolean; /** * Optional function to pass to govern if tracing should be enabled for HTTP requests made to outgoing URLs using the `http` or `https` node.js standard library modules. If passed, evaluated for each outgoing request, and tracing is disabled if the function returns false. **/ traceOutgoingURL?: (url: string) => boolean; /** * Optional function to pass to decorate spans with extra attributes when an error is thrown and processed by one of the Starscream telemetry helper functions */ errorHook?: (err: Error, span: Span) => void; /** * A list of extra OpenTelemetry instrumentations to register early when the server boots. */ instrumentations?: Instrumentation[]; /** * A list of OpenTelemetry resource detectors, these will run when booting the telemetry SDK. */ detectors?: TelemetryResourceDetector[]; }; /** * Governs if this starscream server should emit metrics data using OpenTelemetry * Starscream couples directly to the OpenTelemetry API and SDK, emitting metrics automatically. * * @see telemetry.ts */ metrics: { /** Enable metric collecting and exporting */ enabled: boolean; /** OpenTelemetry metric collection interval in milliseconds */ intervalMS: number; /** Optionally thunked OpenTelemetry metric exporter for passing to the OpenTelemetry SDK */ reader?: MetricReader | ((config: EnvironmentConfig) => MetricReader); }; /** * Options governing how Starscream serializes cookies for HTTP requests. Passed to the `@fastify/cookie` plugin. */ cookies?: CookieSerializeOptions; /** * A map of domains powering this application. User extensible if you want to add more domains that your application listens on that mean special things to you. There's two built in: `Config.domains.app` for your application (generally the starscream server), and `Config.domains.assets` for where to source assets from. They can be the same if Starscream is serving your assets, but you also might set `Config.domains.assets` to a CDN in production, or something like `webpack-development-server` in development. */ domains: { assets: string; app: string; [key: string]: string; }; /** * A secret key used for encrypting data in cookies and similar. Should not be shard outside the system as it is used to prove the system generated data when it comes back into the system. Would allow session forgery if leaked. */ secretKey: Buffer; /** * Optional configuration for the `server.redis` built in redis client. */ redis: false | RedisOptions; /** * Optional configuration for the `server.cache` built in cache object. */ cache: false | ((server: StarscreamServer) => Promise>); /** * Optional configuration for the built in `server.storage` cloud storage wrapper. */ storage: AdapterConfig | false; /** * Governs graceful shutdown behavior for this starscream server. */ shutdown: { /** * Enable graceful shutdown when this starscream server receives a SIGTERM signal. * If enabled (the default), the server won't immediately quit when SIGTERM'd (ctrl+c'd), and instead allow any in-flight requests to finish processing. The server will stop accepting new connections on the socket immediately and dispatch the fastify `onClose` event. **/ graceful: boolean; /** * A maximum timeout the server should wait for in flight requests to complete before aborting them during a graceful shutdown. */ timeoutMS: number; /** * Options for the `onShutdown` queue. * * @default * { * maxIterations: 1, * defaultPriority: 50, * minPriority: 0, * maxPriority: 100, * throwOnError: false * } */ queue: OperationQueueOptions; }; /** * Optional configuration for the `@fastify/websocket` plugin that allows Starscream routes to serve websocket connections. */ websockets: boolean | WebsocketPluginOptions; /** * A string name for the deployed version of this starscream server. Often uses the git sha of the currently running code. */ release: string; /** * Prevent poorly behaved code from registering a global window object in the context of this nodejs process * Often times, libraries may monkeypatch the `globalThis` object server side to add a window object. Many thing assume that the window object's absence means the code is running server side, so this option enforces that by preventing a window monkeypatch from being set. * Defaults to true in development, but false in test for compatibility with the jest jsdom environment **/ preventWindowObject: boolean; /** * Log any handles which are keeping the node process from exiting after the server has closed using `why-is-node-running`. Useful for debugging what is keeping a process from exiting cleanly, similar to jest's `--detectOpenHandles` feature. * Defaults to false because it is quite expensive to track all open handles. */ logOpenHandlesAfterClose: boolean; /** * User controlled configuration as defined in your `starscream.config.ts`. Carries along whatever data you like, in whatever shape you need, for convenient access at `Config.app`. */ app?: AppConfig; } /** * An app's config is sets of configs set under keys named after environments. */ export interface ConfigSettings { always?: DeepPartial>; [environment: string]: DeepPartial> | undefined; } export declare const tmpDir: string; export declare const DefaultConfig: (backendPackageRoot: string) => EnvironmentConfig; export declare const Config: EnvironmentConfig; export declare const requireAppConfig: (config: EnvironmentConfig) => void;