wikitree-js
Version:
Javascript library for the WikiTree API
103 lines (102 loc) • 4.27 kB
TypeScript
import { BioFormat, ClientLoginResponse, Person, PersonField, WikiTreeRequest } from './wikitree_types';
/** Wraps an error returned from the WikiTree API. */
export declare class WikiTreeError extends Error {
constructor(message: string);
}
export interface WikiTreeAuthentication {
cookies: string;
}
/** Additional API options common to all requests. */
export interface ApiOptions {
/** Authentication credentials as returned by the login() function. */
auth?: WikiTreeAuthentication;
/** Alternative API URL. */
apiUrl?: string;
/** Application id used for statistical purposes. */
appId?: string;
}
/** Sends a request to the WikiTree API. Returns the raw response. */
export declare function fetchWikiTree(request: WikiTreeRequest, options?: ApiOptions): Promise<Response>;
/** Sends a request to the WikiTree API. Returns the parsed response JSON. */
export declare function wikiTreeGet(request: WikiTreeRequest, options?: ApiOptions): Promise<any>;
/** Optional arguments for the GetPerson API call. */
export interface GetPersonArgs {
bioFormat?: BioFormat;
fields?: Array<PersonField> | '*';
resolveRedirect?: boolean;
}
/**
* Retrieves a single person record from WikiTree.
*
* See also: https://github.com/wikitree/wikitree-api/blob/main/getPerson.md
*/
export declare function getPerson(key: string, args?: GetPersonArgs, options?: ApiOptions): Promise<Person>;
/** Optional arguments for the GetAncestors API call. */
interface GetAncestorsArgs {
depth?: number;
bioFormat?: BioFormat;
fields?: Array<PersonField> | '*';
resolveRedirect?: boolean;
}
/**
* Retrieves ancestors from WikiTree for the given person ID.
*
* See also: https://github.com/wikitree/wikitree-api/blob/main/getAncestors.md
*/
export declare function getAncestors(key: string, args?: GetAncestorsArgs, options?: ApiOptions): Promise<Person[]>;
/** Optional arguments for the GetRelatives API call. */
export interface GetRelativesArgs {
getParents?: boolean;
getChildren?: boolean;
getSpouses?: boolean;
getSiblings?: boolean;
bioFormat?: BioFormat;
fields?: Array<PersonField> | '*';
}
/** Optional arguments for the GetDescendants API call. */
interface GetDescendantsArgs {
depth?: number;
bioFormat?: BioFormat;
fields?: Array<PersonField> | '*';
resolveRedirect?: boolean;
}
/**
* Retrieves descendants from WikiTree for the given person ID.
*
* See also: https://github.com/wikitree/wikitree-api/blob/main/getDescendants.md
*/
export declare function getDescendants(key: string, args?: GetDescendantsArgs, options?: ApiOptions): Promise<Person[]>;
/**
* Retrieves relatives from WikiTree for the given array of person IDs.
* If a key does not exist or is inaccessible, it is omitted in the result.
*
* See also: https://github.com/wikitree/wikitree-api/blob/main/getRelatives.md
*/
export declare function getRelatives(keys: string[], args?: GetRelativesArgs, options?: ApiOptions): Promise<Person[]>;
/**
* Returns the logged in user name or undefined if not logged in.
*
* In the browser, call this function without arguments.
* This is not an authoritative answer. The result of this function relies on
* the cookies set on the apps.wikitree.com domain under which this application
* is hosted. The authoritative source of login information is in cookies set on
* the api.wikitree.com domain.
*
* In Node.js, call this function with the auth parameter. This is an
* authoritative answer because the login flow is under control of the
* wikitree-js library.
*/
export declare function getLoggedInUserName(auth?: WikiTreeAuthentication): string | undefined;
/**
* Navigates to WikiTree login screen at https://api.wikitree.com/api.php with
* the specified return URL.
*/
export declare function navigateToLoginPage(returnUrl: string): void;
export declare function clientLogin(authcode: string, options?: ApiOptions): Promise<ClientLoginResponse>;
/**
* Logs in to WikiTree returning authentication credentials.
* This function will not work in the browser because it handles cookies directly.
* Throws an exception if login fails.
*/
export declare function login(email: string, password: string): Promise<WikiTreeAuthentication>;
export {};