@samepage/backend
Version:
Backend utilities for the apis of SamePage integrations
19 lines (18 loc) • 919 B
TypeScript
import type { APIGatewayProxyHandler, APIGatewayProxyEventHeaders } from "aws-lambda";
import { BackendRequest } from "../internal/types";
import { ZodType, z } from "zod";
type Logic<T extends ZodType<any, any, any>, U> = (e: BackendRequest<T>) => string | U | Promise<U | string>;
export declare const qsToJson: (q: string) => Record<string, unknown>;
declare const createAPIGatewayProxyHandler: <T extends ZodType<any, any, any>, U extends Record<string, unknown>>(args: Logic<z.TypeOf<T>, U> | {
logic: Logic<z.TypeOf<T>, U>;
allowedOrigins?: (string | RegExp)[] | undefined;
bodySchema?: {
parse: (s: string) => z.TypeOf<T>;
} | undefined;
includeHeaders?: string[] | undefined;
validate?: ((args: {
body: string | null;
headers: APIGatewayProxyEventHeaders;
}) => boolean) | undefined;
}) => APIGatewayProxyHandler;
export default createAPIGatewayProxyHandler;