@withstudiocms/effect
Version:
Effect-TS Utilities for Astro
56 lines (55 loc) • 3.2 kB
TypeScript
import type { AllResponseOpts, CreateResponseOpts, OptionsResponseOpts } from './types.js';
/**
* Generates a 204 No Content HTTP response for OPTIONS requests with appropriate CORS and allowed methods headers.
*
* @param opts - Configuration options for the response.
* @param opts.allowedMethods - Array of HTTP methods allowed for the route (e.g., ['GET', 'POST']).
* @param opts.allowedOrigins - Optional array of allowed origins for CORS. If not provided, defaults to '*'.
* @param opts.headers - Optional additional headers to include in the response.
* @returns A `Response` object configured for an OPTIONS request.
*/
export declare const OptionsResponse: (opts: OptionsResponseOpts) => Response;
/**
* Creates a `Response` object with a 405 "Method Not Allowed" status.
*
* @param opts - Options for configuring the response.
* @param opts.allowedOrigins - An optional array of allowed origins for CORS. If not provided, defaults to '*'.
* @param opts.headers - Optional additional headers to include in the response.
* @returns A `Response` object with the specified headers and a 405 status.
*/
export declare const AllResponse: (opts?: AllResponseOpts) => Response;
/**
* Creates a JSON HTTP response with customizable status, headers, and CORS settings.
*
* @template T - The type of the data to be serialized as JSON.
* @param data - The data to be included in the response body.
* @param opts - Optional settings for the response, including status code, status text, headers, and allowed origins.
* @returns A `Response` object with the serialized JSON data and specified options.
*/
export declare const createJsonResponse: <T>(data: T, opts?: CreateResponseOpts) => Response;
/**
* Creates a `Response` object with a plain text body and customizable options.
*
* @param data - The string content to be sent in the response body.
* @param opts - Optional settings for the response, including status, statusText, headers, and allowed origins.
* @returns A `Response` object with the specified text content and options.
*/
export declare const createTextResponse: (data: string, opts?: CreateResponseOpts) => Response;
/**
* Creates an HTML response with customizable status, headers, and allowed origins.
*
* @param data - The HTML string to be sent in the response body.
* @param opts - Optional settings for the response, including status, statusText, headers, and allowedOrigins.
* @returns A `Response` object with the specified HTML content and headers.
*/
export declare const createHtmlResponse: (data: string, opts?: CreateResponseOpts) => Response;
/**
* Creates a HTTP 302 redirect response with customizable headers.
*
* @param url - The URL to redirect to, set in the `Location` header.
* @param opts - Optional settings for the response.
* @param opts.headers - Additional headers to include in the response.
* @param opts.allowedOrigins - Array of allowed origins for CORS, joined and set in the `Access-Control-Allow-Origin` header. Defaults to `*` if not provided.
* @returns A `Response` object configured for a 302 redirect.
*/
export declare const createRedirectResponse: (url: string, opts?: CreateResponseOpts) => Response;