/// import type { Response } from 'got'; import * as strm from 'stream'; export declare type ContainerType = 'public' | 'private' | 'gallery'; declare type KnownPools = 'ru-1' | 'ru-2' | 'ru-3' | 'ru-7' | 'ru-8' | 'ru-9' | 'gis-1'; declare type Pool = KnownPools | Omit; export interface FileObject { bytes: number; content_type: string; hash: string; last_modified: string; name: string; } interface RequiredParams { container: string; } export interface Options { accountId: string; username: string; password: string; token?: string; projectId: string; projectName: string; /** * Servers location pool * @default ru-1 * @see https://docs.selectel.ru/control-panel-actions/infrastructure/#selectel-infrastructure */ pool?: Pool; } export interface CreateContainerParams extends RequiredParams { type?: ContainerType; metadata?: string; } export interface GetFilesParams extends RequiredParams { limit?: number; marker?: string; prefix?: string; delimiter?: string; format?: 'json' | 'xml'; } export interface UploadFileParams extends RequiredParams { /** * File's buffer or local path */ file: Buffer | strm.Stream | string; /** * In case when archive are passed, filename can be omitted. * In that case all archived files will be extracted within * container root, or it could be used as a folder name */ fileName?: string; deleteAt?: number; lifetime?: number; etag?: string; metadata?: string; archive?: 'tar' | 'tar.gz' | 'gzip'; } export interface DeleteFilesParams extends RequiredParams { /** * Files names */ files: string[]; } export interface DeleteFileParams extends RequiredParams { file: string; } export interface AuthorizeReturn { expire?: string | number; token?: string; } export interface GetContainersData { name: string; count: number; bytes: number; type: ContainerType; /** * Container last modification date */ last_modified: string; } export interface DeleteFilesReturn { 'Number Not Found': number; 'Response Status': string; 'Response Body': string; Errors?: string[]; 'Number Deleted': number; } export declare class SelectelStorageClient { /** * username is a public since it is required from outside when we want to cache * token, and we have several Selectel users in our app */ readonly username: string; private readonly accountId; private readonly password; private readonly storageUrl; private readonly projectId; private readonly projectName; /** * Authorization token */ private token?; private expireAuthToken?; constructor(options: Options); /** * Summary storage information * * @see https://developers.selectel.ru/docs/cloud-services/cloud-storage/storage_swift_api/#%D0%BF%D0%BE%D0%BB%D1%83%D1%87%D0%B8%D1%82%D1%8C-%D0%B8%D0%BD%D1%84%D0%BE%D1%80%D0%BC%D0%B0%D1%86%D0%B8%D1%8E-%D0%BE-%D1%85%D1%80%D0%B0%D0%BD%D0%B8%D0%BB%D0%B8%D1%89%D0%B5 */ getInfo(): Promise>; /** * Request could be of two types: with json and with string * @param {boolean} returnJson * @returns {Promise} */ getContainers(returnJson?: boolean): Promise | Promise>; /** * * @param {string} params.container - new container name * @param {ContainerType} [params.type] - container type * @param {string} [params.metadata] - additional meta data * @returns {Promise} */ createContainer(params: CreateContainerParams): Promise>; /** * Receive container information * @param {string} params.container - Container name * @returns {Promise} */ getContainerInfo(params: RequiredParams): Promise>; /** * Get a list of files data * * @todo: should we return void here too? */ getFiles(params: GetFilesParams): Promise<{ files: string[] | FileObject[]; filesAmount: number; containerSize: number; containerType: ContainerType; }>; /** * Get a file info from headers * @param {string} params.container - Container name * @returns { * Promise<{ * 'content-length': string, * 'content-type': string, * }> * } */ getFileInfo(params: RequiredParams): Promise<{ readonly 'content-length': number; readonly 'content-type': string; }>; /** * Upload single file to Selectel storage * @param {object} params * @param {string} [params.fileName] in case when archive are passed, filename * can be omitted. In that case all archived files will be extracted within * container root, or it could be used as a folder name * @param {Buffer | string} params.file - file's buffer or local path * @returns {Promise} */ uploadFile(params: UploadFileParams): Promise; /** * This method are allowed only for root users. Additional users even with * write permissions should user `deleteFile` method * @param {string} params.container - Container name where you want to delete * files * @param {string[]} params.files - files names * @returns {Promise} */ deleteFiles(params: DeleteFilesParams): Promise; /** * @param {string} params.container * @param {string} params.file * @returns {Promise} statusCode "204" on success */ deleteFile(params: DeleteFileParams): Promise>; /** * Authorize * @returns {Promise<{ expire: string, token: string }>} When you want * to extend class this could be helpful to memorize token. I.e. to redis */ protected authorize(): Promise<{ expire: number; token: any; } | { expire?: undefined; token?: undefined; }>; private authorizationRequest; private makeRequest; } export {};