UNPKG

postmark

Version:

Official Node.js client library for the Postmark HTTP API - https://www.postmarkapp.com

85 lines (84 loc) 3.12 kB
import { ClientOptions, HttpClient } from "./models"; /** * Http client implementation based on the native Fetch API (available in Node 18+). * This keeps the SDK dependency-free while preserving the previous error handling contract. */ export declare class FetchHttpClient extends HttpClient { client: ClientOptions.FetchImplementation; private errorHandler; constructor(configOptions?: ClientOptions.Configuration); /** * Create http client instance with default settings. */ initHttpClient(configOptions?: ClientOptions.Configuration): void; /** * Process http request. * * @param method - Which type of http request will be executed. * @param path - API URL endpoint. * @param queryParameters - Querystring parameters used for http request. * @param body - Data sent with http request. * @param requestHeaders - Headers sent with http request. */ httpRequest<T>(method: ClientOptions.HttpMethod, path: string, queryParameters: object, body: (null | object), requestHeaders: any): Promise<T>; /** * Build the full request URL from the base URL, path and query parameters. * * @private */ private buildRequestURL; /** * Serialize query parameters into a querystring, ignoring undefined and null values. * * Every current *FilteringParameters query value is a string, number, boolean or enum, so * primitive serialization is sufficient today. Arrays are still expanded to repeated keys and * Date values to ISO strings (as axios used to do) so that adding such a filter param later * cannot silently produce a malformed URL via String([1,2]) or String(new Date()). * * @private */ private serializeQueryParameters; private stringifyQueryValue; /** * Read and parse the response body. Postmark responses are JSON, but empty bodies are tolerated. * * @private */ private parseResponseBody; /** * Build a Postmark error from a non-2xx response. * * @param data - parsed response body. * @param status - http response status code. * * @return {PostmarkError} - formatted Postmark error * @private */ private buildRequestError; /** * Transform a thrown error (network failure, timeout, abort) into a proper Postmark error. * * @param errorThrown - error thrown while performing the request. * * @return {PostmarkError} - formatted Postmark error * @private */ private transformError; /** * Build an AbortSignal that aborts the request once the configured timeout elapses. * * AbortSignal.timeout() is available at runtime in Node 18+, but is not present in the * lib.dom typings shipped with the TypeScript version this project pins, so it is * referenced through an explicit cast. * * @private */ private buildTimeoutSignal; /** * Timeout in seconds is adjusted to milliseconds. * * @private */ private getRequestTimeoutInMilliseconds; private adjustValue; }