@datocms/rest-client-utils
Version:
Utilities for DatoCMS REST API clients
34 lines (33 loc) • 1.14 kB
TypeScript
/// <reference lib="dom" />
import type { JobResult } from './internalTypes';
export declare enum LogLevel {
/** No logging */
NONE = 0,
/** Logs HTTP requests (method, URL) and responses (status) */
BASIC = 1,
/** Logs HTTP requests (method, URL, body) and responses (status, body) */
BODY = 2,
/** Logs HTTP requests (method, URL, headers, body) and responses (status, headers, body) */
BODY_AND_HEADERS = 3
}
type RequestOptions = {
baseUrl: string;
fetchJobResult: (jobId: string) => Promise<JobResult>;
fetchFn?: typeof fetch;
apiToken: string | null;
extraHeaders?: Record<string, string>;
logLevel?: LogLevel;
autoRetry?: boolean;
retryCount?: number;
requestTimeout?: number;
method: 'GET' | 'PUT' | 'POST' | 'DELETE';
url: string;
queryParams?: Record<string, unknown>;
body?: unknown;
preCallStack?: string;
logFn?: (message: string) => void;
userAgent?: string;
};
export declare function getFetchFn(customFetchFn?: typeof fetch): typeof fetch;
export declare function request<T>(options: RequestOptions): Promise<T>;
export {};