@fluvial/cookies
Version:
A cookie management library for Fluvial
23 lines (22 loc) • 1.23 kB
TypeScript
import { CookieCollection } from './cookie-collection.js';
import type { Request, Response } from 'fluvial';
/** This is the middleware function to add the `cookies` property to both the request and response objects. The `cookies` property is a `CookieCollection` object, also available from this module */
export declare function cookies(options?: CookieInitMiddlewareOptions): (req: Request, res: Response) => Promise<"next">;
declare global {
namespace Fluvial {
interface BaseRequest {
cookies?: CookieCollection;
}
interface BaseResponse {
cookies?: CookieCollection;
}
}
}
export interface CookieInitMiddlewareOptions {
/** This skips creating the `cookies` object on the response */
incomingOnly?: boolean;
/** This only creates a `cookies` object on the request if a cookie header is found */
populateIncomingOnlyIfFound?: boolean;
/** This enables compatibility with express.js servers, as they do not allow for the `beforeSend` behavior like Fluvial responses do; as such, this updates the `set-cookie` header(s) every time a change to the cookie collection is made instead of once, right before it's sent */
expressMode?: boolean;
}