@tmlmobilidade/interfaces
Version:
This package provides SDK-style connectors for interacting with databases (e.g., stops, plans, rides, alerts) and external providers (e.g., authentication, storage). It simplifies data access and integration across projects.
65 lines (64 loc) • 2.23 kB
TypeScript
import { IStorageProvider } from './storage.interface.js';
import { Readable } from 'node:stream';
export interface S3StorageProviderConfiguration {
access_key_id: string;
bucket_name: string;
endpoint?: string;
region?: string;
secret_access_key: string;
}
export declare class S3StorageProvider implements IStorageProvider {
private readonly bucketName;
private readonly s3Client;
constructor(config: S3StorageProviderConfiguration);
/**
* Checks if the bucket exists and creates it if it doesn't.
*/
checkBucket(): Promise<void>;
/**
* Copies a file from one path to another.
* @param source - The source file path and name in S3.
* @param destination - The destination file path and name in S3.
*/
copyFile(source: string, destination: string): Promise<void>;
/**
* Deletes a file from S3.
* @param key - The file path and name in S3.
*/
deleteFile(key: string): Promise<void>;
/**
* Deletes multiple files from S3.
* @param keys - The file paths and names in S3.
*/
deleteFiles(keys: string[]): Promise<void>;
/**
* Downloads a file from S3.
* @param key - The file path and name in S3.
* @returns The file as a readable stream.
*/
downloadFile(key: string): Promise<Readable>;
/**
* Checks if a file exists in S3.
* @param key - The file path and name in S3.
* @returns True if the file exists, false otherwise.
*/
fileExists(key: string): Promise<boolean>;
/**
* Get the signed URL of a file from the storage.
* @param key - The file path and name in the storage.
* @returns The signed URL of the file.
*/
getFileUrl(key: string): Promise<string>;
/**
* Lists files in an S3 bucket.
* @param prefix - Filter by prefix (optional).
* @returns Array of file keys in the bucket.
*/
listFiles(prefix?: string): Promise<string[]>;
/**
* Uploads a file to S3.
* @param key - The file path and name in S3.
* @param body - The content to upload, either as a string, buffer, or readable stream.
*/
uploadFile(key: string, body: Buffer | Readable | string): Promise<void>;
}