UNPKG

moeralib

Version:

Library to interact with Moera decentralized social network

183 lines 5.41 kB
/// <reference types="node" /> import { Result } from "./types"; /** * Generic node error. */ export declare class MoeraNodeError extends Error { /** * @param {string} name - request name * @param {string} message - error message */ constructor(name: string, message: string); } /** * Node returned an error response. */ export declare class MoeraNodeApiError extends MoeraNodeError { /** * Error code. */ errorCode: string; /** * @param {string} name - request name * @param {Result} result - node response */ constructor(name: string, result: Result); } /** * Error while connecting the node. */ export declare class MoeraNodeConnectionError extends Error { /** * @param {string} message - error message */ constructor(message: string); } /** * Missing context of the call (authentication parameters or node URL). */ export declare class MoeraNodeCallError extends Error { /** * @param {string} message - error message */ constructor(message: string); } type Structure = Partial<Record<string, any>>; /** * Authentication type. * * "none" - No authentication.\ * "peer" - Carte authentication.\ * "admin" - Admin token authentication.\ * "root-admin" - Root admin secret authentication. */ export type NodeAuth = "none" | "peer" | "admin" | "root-admin"; export interface CarteSource { getCarte: () => Promise<string>; } /** * Convert partial node URL to a standardized form. * * @param {string} url - partial URL * @return {string} standard URL */ export declare function moeraRoot(url: string): string; /** * Parameters of a node API request. */ interface CallOptions { /** * Query parameters, mapping name to value, ``null`` values are skipped */ params?: Partial<Record<string, string | number | boolean | null>> | null; /** * Request method (one of 'GET', 'POST', 'PUT', 'DELETE'), the default is 'GET' */ method: string; /** * Request body */ body?: Structure | Structure[] | Buffer | null; /** * Content-Type of the request body, when it is not a JSON structure */ contentType?: string | null; /** * `true` (default) to authenticate the request, `false` otherwise */ auth?: boolean; /** * JSON schema name to validate the response, or ``"blob"`` if the result is ``Buffer`` */ schema: string; /** * `true` to decode `Body` structures in the response, `false` (default) otherwise */ bodies?: boolean; /** * `true` to encode `Body` structures in the request, `false` (default) otherwise */ srcBodies?: boolean; } export declare class Caller { /** * API endpoint URL of the node. */ root: string | null; private _rootSecret; private _token; private _carte; private _carteSource; private _authMethod; /** * Set node URL. * * @param {string} url */ nodeUrl(url: string): void; /** * Set root secret for authentication. * * @param {string} secret */ rootSecret(secret: string): void; /** * Set admin token for authentication. * * @param {string} token */ token(token: string): void; /** * Set carte for authentication. * * @param {string} carte */ carte(carte: string): void; /** * Set a source of cartes for authentication. * * @param {CarteSource} carteSource */ carteSource(carteSource: CarteSource): void; /** * Select authentication method for the following requests. * * @param {NodeAuth} authMethod */ authMethod(authMethod: NodeAuth): void; /** * Switch off authentication for the following requests. */ noAuth(): void; /** * Select carte authentication for the following requests. */ auth(): void; /** * Select admin token authentication for the following requests. */ authAdmin(): void; /** * Select root admin secret authentication for the following requests. */ authRootAdmin(): void; /** * Generic method for making node API requests. * * @param {string} name - request name (for error messages) * @param {string} location - request path * @param {Partial<Record<string, string | number | boolean | null>> | null} params - query parameters, mapping * name to value, ``null`` values are skipped * @param {string} method - request method (one of 'GET', 'POST', 'PUT', 'DELETE'), the default is 'GET' * @param {Structure | Structure[] | Buffer | null} body - request body * @param {string | null} contentType - content-type of the request body, when it is not a JSON structure * @param {boolean} auth - `true` (default) to authenticate the request, `false` otherwise * @param {string} schema - JSON schema to validate the response * @param {boolean} bodies - `true` to decode `Body` structures in the response, `false` (default) otherwise * @param {boolean} srcBodies - `true` to encode `Body` structures in the request, `false` (default) otherwise * @return {Promise<any>} */ call(name: string, location: string, { params, method, body, contentType, auth, schema, bodies, srcBodies }: CallOptions): Promise<any>; } export {}; //# sourceMappingURL=caller.d.ts.map