alepha
Version:
Easy-to-use modern TypeScript framework for building many kind of applications.
115 lines • 3.98 kB
TypeScript
import { Middleware, Static } from "alepha";
import { ServerRouterProvider } from "alepha/server";
//#region ../../src/server/cors/providers/ServerCorsProvider.d.ts
/**
* CORS configuration atom (global defaults)
*/
declare const corsOptions: import("alepha").Atom<import("zod").ZodObject<{
origin: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodString>>;
methods: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
headers: import("zod").ZodDefault<import("zod").ZodArray<import("zod").ZodString>>;
credentials: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
maxAge: import("zod").ZodOptional<import("zod").ZodNumber>;
}, import("zod/v4/core").$strip>, "alepha.server.cors.options">;
type CorsOptions = Static<typeof corsOptions.schema>;
declare module "alepha" {
interface State {
[corsOptions.key]: CorsOptions;
}
}
interface CorsRegistration extends Partial<CorsOptions> {
/**
* Name identifier for this CORS config.
*/
name?: string;
/**
* Path patterns to match (supports wildcards like /api/*).
*/
paths?: string[];
}
declare class ServerCorsProvider {
protected readonly log: import("alepha/logger").Logger;
protected readonly serverRouterProvider: ServerRouterProvider;
protected readonly globalOptions: Readonly<{
origin?: string | undefined;
methods: string[];
headers: string[];
credentials?: boolean | undefined;
maxAge?: number | undefined;
}>;
/**
* Registered CORS configurations with their path patterns
*/
readonly registeredConfigs: CorsRegistration[];
/**
* Register a CORS configuration (called by primitives)
*/
registerCors(config: CorsRegistration): void;
protected readonly onStart: import("alepha").HookPrimitive<"start">;
/**
* Build complete CORS options by merging with global defaults
*/
buildCorsOptions(config: Partial<CorsOptions>): CorsOptions;
/**
* Apply CORS headers to the response
*/
applyCorsHeaders(request: {
headers: {
origin?: string;
};
reply: {
setHeader: (name: string, value: string) => void;
};
}, options: CorsOptions): void;
protected readonly configure: import("alepha").HookPrimitive<"start">;
protected readonly onRequest: import("alepha").HookPrimitive<"server:onRequest">;
isOriginAllowed(origin: string | undefined, allowed: CorsOptions["origin"]): boolean;
}
type ServerCorsProviderOptions = CorsOptions;
//#endregion
//#region ../../src/server/cors/primitives/$cors.d.ts
/**
* Middleware that applies CORS headers to the response and handles OPTIONS preflight.
*
* Reads the request from the ALS context and applies the configured
* CORS headers via `ServerCorsProvider`. Options are merged with
* global CORS defaults.
*
* For OPTIONS preflight requests, the middleware short-circuits with a 204 response
* and skips the handler entirely.
*
* **Route middleware** — requires a request context (`$action`). Throws if used outside one.
*
* ```typescript
* class ApiController {
* getOrders = $action({
* use: [$cors({ origin: "https://app.example.com", credentials: true })],
* handler: async ({ query }) => { ... },
* });
* }
* ```
*/
declare const $cors: (options?: Partial<CorsOptions>) => Middleware;
//#endregion
//#region ../../src/server/cors/index.d.ts
declare module "alepha/server" {
interface ServerRoute {
/**
* Route-specific CORS configuration.
* If set, overrides the global CORS options for this route.
*/
cors?: CorsOptions;
}
}
/**
* Cross-Origin Resource Sharing configuration.
*
* **Features:**
* - CORS policy definition
*
* @module alepha.server.cors
*/
declare const AlephaServerCors: import("alepha").Service<import("alepha").Module>;
//#endregion
export { $cors, AlephaServerCors, CorsOptions, CorsRegistration, ServerCorsProvider, ServerCorsProviderOptions, corsOptions };
//# sourceMappingURL=index.d.ts.map