UNPKG

@afriex/core

Version:

HTTP client, configuration and typed errors for the Afriex Business API SDK

89 lines • 3.36 kB
import { Environment, EnvironmentConfig } from "./Environment.js"; import { LogLevel } from "../utils/logger.js"; /** * The API version this SDK was written for, sent as the `x-api-version` * header. It is also what the API serves when the header is left out. */ export declare const DEFAULT_API_VERSION = "2026-05-18"; /** The header the API version is sent in. */ export declare const API_VERSION_HEADER = "x-api-version"; /** The header a request signature is sent in. */ export declare const API_SIGNATURE_HEADER = "x-api-signature"; /** * The `User-Agent` sent when none is configured. `@afriex/sdk` adds its own * version to it; a client built from `@afriex/core` alone sends it as it is. */ export declare const DEFAULT_USER_AGENT = "Afriex-TypeScript-SDK"; export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | "TRACE"; /** * The methods retried by default: those that are safe to send twice. POST and * PATCH are left out, because repeating one can repeat its effect. */ export declare const DEFAULT_RETRYABLE_METHODS: readonly HttpMethod[]; /** What a request signer is given. */ export interface RequestToSign { method: string; /** The full URL, query string included. */ url: string; /** The JSON body as it is sent, or an empty string when there is none. */ body: string; } /** * Returns the signature to send in the `x-api-signature` header. Return * `undefined` to send the request unsigned. */ export type RequestSigner = (request: RequestToSign) => string | undefined | Promise<string | undefined>; export interface AfriexConfig { apiKey: string; environment?: Environment; customConfig?: Partial<EnvironmentConfig>; logLevel?: LogLevel; enableLogging?: boolean; retryConfig?: RetryConfig; /** * Sent as the `x-api-version` header. Defaults to `DEFAULT_API_VERSION`, * the version this SDK's types describe. */ apiVersion?: string; /** * Signs each request, for a business that has payload signing enabled. * The result is sent in the `x-api-signature` header. */ signRequest?: RequestSigner; /** * Sent as the `User-Agent` header. `@afriex/sdk` sets it to * `Afriex-TypeScript-SDK/<version>` unless you pass your own. */ userAgent?: string; } export interface RetryConfig { maxRetries: number; retryDelay: number; retryableStatusCodes: number[]; /** * The HTTP methods that are retried. Defaults to * `DEFAULT_RETRYABLE_METHODS`, which leaves out POST and PATCH. * * Add POST only when every POST you send can be repeated safely. A * repeated `paymentBatches.withdraw()` pays every recipient again. */ retryableMethods?: HttpMethod[]; } export declare class Config { readonly apiKey: string; readonly environment: Environment; readonly baseUrl: string; readonly timeout: number; readonly maxRetries: number; readonly retryDelay: number; readonly logLevel: LogLevel; readonly enableLogging: boolean; readonly retryableStatusCodes: number[]; readonly retryableMethods: HttpMethod[]; readonly apiVersion: string; readonly signRequest?: RequestSigner; readonly userAgent: string; constructor(config: AfriexConfig); private validateConfig; } //# sourceMappingURL=Config.d.ts.map