@commercelayer/sdk
Version:
Commerce Layer Javascript SDK
56 lines (52 loc) • 2.54 kB
text/typescript
type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
type FetchResponse = any;
type FetchRequestOptions = RequestInit;
type FetchClientOptions = {
interceptors?: InterceptorManager;
fetch?: Fetch;
};
declare class FetchError extends Error {
#private;
static NAME: string;
static isFetchError: (error: any) => error is FetchError;
constructor(status: number, statusText: string, body?: any, request?: FetchRequestOptions);
get errors(): any[] | undefined;
get status(): number;
get statusText(): string;
get request(): Partial<FetchRequestOptions> | undefined;
}
declare const fetchURL: (url: URL, requestOptions: FetchRequestOptions, clientOptions?: FetchClientOptions) => Promise<FetchResponse>;
type InterceptorEventManager<S extends (RequestInterceptor | ResponseInterceptor), F extends (ErrorInterceptor | ResponseInterceptor)> = {
onSuccess?: S;
onFailure?: F;
};
type RequestEventManager = InterceptorEventManager<RequestInterceptor, ErrorInterceptor>;
type ResponseEventManager = InterceptorEventManager<ResponseInterceptor, ErrorInterceptor>;
type ErrorEventManager = InterceptorEventManager<ResponseInterceptor, ResponseInterceptor>;
type InterceptorManager = {
request?: RequestEventManager;
response?: ResponseEventManager;
rawReader?: ErrorEventManager;
};
type RequestObj = {
url: URL;
options: FetchRequestOptions;
};
type RequestInterceptor = (request: RequestObj) => RequestObj | Promise<RequestObj>;
type ResponseObj = Response;
type ResponseInterceptor = (response: ResponseObj) => ResponseObj | Promise<ResponseObj>;
type ApiHeadersLock = 'x-ratelimit-limit' | 'x-ratelimit-interval' | 'x-ratelimit-remaining';
type ApiHeaders = {
[key in ApiHeadersLock]: string | number | boolean;
};
type HeadersObj = Record<string, string> | ApiHeaders;
type ErrorObj = FetchError;
type ErrorInterceptor = (error: ErrorObj) => ErrorObj | Promise<ErrorObj>;
type InterceptorType = 'request' | 'response';
type RawResponseReader = {
id: number;
rawResponse?: any;
headers?: HeadersObj;
ok: boolean;
};
export { type ErrorObj as E, type Fetch as F, type HeadersObj as H, type InterceptorType as I, type RequestObj as R, type ResponseObj as a, type RequestInterceptor as b, type ErrorInterceptor as c, type ResponseInterceptor as d, type RawResponseReader as e, type InterceptorManager as f, type FetchResponse as g, type FetchRequestOptions as h, type FetchClientOptions as i, FetchError as j, fetchURL as k };