import type { NextFunction, Request, Response } from "express"; import type { ZodNullable, ZodObject, ZodOptional, ZodRawShape } from "zod"; import { FindConfig, MedusaPricingContext, RequestQueryFields } from "@jackchim/types"; import { MedusaContainer } from "../container"; import { RestrictedFields } from "./utils/restricted-fields"; /** * List of all the supported HTTP methods */ export declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]; export type RouteVerb = (typeof HTTP_METHODS)[number]; export type MiddlewareVerb = "USE" | "ALL" | RouteVerb; type SyncRouteHandler = (req: MedusaRequest, res: MedusaResponse) => void; export type AsyncRouteHandler = (req: MedusaRequest, res: MedusaResponse) => Promise; export type RouteHandler = SyncRouteHandler | AsyncRouteHandler; export type MiddlewareFunction = MedusaRequestHandler | ((...args: any[]) => any); export type MedusaErrorHandlerFunction = (error: any, req: MedusaRequest, res: MedusaResponse, next: MedusaNextFunction) => Promise | void; export type ParserConfigArgs = { sizeLimit?: string | number | undefined; preserveRawBody?: boolean; }; export type ParserConfig = false | ParserConfigArgs; export type MiddlewareRoute = { /** * @deprecated. Instead use {@link MiddlewareRoute.methods} */ method?: MiddlewareVerb | MiddlewareVerb[]; methods?: MiddlewareVerb[]; matcher: string | RegExp; bodyParser?: ParserConfig; additionalDataValidator?: ZodRawShape; middlewares?: MiddlewareFunction[]; }; export type MiddlewaresConfig = { errorHandler?: false | MedusaErrorHandlerFunction; routes?: MiddlewareRoute[]; }; /** * Route descriptor refers represents a route either scanned * from the filesystem or registered manually. It does not * represent a middleware */ export type RouteDescriptor = { matcher: string; method: RouteVerb; handler: RouteHandler; optedOutOfAuth: boolean; isRoute: true; routeType?: "admin" | "store" | "auth"; absolutePath?: string; relativePath?: string; shouldAppendAdminCors: boolean; shouldAppendStoreCors: boolean; shouldAppendAuthCors: boolean; }; /** * Represents a middleware */ export type MiddlewareDescriptor = { matcher: string; methods?: MiddlewareVerb | MiddlewareVerb[]; handler: MiddlewareFunction; }; export type BodyParserConfigRoute = { matcher: string; methods: MiddlewareVerb | MiddlewareVerb[]; config: ParserConfig; }; export type AdditionalDataValidatorRoute = { matcher: string; methods: MiddlewareVerb | MiddlewareVerb[]; schema: ZodRawShape; validator: ZodOptional>>; }; export type GlobalMiddlewareDescriptor = { config?: MiddlewaresConfig; }; export interface MedusaRequest> extends Request<{ [key: string]: string; }, any, Body> { validatedBody: Body; validatedQuery: RequestQueryFields & QueryFields; /** * TODO: shouldn't this correspond to returnable fields instead of allowed fields? also it is used by the cleanResponseData util */ allowedProperties: string[]; /** * An object containing the select, relation, skip, take and order to be used with medusa internal services */ listConfig: FindConfig; /** * An object containing the select, relation to be used with medusa internal services */ retrieveConfig: FindConfig; /** * An object containing fields and variables to be used with the remoteQuery * * @since 2.2.0 */ queryConfig: { fields: string[]; pagination: { order?: Record; skip: number; take?: number; }; withDeleted?: boolean; }; /** * @deprecated Use {@link queryConfig} instead. */ remoteQueryConfig: MedusaRequest["queryConfig"]; /** * An object containing the fields that are filterable e.g `{ id: Any }` */ filterableFields: QueryFields; includes?: Record; /** * An array of fields and relations that are allowed to be queried, this can be set by the * consumer as part of a middleware and it will take precedence over the req.allowed set * by the api */ allowed?: string[]; errors: string[]; scope: MedusaContainer; session?: any; rawBody?: any; requestId?: string; restrictedFields?: RestrictedFields; /** * An object that carries the context that is used to calculate prices for variants */ pricingContext?: MedusaPricingContext; /** * A generic context object that can be used across the request lifecycle */ context?: Record; /** * Custom validator to validate the `additional_data` property in * requests that allows for additional_data */ additionalDataValidator?: ZodOptional>>; } export interface AuthContext { actor_id: string; actor_type: string; auth_identity_id: string; app_metadata: Record; } export interface PublishableKeyContext { key: string; sales_channel_ids: string[]; } export interface AuthenticatedMedusaRequest> extends MedusaRequest { auth_context: AuthContext; publishable_key_context?: PublishableKeyContext; } export interface MedusaStoreRequest> extends MedusaRequest { auth_context?: AuthContext; publishable_key_context: PublishableKeyContext; } export type MedusaResponse = Response; export type MedusaNextFunction = NextFunction; export type MedusaRequestHandler = (req: MedusaRequest, res: MedusaResponse, next: MedusaNextFunction) => Promise | void; export {}; //# sourceMappingURL=types.d.ts.map