UNPKG

wiki-saikou

Version:

The library provides the out of box accessing to MediaWiki API in both browsers & Node.js, and the syntax is very similar to vanilla `new mw.Api()`. TypeScript definition included~

83 lines (82 loc) 3.66 kB
import { Fexios, FexiosConfigs, FexiosRequestOptions, FexiosFinalContext } from 'fexios'; /** * MediaWiki Api for Axios * Provides the API call methods similar to `mw.Api` at non-mw environments * * @author Dragon-Fish <dragon-fish@qq.com> * @license MIT */ export declare class MediaWikiApi { readonly baseURL?: string | undefined; readonly version: any; readonly request: Fexios; private tokens; readonly cookies: Map<string, string>; readonly defaultParams: MwApiParams; readonly defaultOptions: Partial<FexiosConfigs>; static INIT_DEFAULT_PARAMS: MwApiParams; constructor(baseURL?: string | undefined, defaultOptions?: Partial<FexiosConfigs>, defaultParams?: MwApiParams); setBaseURL(baseURL: string): this; static normalizeParamValue(item: MwApiParams[keyof MwApiParams]): string | File | undefined; static createRequestHandler(baseURL: string): Fexios; /** Base methods encapsulation */ get<T = any>(query: MwApiParams, options?: FexiosRequestOptions): Promise<FexiosFinalContext<T>>; post<T = any>(data: MwApiParams | URLSearchParams | FormData, options?: FexiosRequestOptions): Promise<FexiosFinalContext<T>>; login(lgname: string, lgpassword: string, params?: MwApiParams, postOptions?: { retry?: number; noCache?: boolean; }): Promise<{ result: 'Success' | 'NeedToken' | 'WrongToken' | 'Failed'; token?: string; reason?: { code: string; text: string; }; lguserid: number; lgusername: string; }>; getUserInfo(): Promise<{ id: number; name: string; groups: string[]; rights: string[]; blockid?: number; blockedby?: string; blockedbyid?: number; blockreason?: string; blockexpiry?: string; blockedtimestamp?: string; }>; /** Token Handler */ getTokens(type?: MwTokenName[]): Promise<Record<string, string>>; token(type?: MwTokenName, noCache?: boolean): Promise<string>; postWithToken<T = any>(tokenType: MwTokenName, body: MwApiParams, options?: { tokenName?: string; retry?: number; noCache?: boolean; }): Promise<FexiosFinalContext<T>>; postWithEditToken<T = any>(body: MwApiParams): Promise<FexiosFinalContext<T>>; static isBadTokenError(data?: any): any; getMessages(ammessages: string[], amlang: string | undefined, options: MwApiParams): Promise<Record<string, string>>; parseWikitext(wikitext: string, title?: string, extraBody?: MwApiParams, options?: FexiosRequestOptions): Promise<string>; } export declare class MediaWikiForeignApi extends MediaWikiApi { constructor(baseURL?: string, defaultOptions?: Partial<FexiosConfigs>, defaultParams?: MwApiParams); } export default MediaWikiApi; export { MediaWikiApi as MwApi, MediaWikiForeignApi as ForeignApi }; export declare enum WikiSaikouErrorCode { HTTP_ERROR = "HTTP_ERROR", LOGIN_FAILED = "LOGIN_FAILED", LOGIN_RETRY_LIMIT_EXCEEDED = "LOGIN_RETRY_LIMIT_EXCEEDED", TOKEN_RETRY_LIMIT_EXCEEDED = "TOKEN_RETRY_LIMIT_EXCEEDED" } export declare class WikiSaikouError extends Error { readonly code: WikiSaikouErrorCode; readonly message: string; readonly cause?: FexiosFinalContext | undefined; readonly name = "WikiSaikouError"; constructor(code: WikiSaikouErrorCode, message?: string, cause?: FexiosFinalContext | undefined); } export type MwApiParams = Record<string, string | number | string[] | undefined | boolean | File>; export type MwTokenName = 'createaccount' | 'csrf' | 'login' | 'patrol' | 'rollback' | 'userrights' | 'watch';