datadirect
Version:
Types for working with Blackbaud's front-end APIs
27 lines (26 loc) • 957 B
TypeScript
import { JSONObject, JSONPrimitiveTypes, JSONValue } from '@battis/typescript-tricks';
export type Response = JSONValue;
export type Method = 'GET' | 'POST' | 'PUT' | 'DELETE';
export type Payload = Record<string, JSONPrimitiveTypes> | JSONObject;
export type FetchParams = {
input: URL | string;
init: {
method: Method;
body?: string;
};
pageSize?: number;
};
export type Prepare<P extends Payload> = (payload: P, base?: string) => FetchParams;
export type Fetch<P extends Payload, R extends Response> = (payload: P) => Promise<R>;
export type Module<P extends Payload> = {
prepare: Prepare<P>;
};
export type RequestParams = {
path: string;
base?: URL | string;
payload: Payload;
method?: Method;
pageSize?: number;
};
export declare function preparePath(path: URL | string, pathParams?: Record<string, JSONPrimitiveTypes>): string;
export declare function prepare(req: RequestParams): FetchParams;