storyblok-js-client
Version:
Universal JavaScript SDK for Storyblok's API
46 lines (45 loc) • 1.48 kB
TypeScript
import { ISbCustomFetch, ISbError, ISbResponse, ISbStoriesParams } from './interfaces';
export interface ResponseFn {
(arg?: ISbResponse | any): any;
}
export interface ISbFetch {
baseURL: string;
timeout?: number;
headers: Headers;
responseInterceptor?: ResponseFn;
fetch?: typeof fetch;
}
declare class SbFetch {
private baseURL;
private timeout?;
private headers;
private responseInterceptor?;
private fetch;
private ejectInterceptor?;
private url;
private parameters;
private fetchOptions;
constructor($c: ISbFetch);
/**
*
* @param url string
* @param params ISbStoriesParams
* @returns Promise<ISbResponse | Error>
*/
get(url: string, params: ISbStoriesParams): Promise<ISbResponse | ISbError>;
post(url: string, params: ISbStoriesParams): Promise<ISbResponse | ISbError>;
put(url: string, params: ISbStoriesParams): Promise<ISbResponse | ISbError>;
delete(url: string, params?: ISbStoriesParams): Promise<ISbResponse | ISbError>;
private _responseHandler;
private _methodHandler;
setFetchOptions(fetchOptions?: ISbCustomFetch): void;
eject(): void;
/**
* Normalizes error messages from different response structures
* @param data The response data that might contain error information
* @returns A normalized error message string
*/
private _normalizeErrorMessage;
private _statusHandler;
}
export default SbFetch;