summaryrefslogtreecommitdiff
path: root/nodejs/lib/api.ts
diff options
context:
space:
mode:
Diffstat (limited to 'nodejs/lib/api.ts')
-rw-r--r--nodejs/lib/api.ts35
1 files changed, 33 insertions, 2 deletions
diff --git a/nodejs/lib/api.ts b/nodejs/lib/api.ts
index f023ccf..2bb81a6 100644
--- a/nodejs/lib/api.ts
+++ b/nodejs/lib/api.ts
@@ -3,8 +3,39 @@ import events from 'events';
import { PriorityQueue } from './priority_queue.ts';
import { getToken } from '../database/tokens.ts';
-import { APIError, Request, RequestPromise, Response } from '../model/api.ts';
-import { RateLimitError } from '../model/errors.ts';
+import { RateLimitError } from './errors.ts';
+
+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;
+}
// queue processor module variables
const bus = new events.EventEmitter(); // a bus to notify the queue processor to start processing messages