UNPKG

@mollie/api-client

Version:
48 lines (47 loc) 2.52 kB
import { type RequestInit } from 'node-fetch'; import { type SecureContextOptions } from 'tls'; import type Page from '../data/page/Page'; import type Options from '../Options'; import HelpfulIterator from '../plumbing/iteration/HelpfulIterator'; import type Maybe from '../types/Maybe'; import { type IdempotencyParameter } from '../types/parameters'; import { type SearchParameters } from './buildUrl'; interface Data { } interface Context { } /** * This class is essentially a wrapper around fetch. It simplifies communication with the Mollie API over the network. */ export default class NetworkClient { /** * Triggers a request to the Mollie API. * * In contrast to the underlying `fetch` function, this function will: * - retry the request in some scenarios (see `retryingFetch`) * - throw an `ApiError` if the response from the Mollie API indicates an error * - appropriately process the response body before returning it (i.e. parsing it as JSON or throwing an ApiError if the response status indicates an error) */ protected readonly request: (pathname: string, options?: RequestInit) => Promise<any>; constructor({ apiKey, accessToken, versionStrings, apiEndpoint, caCertificates, libraryVersion, nodeVersion, }: Options & { caCertificates?: SecureContextOptions['ca']; libraryVersion: string; nodeVersion: string; }); post<R>(pathname: string, data: Data & IdempotencyParameter, query?: SearchParameters): Promise<R | true>; get<R>(pathname: string, query?: SearchParameters): Promise<R>; list<R>(pathname: string, binderName: string, query?: SearchParameters): Promise<R[]>; page<R>(pathname: string, binderName: string, query?: SearchParameters): Promise<R[] & Pick<Page<R>, 'links'>>; iterate<R>(pathname: string, binderName: string, query: Maybe<SearchParameters>, valuesPerMinute?: number): HelpfulIterator<R>; patch<R>(pathname: string, data: Data): Promise<R>; delete<R>(pathname: string, context?: Context & IdempotencyParameter): Promise<R | true>; /** * Low-level request method for endpoints that don't follow the standard Mollie API conventions. * Allows full control over URL, headers, and body encoding while still using retry logic and error handling. * * @param url - Full URL (not relative to apiEndpoint) * @param options - Full RequestInit options (method, headers, body) */ rawRequest<R>(url: string, options: RequestInit): Promise<R>; } export {};