UNPKG

node-cloudflare-r2

Version:
50 lines (49 loc) 1.73 kB
import { 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 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>; }