@tableau/taco-toolkit
Version:
Tableau Connector Toolkit
49 lines (48 loc) • 2.74 kB
TypeScript
import { NextFunction, Request, Response } from 'express';
import { ConnectionData } from '../../shared/types/connection-data';
type RequestLoggerReplacer = (req: Request) => object | string | undefined;
export declare function getRequestLogger(listeningServer: string, replacer?: RequestLoggerReplacer): (req: Request, _res: Response, next: NextFunction) => void;
/**
* Mask secret query params in the url for logging
*/
export declare function maskURL(url: string): string;
/**
* Ensures that there is exactly one of the header and returns its value.
*/
export declare const getSingleRequiredHeader: (name: string, req: Request) => string;
/**
* Ensures that there is at most one of the header and returns its value or undefined.
* Throws if there are multiple entries.
*/
export declare const getSingleOptionalHeader: (name: string, req: Request) => string | undefined;
interface StringHeaderOptions {
allowEmpty: boolean;
}
export declare function getOptionalConnectionData(req: Request): ConnectionData | undefined;
export declare function getConnectionData(req: Request): ConnectionData;
export declare function getRequiredTacoPathHeader(req: Request): string;
export declare function getOptionalTacoPathHeader(req: Request): string | undefined;
/**
* Retrieve a string value from a required request header.
* It validates the value according to the options, and throws an Error when validation fails.
*/
export declare function getRequiredStringHeader(req: Request, headerName: string, options: StringHeaderOptions): string;
/**
* Retrieve a string value from a required request header.
* It validates the value according to the options, and throws an Error when validation fails.
*/
export declare function getOptionalStringHeader(req: Request, headerName: string, options: StringHeaderOptions): string | undefined;
export declare function sendBadRequest(res: Response, message: string | Error): Response<any, Record<string, any>>;
export declare function sendNotFound(res: Response, message: string): Response<any, Record<string, any>>;
export declare function sendInternalServerError(res: Response, error: string | Error): Response<any, Record<string, any>>;
export declare function errorHandler(err: Error, _req: Request, res: Response): void;
export declare function notFoundHandler(_req: Request, res: Response): void;
/**
* Check if request has certain localization header value.
*/
export declare function hasLocalizationHeader(req: Request): boolean;
/**
* Get i18n header value from the request headers. If the header is absent, it returns the given default value.
*/
export declare function getLocalizationHeader(req: Request, headerName: 'language' | 'locale', defaultValue: string): string;
export {};