import * as express from "express"; import * as t from "io-ts"; import { UrlFromString } from "./url"; export declare enum HttpStatusCodeEnum { HTTP_STATUS_200 = 200, HTTP_STATUS_201 = 201, HTTP_STATUS_202 = 202, HTTP_STATUS_203 = 203, HTTP_STATUS_204 = 204, HTTP_STATUS_205 = 205, HTTP_STATUS_206 = 206, HTTP_STATUS_207 = 207, HTTP_STATUS_208 = 208, HTTP_STATUS_300 = 300, HTTP_STATUS_301 = 301, HTTP_STATUS_302 = 302, HTTP_STATUS_303 = 303, HTTP_STATUS_304 = 304, HTTP_STATUS_305 = 305, HTTP_STATUS_306 = 306, HTTP_STATUS_307 = 307, HTTP_STATUS_308 = 308, HTTP_STATUS_400 = 400, HTTP_STATUS_401 = 401, HTTP_STATUS_402 = 402, HTTP_STATUS_403 = 403, HTTP_STATUS_404 = 404, HTTP_STATUS_405 = 405, HTTP_STATUS_406 = 406, HTTP_STATUS_407 = 407, HTTP_STATUS_408 = 408, HTTP_STATUS_409 = 409, HTTP_STATUS_410 = 410, HTTP_STATUS_411 = 411, HTTP_STATUS_412 = 412, HTTP_STATUS_413 = 413, HTTP_STATUS_414 = 414, HTTP_STATUS_415 = 415, HTTP_STATUS_416 = 416, HTTP_STATUS_417 = 417, HTTP_STATUS_418 = 418, HTTP_STATUS_421 = 421, HTTP_STATUS_422 = 422, HTTP_STATUS_423 = 423, HTTP_STATUS_424 = 424, HTTP_STATUS_425 = 425, HTTP_STATUS_426 = 426, HTTP_STATUS_428 = 428, HTTP_STATUS_429 = 429, HTTP_STATUS_431 = 431, HTTP_STATUS_451 = 451, HTTP_STATUS_500 = 500, HTTP_STATUS_501 = 501, HTTP_STATUS_502 = 502, HTTP_STATUS_503 = 503, HTTP_STATUS_504 = 504, HTTP_STATUS_505 = 505, HTTP_STATUS_506 = 506, HTTP_STATUS_507 = 507, HTTP_STATUS_508 = 508, HTTP_STATUS_510 = 510, HTTP_STATUS_511 = 511 } export declare const HttpStatusCode: t.Type; export type HttpStatusCode = t.TypeOf; export declare const ProblemJson: t.PartialC<{ detail: t.StringC; instance: t.StringC; status: t.Type; title: t.StringC; type: t.Type; }>; export type ProblemJson = t.TypeOf; /** * Interface for a Response that can be returned by a middleware or * by the handlers. */ export interface IResponse { readonly kind: T; readonly apply: (response: express.Response) => void; readonly detail?: string; } /** * Interface for a successful response returning a json object. */ export interface IResponseSuccessJson extends IResponse<"IResponseSuccessJson"> { readonly value: T; } /** * Returns a successful json response. * * @param o The object to return to the client */ export declare const ResponseSuccessJson: (o: T) => IResponseSuccessJson; /** * Interface for a successful response returning a xml object. */ export interface IResponseSuccessXml extends IResponse<"IResponseSuccessXml"> { readonly value: T; } /** * Returns a successful xml response. * * @param o The object to return to the client */ export declare const ResponseSuccessXml: (o: T) => IResponseSuccessXml; /** * Interface for a issuing a request accepted response. */ export interface IResponseSuccessAccepted extends IResponse<"IResponseSuccessAccepted"> { readonly payload?: V; } /** * Returns a request accepted response. */ export declare const ResponseSuccessAccepted: (detail?: string, payload?: V | undefined) => IResponseSuccessAccepted; /** * Interface for a issuing a client redirect . */ export type IResponsePermanentRedirect = IResponse<"IResponsePermanentRedirect">; /** * Returns a redirect response. * * @param o The object to return to the client */ export declare const ResponsePermanentRedirect: (location: UrlFromString) => IResponsePermanentRedirect; /** * Interface for issuing a client see-other redirect (uncached by browser) . */ export type IResponseSeeOtherRedirect = IResponse<"IResponseSeeOtherRedirect">; /** * Returns a HTTP_303 redirect response. * * @param location The url to redirect the client to */ export declare const ResponseSeeOtherRedirect: (location: UrlFromString) => IResponseSeeOtherRedirect; /** * Interface for a successful response returning a redirect to a resource. */ export interface IResponseSuccessRedirectToResource extends IResponse<"IResponseSuccessRedirectToResource"> { readonly resource: T; readonly payload: V; } /** * Returns a successful response returning a redirect to a resource. */ export declare const ResponseSuccessRedirectToResource: (resource: T, url: string, payload: V) => IResponseSuccessRedirectToResource; /** * Type for a successful response with no content (http code 204) */ export type IResponseSuccessNoContent = IResponse<"IResponseSuccessNoContent">; /** * Returns a successful response without content and with a status code of 204 */ export declare const ResponseSuccessNoContent: () => IResponse<"IResponseSuccessNoContent">; /** * Interface for a response describing a generic server error. */ export type IResponseErrorGeneric = IResponse<"IResponseErrorGeneric">; /** * Returns a response describing a generic error. * * The error is translated to an RFC 7807 response (Problem JSON) * See https://zalando.github.io/restful-api-guidelines/index.html#176 * */ export declare const ResponseErrorGeneric: (status: HttpStatusCode, title: string, detail: string, problemType?: string) => IResponseErrorGeneric; /** * Interface for a response describing a 404 error. */ export type IResponseErrorNotFound = IResponse<"IResponseErrorNotFound">; /** * Returns a response describing a 404 error. * * @param title The error message */ export declare const ResponseErrorNotFound: (title: string, detail: string) => IResponseErrorNotFound; /** * Interface for a response describing a validation error. */ export type IResponseErrorValidation = IResponse<"IResponseErrorValidation">; /** * Returns a response describing a validation error. */ export declare const ResponseErrorValidation: (title: string, detail: string) => IResponseErrorValidation; /** * Returns a response describing a validation error. */ export declare const ResponseErrorFromValidationErrors: (type: t.Type) => (errors: ReadonlyArray) => IResponseErrorValidation; /** * Interface for 401 unauthorized */ export type IResponseErrorUnauthorized = IResponse<"IResponseErrorUnauthorized"> & { readonly detail: string; }; /** * Returns an unauthorized error response with status code 401. */ export declare const ResponseErrorUnauthorized: (detail: string) => IResponseErrorUnauthorized; /** * The user is not allowed here. */ export type IResponseErrorForbiddenNotAuthorized = IResponse<"IResponseErrorForbiddenNotAuthorized">; /** * Return an IResponseErrorForbiddenNotAuthorized with a default detail if not provided */ export declare const getResponseErrorForbiddenNotAuthorized: (detail?: string) => IResponseErrorForbiddenNotAuthorized; /** * The user is not allowed here. */ export declare const ResponseErrorForbiddenNotAuthorized: IResponseErrorForbiddenNotAuthorized; /** * The user is not allowed to issue production requests. */ export type IResponseErrorForbiddenNotAuthorizedForProduction = IResponse<"IResponseErrorForbiddenNotAuthorizedForProduction">; /** * The user is not allowed to issue production requests. */ export declare const ResponseErrorForbiddenNotAuthorizedForProduction: IResponseErrorForbiddenNotAuthorizedForProduction; /** * The user is not allowed to issue requests for the recipient. */ export type IResponseErrorForbiddenNotAuthorizedForRecipient = IResponse<"IResponseErrorForbiddenNotAuthorizedForRecipient">; /** * The user is not allowed to issue requests for the recipient. */ export declare const ResponseErrorForbiddenNotAuthorizedForRecipient: IResponseErrorForbiddenNotAuthorizedForRecipient; /** * The user is not allowed to send messages with default addresses. */ export type IResponseErrorForbiddenNotAuthorizedForDefaultAddresses = IResponse<"IResponseErrorForbiddenNotAuthorizedForDefaultAddresses">; /** * The user is not allowed to send messages with default addresses. */ export declare const ResponseErrorForbiddenNotAuthorizedForDefaultAddresses: IResponseErrorForbiddenNotAuthorizedForDefaultAddresses; /** * The user is anonymous. */ export type IResponseErrorForbiddenAnonymousUser = IResponse<"IResponseErrorForbiddenAnonymousUser">; /** * The user is anonymous. */ export declare const ResponseErrorForbiddenAnonymousUser: IResponseErrorForbiddenAnonymousUser; /** * The user is not part of any valid authorization groups. */ export type IResponseErrorForbiddenNoAuthorizationGroups = IResponse<"IResponseErrorForbiddenNoAuthorizationGroups">; /** * Return an IResponseErrorForbiddenNoAuthorizationGroups with a default detail if not provided */ export declare const getResponseErrorForbiddenNoAuthorizationGroups: (description?: string) => IResponseErrorForbiddenNoAuthorizationGroups; /** * The user is not part of any valid authorization groups. */ export declare const ResponseErrorForbiddenNoAuthorizationGroups: IResponseErrorForbiddenNoAuthorizationGroups; /** * Interface for a response describing a conflict error (409). */ export type IResponseErrorConflict = IResponse<"IResponseErrorConflict">; /** * Returns a response describing an conflict error (409). * * @param detail The error message */ export declare function ResponseErrorConflict(detail: string): IResponseErrorConflict; /** * Interface for a response describing a precondition failed error (412). */ export type IResponseErrorPreconditionFailed = IResponse<"IResponseErrorPreconditionFailed">; /** * Returns a response describing an precondition failed error (412). * * @param detail The error message */ export declare function ResponseErrorPreconditionFailed(detail: string, problemType?: string): IResponseErrorPreconditionFailed; /** * Interface for a response describing a too many requests error (429). */ export type IResponseErrorTooManyRequests = IResponse<"IResponseErrorTooManyRequests">; /** * Returns a response describing a too many requests error (429). * * @param detail The error message */ export declare function ResponseErrorTooManyRequests(detail?: string): IResponseErrorTooManyRequests; /** * Interface for a response describing an internal server error. */ export type IResponseErrorInternal = IResponse<"IResponseErrorInternal">; /** * Returns a response describing an internal server error. * * @param detail The error message */ export declare function ResponseErrorInternal(detail: string): IResponseErrorInternal; /** * Interface for a response describing a bad gateway. */ export type IResponseErrorBadGateway = IResponse<"IResponseErrorBadGateway">; /** * Returns a response describing a bad gateway error. * * @param detail The error message */ export declare function ResponseErrorBadGateway(detail: string): IResponseErrorBadGateway; /** * Interface for a response describing a service unavailable error. */ export type IResponseErrorServiceUnavailable = IResponse<"IResponseErrorServiceUnavailable">; /** * Returns a response describing a service unavailable error. * * @param detail The error message */ export declare function ResponseErrorServiceUnavailable(detail: string): IResponseErrorServiceUnavailable; /** * Returns a response describing a service temporarily unavailable error. * * @param detail The error message * @param retryAfter seconds to wait for the Retry-After header */ export declare function ResponseErrorServiceTemporarilyUnavailable(detail: string, retryAfter: string): IResponseErrorServiceUnavailable; /** * Interface for a response describing a gateway timeout. */ export type IResponseErrorGatewayTimeout = IResponse<"IResponseErrorGatewayTimeout">; /** * Returns a response describing a gateway timeout error. * * @param detail The error message */ export declare function ResponseErrorGatewayTimeout(detail: string): IResponseErrorGatewayTimeout; /** * Returns a response describing a resource that is no more available. */ export interface IResponseErrorGone extends IResponse<"IResponseErrorGone"> { readonly value: { readonly detail: string; }; } /** * Returns a response with status 410 and a detail msg. */ export declare function ResponseErrorGone(detail: string): IResponseErrorGone;