UNPKG

discourse-js

Version:

A client-side javascript wrapper for the discourse API.

53 lines (52 loc) 1.98 kB
import { ICategories } from './resources/Categories'; import { IGroups } from './resources/Groups'; import { IMessages } from './resources/Messages'; import { INotifications } from './resources/Notifications'; import { IPosts } from './resources/Posts'; import { IPreferences } from './resources/Preferences'; import { ITopics } from './resources/Topics'; import { IUploads } from './resources/Uploads'; import { IUsers } from './resources/Users'; export * from './resources/index'; export * from './types/index'; export * from './utils'; interface RequestOptions { path?: string; headers?: Record<string, string>; body?: Record<string, any>; method?: string; } declare type FinalRequestOptions = Omit<RequestOptions, 'body'> & { body?: BodyInit; }; interface ConfigInterface { apiKey: string | null; apiUsername: string | null; userApiKey?: string | null; baseUrl?: string | null; } export default class Discourse { _BASE_URL: string; _USER_API_KEY: string; _API_KEY: string | null; _API_USERNAME: string | null; isUsingAdminAPI: string; categories: ICategories; groups: IGroups; messages: IMessages; notifications: INotifications; posts: IPosts; preferences: IPreferences; topics: ITopics; uploads: IUploads; users: IUsers; constructor(userApiKey: string, baseUrl: string, apiKey?: string | null); config: ({ userApiKey, baseUrl, apiUsername, apiKey }?: ConfigInterface) => void; requestHeaders(): Record<string, string>; createBody: (body: Record<string, string | number | Blob>) => FormData; get: ({ path, headers }?: RequestOptions) => Promise<any>; post: ({ path, headers, body }: RequestOptions) => Promise<any>; put({ path, headers, body }: RequestOptions): Promise<any>; delete({ path, headers, body }: RequestOptions): Promise<any>; request: (options: FinalRequestOptions) => Promise<any>; }