summaryrefslogtreecommitdiff
path: root/nodejs/model/api.ts
blob: 69c7ee1d6c0305b0a54bdce6f1cf40b77eabb8fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
export type APIError = {
	error: string;
	code: number;
	data: unknown;
};

export type Meta = {
	limit: number;
	page: number;
	total: number;
}

export type Request = {
	endpoint: string; // the path part of the url to call
	method?: string; // HTTP method for `fetch` call, defaults to 'GET'
	page?: number; // run a paginated request starting from this page until all the following pages are fetched
	payload?: { [key:string]: any}; // optional json object that will be sent along the request
	priority?: number; // optional priority value, defaults to 10. lower than 10 means the message will be sent faster
};

export type RequestPromise<T> = {
	reject: (reason?: any) => void;
	request: Request;
	resolve: (value: Response<T> | PromiseLike<Response<T>>) => void;
};

export type Response<T> = {
	data: T;
	error?: APIError;
	meta?: Meta;
}