import { ListS3Options, ListS3Response } from '../types/aws-types'; import { Readable } from 'stream'; import { AWSAuth } from '../utils/aws-initialise'; import { AWSApiResponse, SaveToS3Response, LoadFromS3Response, CheckBucketResponse, uploadToS3Response } from '../types'; /** * Lists objects in a bucket, or the names of all buckets, for a specified account. * @param {ListS3Options} [options={ limit: 10 }] - ListS3Options object that contains the bucket name, limit, and other options. * @returns {Promise} - A Promise that resolves to a ListS3Response containing the list of objects or buckets. * @example * const response = await ls({ bucket: 'my-bucket', limit: 5 }); */ export declare const ls: (options?: ListS3Options) => Promise; /** * Generates a unique S3 bucket name that conforms to AWS specs and is valid. * @param {string} [prefix] - Optional prefix to add to the bucket name. The prefix is sanitized to only include alphanumeric characters and hyphens. * @returns {string} - A unique S3 bucket name. * @example * const bucketName = generateBucketName('my-prefix'); */ export declare const generateBucketName: (prefix?: string) => string; /** * Creates an S3 bucket for the given bucket name. * * @param {string} bucketName - The name of the S3 bucket to create. * @param {AWSAuth} [auth={}] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain. * @returns {Promise} - A Promise that resolves with an AWSApiResponse object. * @example * const response = await createS3('my-new-bucket'); */ export declare const createS3: (bucketName: string, auth?: AWSAuth | null) => Promise; /** * Uploads a file or directory to an S3 bucket. * @param {string} bucketName - The name of the S3 bucket to upload to. * @param {string} sourcePath - The path to the file or directory to upload. Must start with an allowed path (configurable via LUMIC_ALLOWED_UPLOAD_PATHS environment variable, defaults to '/tmp'). Path traversal (..) is not allowed. * @param {Object} [options] - Optional parameters. * @param {string} [options.destinationPath] - The path to the destination in the S3 bucket. * @param {AWSAuth} [options.auth] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain. * @param {boolean} [options.isPublic] - Whether the uploaded file should be publicly accessible. Defaults to false. * @returns {Promise} - A Promise that resolves with an uploadToS3Response object. * @example * const response = await uploadToS3('my-bucket', '/tmp/my-file.txt', { isPublic: true }); */ export declare const uploadToS3: (bucketName: string, sourcePath: string, options?: { destinationPath?: string; auth?: AWSAuth | null; isPublic?: boolean; }) => Promise; /** * Reads a file from S3 as a readable stream. * @param {string} bucket - The name of the S3 bucket to read from. * @param {string} key - The key of the object to read from the bucket. * @param {AWSAuth} [auth] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain. * @returns {Promise} - A Promise that resolves with a Readable stream. * @example * const stream = await readS3File('my-bucket', 'path/to/my-file.txt'); */ export declare function readS3File(bucket: string, key: string, auth?: AWSAuth | null): Promise; /** * Downloads files from S3 to a local directory. * @param {string} bucketName - The name of the S3 bucket to download from. * @param {string} [s3Path=''] - The path in the S3 bucket to start downloading from. Defaults to the root of the bucket. * @param {string} [localPath] - The local directory to download the files to. Defaults to os.tmpdir(). * @param {AWSAuth} [auth] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain. * @returns {Promise} - A Promise that resolves with an AWSApiResponse object. * @example * const response = await downloadFromS3('my-bucket', 'path/to/files', '/local/path'); */ export declare const downloadFromS3: (bucketName: string, s3Path?: string, localPath?: string, auth?: AWSAuth | null) => Promise; /** * Deletes a file from an S3 bucket given its URL. * @param {string} s3FileUrl - The URL of the file to delete, e.g. https://my-bucket.s3.amazonaws.com/path/to/file.txt * @param {AWSAuth} [auth] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain. * @returns {Promise} - A Promise that resolves with a boolean indicating whether the file was successfully deleted (true) or not (false). * @example * const success = await deleteS3FileFromUrl('https://my-bucket.s3.amazonaws.com/path/to/file.txt'); */ export declare function deleteS3FileFromUrl(s3FileUrl: string, auth?: AWSAuth | null): Promise; /** * Destroys an S3 bucket, deleting all its contents before deleting the bucket. * @param {string} bucketName - The name of the S3 bucket to destroy. * @param {AWSAuth} [auth] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain. * @returns {Promise} - A Promise that resolves with an AWSApiResponse object. * @example * const response = await destroyS3('my-bucket'); */ export declare const destroyS3: (bucketName: string, auth?: AWSAuth | null) => Promise; /** * Saves a string or an object to an S3 bucket as a file. * @param {string} bucket - The name of the S3 bucket to save the file to. * @param {string | object} content - The content to save to S3. * @param {string} [filename=temp.txt] - The filename to use when saving the content to S3. Defaults to 'temp.txt'. * @param {AWSAuth} [auth=null] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain. * @param {boolean} [isPublic=false] - Whether to make the saved file publicly accessible. Defaults to false. * @returns {Promise} - A Promise that resolves with a SaveToS3Response object. * @example * const response = await saveToS3('my-bucket', { key: 'value' }, 'my-file.json'); */ export declare const saveToS3: (bucket: string, content: string | object, filename?: string, auth?: AWSAuth | null, isPublic?: boolean) => Promise; /** * Loads a file from an S3 bucket and returns its content as a string or parsed JSON. * @param {string} bucketName - The name of the S3 bucket to read from. * @param {string} s3Key - The key of the object to read from the bucket. * @param {AWSAuth} [auth=null] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain. * @returns {Promise} - A Promise that resolves with an object containing the loaded content and a success flag. If the content is valid JSON, it is parsed and returned as an object. If not, it is returned as a string. * @example * const response = await loadFromS3('my-bucket', 'path/to/my-file.json'); */ export declare const loadFromS3: (bucketName: string, s3Key: string, auth?: AWSAuth | null) => Promise; /** * Searches for files in a bucket that contain a given string. * @param {string} bucketName - The name of the S3 bucket to search in. * @param {string} fileNamePart - The string to search for in the file names. * @param {AWSAuth} [auth=null] - Optional AWS credentials to use for the operation. If not provided, the AWS SDK will use the default credential provider chain. * @returns {Promise} - A Promise that resolves with a CheckBucketResponse object containing a flag indicating if a file was found, the file name of the first matching file, and the last modified date of that file. * @example * const response = await checkBucketForFileNamePart('my-bucket', 'report'); */ export declare const checkBucketForFileNamePart: (bucketName: string, fileNamePart: string, auth?: AWSAuth | null) => Promise;