/// import { ListResults, PutObjectOptions, StorageProvider } from '@smcloudstore/core/dist/StorageProvider'; import * as Azure from 'azure-storage'; import { Stream } from 'stream'; /** * Connection options for an Azure Blob Storage provider. */ interface AzureStorageConnectionObject { /** Name of the storage account */ storageAccount: string; /** Access key (secret key) for the storage account */ storageAccessKey: string; /** Endpoint to use. Default is `core.windows.net` */ host?: string; } declare type AzureStorageConnectionOptions = string | AzureStorageConnectionObject; /** * Options passed when creating a container */ interface AzureStorageCreateContainerOptions { /** * Determine access level for all files in the container. Defaults to 'none' if not specified. * 'public' and 'private' are not standard in the Azure APIs, and are aliased to 'container' and 'none' respectively. */ access?: 'blob' | 'container' | 'none' | 'public' | 'private'; } /** * Client to interact with Azure Blob Storage. */ declare class AzureStorageProvider extends StorageProvider { protected _client: Azure.BlobService; /** * Initializes a new client to interact with Azure Blob Storage. * * @param connection - Connection options, passed as an object with interface `AzureStorageConnectionObject`, or as a connection string (e.g. as returned from the Azure Portal) */ constructor(connection: AzureStorageConnectionOptions); /** * Create a container on the server. * * @param container - Name of the container * @param options - Dictionary with options for creating the container, including the access level (defaults to 'none' if not specified) * @returns Promise that resolves once the container has been created. The promise doesn't contain any meaningful return value. * @async */ createContainer(container: string, options?: AzureStorageCreateContainerOptions): Promise; /** * Check if a container exists. * * @param container - Name of the container * @returns Promises that resolves with a boolean indicating if the container exists. * @async */ isContainer(container: string): Promise; /** * Create a container on the server if it doesn't already exist. * * @param container - Name of the container * @param options - Dictionary with options for creating the container, including the access level (defaults to 'none' if not specified) * @returns Promise that resolves once the container has been created * @async */ ensureContainer(container: string, options?: AzureStorageCreateContainerOptions): Promise; /** * Lists all containers belonging to the user * * @returns Promise that resolves with an array of all the containers * @async */ listContainers(): Promise; /** * Removes a container from the server * * @param container - Name of the container * @returns Promise that resolves once the container has been removed * @async */ deleteContainer(container: string): Promise; /** * Uploads a stream to the object storage server * * @param container - Name of the container * @param path - Path where to store the object, inside the container * @param data - Object data or stream. Can be a Stream (Readable Stream), Buffer or string. * @param options - Key-value pair of options used by providers, including the `metadata` dictionary * @returns Promise that resolves once the object has been uploaded * @async */ putObject(container: string, path: string, data: Stream | string | Buffer, options?: PutObjectOptions): Promise; /** * Requests an object from the server. The method returns a Promise that resolves to a Readable Stream containing the data. * * @param container - Name of the container * @param path - Path of the object, inside the container * @returns Readable Stream containing the object's data * @async */ getObject(container: string, path: string): Promise; /** * Returns a list of objects with a given prefix (folder). The list is not recursive, so prefixes (folders) are returned as such. * * @param container - Name of the container * @param prefix - Prefix (folder) inside which to list objects * @returns List of elements returned by the server * @async */ listObjects(container: string, prefix?: string): Promise; /** * Removes an object from the server * * @param container - Name of the container * @param path - Path of the object, inside the container * @returns Promise that resolves once the object has been removed * @async */ deleteObject(container: string, path: string): Promise; /** * Returns a URL that clients (e.g. browsers) can use to request an object from the server with a GET request, even if the object is private. * * @param container - Name of the container * @param path - Path of the object, inside the container * @param ttl - Expiry time of the URL, in seconds (default: 1 day) * @returns Promise that resolves with the pre-signed URL for GET requests * @async */ presignedGetUrl(container: string, path: string, ttl?: number): Promise; /** * Returns a URL that clients (e.g. browsers) can use for PUT operations on an object in the server, even if the object is private. * * Notes on using presigned URLs to upload files to Azure Storage using PUT: * * 1. The maximum file size is 100MB; larger files will trigger an error. * 2. You need to set the `X-MS-Blob-Type: BlockBlob` header for uploads to succeed * * @param container - Name of the container * @param path - Path where to store the object, inside the container * @param options - Key-value pair of options used by providers, including the `metadata` dictionary * @param ttl - Expiry time of the URL, in seconds (default: 1 day) * @returns Promise that resolves with the pre-signed URL for GET requests * @async */ presignedPutUrl(container: string, path: string, options?: PutObjectOptions, ttl?: number): Promise; /** * Returns a presigned URL for the specific operation. * * @param operation - Operation: "getObject" or "putObject" * @param container - Name of the container * @param path - Path of the target object, inside the container * @param contentSettings - Additional headers that are required * @param ttl - Expiry time of the URL, in seconds (default: 1 day) * @returns Promise that resolves with the pre-signed URL for the specified operation * @async */ private presignedUrl; /** * Create a container on the server, choosing whether to use the "ifNotExists" method or not * @param container - Name of the container * @param ifNotExists - If true, use the "ifNotExists" method variant * @param options - Dictionary with options for creating the container, including the access level (defaults to 'none' if not specified) * @returns Promise that resolves once the container has been created. The promise doesn't contain any meaningful return value. * @async */ private _createContainerInternal; } export = AzureStorageProvider;