UNPKG

1.98 kBTypeScriptView Raw
1import * as Config from '@oclif/config';
2import { CLIError } from '@oclif/errors';
3import { HTTP, HTTPError, HTTPRequestOptions } from 'http-call';
4import { Login } from './login';
5import { Mutex } from './mutex';
6export declare namespace APIClient {
7 interface Options extends HTTPRequestOptions {
8 retryAuth?: boolean;
9 }
10}
11export interface IOptions {
12 required?: boolean;
13 preauth?: boolean;
14}
15export interface IHerokuAPIErrorOptions {
16 resource?: string;
17 app?: {
18 id: string;
19 name: string;
20 };
21 id?: string;
22 message?: string;
23 url?: string;
24}
25export declare class HerokuAPIError extends CLIError {
26 http: HTTPError;
27 body: IHerokuAPIErrorOptions;
28 constructor(httpError: HTTPError);
29}
30export declare class APIClient {
31 protected config: Config.IConfig;
32 options: IOptions;
33 preauthPromises: {
34 [k: string]: Promise<HTTP<any>>;
35 };
36 authPromise?: Promise<HTTP<any>>;
37 http: typeof HTTP;
38 private readonly _login;
39 private _twoFactorMutex;
40 private _auth?;
41 constructor(config: Config.IConfig, options?: IOptions);
42 get twoFactorMutex(): Mutex<string>;
43 get auth(): string | undefined;
44 set auth(token: string | undefined);
45 twoFactorPrompt(): Promise<string>;
46 preauth(app: string, factor: string): Promise<HTTP<unknown>>;
47 get<T>(url: string, options?: APIClient.Options): Promise<HTTP<T>>;
48 post<T>(url: string, options?: APIClient.Options): Promise<HTTP<T>>;
49 put<T>(url: string, options?: APIClient.Options): Promise<HTTP<T>>;
50 patch<T>(url: string, options?: APIClient.Options): Promise<HTTP<T>>;
51 delete<T>(url: string, options?: APIClient.Options): Promise<HTTP<T>>;
52 stream(url: string, options?: APIClient.Options): Promise<HTTP<unknown>>;
53 request<T>(url: string, options?: APIClient.Options): Promise<HTTP<T>>;
54 login(opts?: Login.Options): Promise<void>;
55 logout(): Promise<void>;
56 get defaults(): typeof HTTP.defaults;
57}