huggingface-chat
Version:
An api for hugging face chat.
85 lines • 3.34 kB
TypeScript
import { AxiosResponse } from 'axios';
/**
* Login class for managing authentication and user sessions.
*/
export default class Login {
private email;
private password;
private headers;
private client;
private cookies;
/**
* Constructs a new instance of the Login class.
* @param {string} email - huggingface email address.
* @param {string} password - huggingface password.
*/
constructor(email: string, password: string);
/**
* Parses cookies into a formatted string.
* @returns {string} A formatted string containing parsed cookies.
*/
private parseCookies;
/**
* Sends an HTTP GET request.
* @param {string} url - The URL to send the GET request to.
* @param { Record<string, any>} _parms - Optional query parameters for the request.
* @returns {Promise<AxiosResponse>} A Promise that resolves to the HTTP response.
*/
get(url: string, _parms?: Record<string, any>): Promise<AxiosResponse>;
/**
* Sends an HTTP POST request.
* @param {string} url - The URL to send the POST request to.
* @param { Record<string, any>} data - Data to include in the request body.
* @param { Record<string, any>} _headers - Optional additional headers for the request.
* @returns {Promise<AxiosResponse>} A Promise that resolves to the HTTP response.
*/
post(url: string, data?: Record<string, any>, _headers?: Record<string, any>): Promise<AxiosResponse>;
/**
* Refreshes cookies based on the response headers.
* @param {AxiosResponse} response - The HTTP response to extract cookies from.
*/
private refreshCookies;
/**
* Attempts to sign in with the provided email and password.
* @throws {Error} If the sign-in fails.
*/
private signinWithEmail;
/**
* Retrieves the authentication URL for a chat.
* @returns {Promise<string>} A Promise that resolves to the authentication URL.
* @throws {Error} If the URL retrieval fails.
*/
private getAuthUrl;
/**
* Extracts CSRF token from a string.
* @param {string} input - The input string containing CSRF information.
* @returns {string | null} The extracted CSRF token or null if not found.
*/
private getCrpf;
/**
* Grants authorization by following redirects.
* @param {string} url - The URL to grant authorization for.
* @returns {Promise<number>} A Promise that resolves to a status code.
* @throws {Error} If the authorization process fails.
*/
private grantAuth;
/**
* Initiates the login process.
* @param {string} cache_path - Optional path for caching login data.
* @returns {Promise<string>} A Promise that resolves to the parsed cookies.
* @throws {Error} If the login process fails.
*/
login(cache_path?: string, force?: boolean): Promise<string>;
/**
* Caches login data to a file.
* @param {string} path - The path where login data will be cached.
*/
private cacheLogin;
/**
* Loads cached login data from a file.
* @param {string} path - The path to the cached login data file.
* @returns {Promise<string>} A Promise that resolves to the cached login data.
*/
loadLoginCache(path: string): Promise<string>;
}
//# sourceMappingURL=login.d.ts.map