import { TypedEventEmitter } from "../models/typed-event-emitter"; import { Method } from "./method"; import { HttpApiEvent, HttpApiEventHandlerMap, IHttpOpts, IRequestOpts } from "./interface"; import { QueryDict } from "../utils"; type Body = Record | BodyInit; interface TypedResponse extends Response { json(): Promise; } export type ResponseType = O extends undefined ? T : O extends { onlyData: true; } ? T : TypedResponse; export declare class FetchHttpApi { private eventEmitter; readonly opts: O; private abortController; constructor(eventEmitter: TypedEventEmitter, opts: O); abort(): void; fetch(resource: URL | string, options?: RequestInit): ReturnType; /** * Sets the base URL for the identity server * @param url - The new base url */ setIdBaseUrl(url: string): void; idServerRequest>(method: Method, path: string, params: Record | undefined, prefix: string, accessToken?: string): Promise>; /** * Perform an authorised request to the homeserver. * @param method - The HTTP method e.g. "GET". * @param path - The HTTP path after the supplied prefix e.g. * "/createRoom". * * @param queryParams - A dict of query params (these will NOT be * urlencoded). If unspecified, there will be no query params. * * @param body - The HTTP JSON body. * * @param opts - additional options. If a number is specified, * this is treated as `opts.localTimeoutMs`. * * @returns Promise which resolves to * ``` * { * data: {Object}, * headers: {Object}, * code: {Number}, * } * ``` * If `onlyData` is set, this will resolve to the `data` object only. * @returns Rejects with an error if a problem occurred. * This includes network problems and Matrix-specific error JSON. */ authedRequest(method: Method, path: string, queryParams?: QueryDict, body?: Body, opts?: IRequestOpts): Promise>; /** * Perform a request to the homeserver without any credentials. * @param method - The HTTP method e.g. "GET". * @param path - The HTTP path after the supplied prefix e.g. * "/createRoom". * * @param queryParams - A dict of query params (these will NOT be * urlencoded). If unspecified, there will be no query params. * * @param body - The HTTP JSON body. * * @param opts - additional options * * @returns Promise which resolves to * ``` * { * data: {Object}, * headers: {Object}, * code: {Number}, * } * ``` * If `onlyData is set, this will resolve to the data` * object only. * @returns Rejects with an error if a problem * occurred. This includes network problems and Matrix-specific error JSON. */ request(method: Method, path: string, queryParams?: QueryDict, body?: Body, opts?: IRequestOpts): Promise>; /** * Perform a request to an arbitrary URL. * @param method - The HTTP method e.g. "GET". * @param url - The HTTP URL object. * * @param body - The HTTP JSON body. * * @param opts - additional options * * @returns Promise which resolves to data unless `onlyData` is specified as false, * where the resolved value will be a fetch Response object. * @returns Rejects with an error if a problem * occurred. This includes network problems and Matrix-specific error JSON. */ requestOtherUrl(method: Method, url: URL | string, body?: Body, opts?: Pick): Promise>; /** * Form and return a homeserver request URL based on the given path params and prefix. * @param path - The HTTP path after the supplied prefix e.g. "/createRoom". * @param queryParams - A dict of query params (these will NOT be urlencoded). * @param prefix - The full prefix to use e.g. "/_matrix/client/v2_alpha", defaulting to this.opts.prefix. * @param baseUrl - The baseUrl to use e.g. "https://matrix.org/", defaulting to this.opts.baseUrl. * @returns URL */ getUrl(path: string, queryParams?: QueryDict, prefix?: string, baseUrl?: string): URL; } export {}; //# sourceMappingURL=fetch.d.ts.map