UNPKG

node-cloudflare-r2

Version:
55 lines (54 loc) 2.03 kB
import { S3Client, type S3ClientConfig } from '@aws-sdk/client-s3'; import { Bucket } from './Bucket'; import type { BucketList, CORSPolicy, CloudflareR2Config } from './types'; export declare class R2 { private readonly config; private readonly r2; readonly endpoint: S3ClientConfig['endpoint']; constructor(config: CloudflareR2Config, overrides?: S3ClientConfig); /** * Returns the S3 client instance. Should be used as a last resort if you need extra custom functionality. * @note It is recommended to use other provided methods for specific operations instead of directly accessing the client. */ __unsafe_getClient(): S3Client; /** * Returns a `Bucket` object that represents the specified storage bucket. * @param bucketName The name of the storage bucket. * @returns A `Bucket` object that represents the specified storage bucket. */ bucket(bucketName: string): Bucket; /** * Returns a list of all buckets owned by the authenticated sender of the request. * @async */ listBuckets(): Promise<BucketList>; /** * Determines if a bucket exists and you have permission to access it. * @async * @param bucketName */ bucketExists(bucketName: string): Promise<boolean>; /** * Create a new R2 bucket and returns `Bucket` object. * @async * @param bucketName */ createBucket(bucketName: string): Promise<Bucket>; /** * Delete an existing bucket. Returns true if success or throws error if fail. * @async * @param bucketName */ deleteBucket(bucketName: string): Promise<boolean>; /** * Returns Cross-Origin Resource Sharing (CORS) policies of the bucket. * @async */ getBucketCors(bucketName: string): Promise<CORSPolicy[]>; /** * Returns the region the bucket resides in. For `Cloudflare R2`, the region is always `auto`. * @async * @param bucketName */ getBucketRegion(bucketName: string): Promise<string>; }