UNPKG

reduct-js

Version:

ReductStore Client SDK for Javascript/NodeJS/Typescript

125 lines (124 loc) 3.9 kB
/** * Represents HTTP Client for ReductStore API * @class */ import { ServerInfo } from "./messages/ServerInfo"; import { BucketInfo } from "./messages/BucketInfo"; import { BucketSettings } from "./messages/BucketSettings"; import { Bucket } from "./Bucket"; import { Token, TokenPermissions } from "./messages/Token"; import { FullReplicationInfo, ReplicationInfo } from "./messages/ReplicationInfo"; import { ReplicationSettings } from "./messages/ReplicationSettings"; /** * Options */ export type ClientOptions = { apiToken?: string; timeout?: number; verifySSL?: boolean; }; export declare class Client { private readonly httpClient; /** * HTTP Client for ReductStore * @param url URL to the storage * @param options */ constructor(url: string, options?: ClientOptions); /** * Get server information * @async * @return {Promise<ServerInfo>} the data about the server */ getInfo(): Promise<ServerInfo>; /** * Get list of buckets * @async * @return {BucketInfo[]} * @see BucketInfo */ getBucketList(): Promise<BucketInfo[]>; /** * Create a new bucket * @param name name of the bucket * @param settings optional settings * @return {Promise<Bucket>} */ createBucket(name: string, settings?: BucketSettings): Promise<Bucket>; /** * Get a bucket by name * @param name name of the bucket * @return {Promise<Bucket>} */ getBucket(name: string): Promise<Bucket>; /** * Try to create a bucket and get it if it already exists * @param name name of the bucket * @param settings optional settings * @return {Promise<Bucket>} */ getOrCreateBucket(name: string, settings?: BucketSettings): Promise<Bucket>; /** * Create a new access token * @param name name of the token * @param permissions permissions for the token * @return {Promise<string>} the token * * @example * const token = await client.createToken("my-token", {fullAccess: true}); * const client = new Client("https://play.storage-reduct.dev", {apiToken: token}); */ createToken(name: string, permissions: TokenPermissions): Promise<string>; /** * Get a token by name * @param name name of the token * @return {Promise<Token>} the token */ getToken(name: string): Promise<Token>; /** * List all tokens * @return {Promise<Token[]>} the list of tokens */ getTokenList(): Promise<Token[]>; /** * Delete a token by name * @param name name of the token */ deleteToken(name: string): Promise<void>; /** * Get current API token and its permissions * @return {Promise<Token>} the token */ me(): Promise<Token>; /** * Get the list of replications * @return {Promise<ReplicationInfo[]>} the list of replications */ getReplicationList(): Promise<ReplicationInfo[]>; /** * Get full information about a replication * @param name name of the replication * @return {Promise<FullReplicationInfo>} the replication */ getReplication(name: string): Promise<FullReplicationInfo>; /** * Create a new replication * @param name name of the replication * @param settings settings of the replication * @return {Promise<void>} */ createReplication(name: string, settings: ReplicationSettings): Promise<void>; /** * Update a replication * @param name name of the replication * @param settings settings of the replication * @return {Promise<void>} */ updateReplication(name: string, settings: ReplicationSettings): Promise<void>; /** * Delete a replication * @param name name of the replication * @return {Promise<void>} */ deleteReplication(name: string): Promise<void>; }