Bucket operations provide comprehensive management of OSS buckets including creation, configuration, access control, and advanced features like lifecycle management, CORS, encryption, and compliance settings.
async function listBuckets(query?: ListBucketsQuery, options?: RequestOptions): Promise<ListBucketsResult>;
interface ListBucketsQuery {
prefix?: string;
marker?: string;
'max-keys'?: number;
}
interface ListBucketsResult {
buckets: BucketInfo[];
owner: Owner;
isTruncated: boolean;
nextMarker?: string;
}
interface BucketInfo {
name: string;
region: string;
creationDate: Date;
storageClass?: string;
}function useBucket(name: string): void;
function setBucket(name: string): void;
function getBucket(): string;
async function getBucketInfo(name: string, options?: RequestOptions): Promise<BucketInfoResult>;
async function getBucketLocation(name: string, options?: RequestOptions): Promise<BucketLocationResult>;
async function getBucketStat(name: string, options?: RequestOptions): Promise<BucketStatResult>;
interface BucketInfoResult {
bucket: {
name: string;
region: string;
creationDate: Date;
extranetEndpoint: string;
intranetEndpoint: string;
acl: string;
dataRedundancyType: string;
storageClass: string;
};
}
interface BucketStatResult {
size: number;
objectCount: number;
multipartUploadCount: number;
liveChannelCount: number;
lastModifiedTime: Date;
standardStorage: number;
standardObjectCount: number;
infrequentAccessStorage: number;
infrequentAccessObjectCount: number;
archiveStorage: number;
archiveObjectCount: number;
coldArchiveStorage: number;
coldArchiveObjectCount: number;
}async function putBucket(name: string, options?: CreateBucketOptions): Promise<PutBucketResult>;
interface CreateBucketOptions extends RequestOptions {
storageClass?: 'Standard' | 'IA' | 'Archive' | 'ColdArchive';
dataRedundancyType?: 'LRS' | 'ZRS';
acl?: 'private' | 'public-read' | 'public-read-write';
region?: string;
}
interface PutBucketResult {
bucket: string;
location: string;
status: number;
headers: Record<string, string>;
}async function deleteBucket(name: string, options?: RequestOptions): Promise<DeleteBucketResult>;
interface DeleteBucketResult {
status: number;
headers: Record<string, string>;
}async function putBucketACL(name: string, acl: string, options?: RequestOptions): Promise<PutBucketACLResult>;
async function getBucketACL(name: string, options?: RequestOptions): Promise<GetBucketACLResult>;
interface GetBucketACLResult {
acl: string;
owner: Owner;
grants?: Grant[];
}
interface Owner {
id: string;
displayName: string;
}
interface Grant {
grantee: Grantee;
permission: string;
}Valid ACL values:
'private' - Only owner has full control'public-read' - Owner has full control, everyone else has read access'public-read-write' - Everyone has read and write accessasync function putBucketLogging(name: string, prefix: string, options?: RequestOptions): Promise<PutBucketLoggingResult>;
async function getBucketLogging(name: string, options?: RequestOptions): Promise<GetBucketLoggingResult>;
async function deleteBucketLogging(name: string, options?: RequestOptions): Promise<DeleteBucketLoggingResult>;
interface GetBucketLoggingResult {
enable: boolean;
prefix?: string;
targetBucket?: string;
}// Enable logging
await client.putBucketLogging('my-bucket', 'access-logs/');
// Get logging configuration
const logging = await client.getBucketLogging('my-bucket');
console.log('Logging enabled:', logging.enable);
// Disable logging
await client.deleteBucketLogging('my-bucket');async function putBucketCORS(name: string, rules: CORSRule[], options?: RequestOptions): Promise<PutBucketCORSResult>;
async function getBucketCORS(name: string, options?: RequestOptions): Promise<GetBucketCORSResult>;
async function deleteBucketCORS(name: string, options?: RequestOptions): Promise<DeleteBucketCORSResult>;
interface CORSRule {
allowedOrigin: string | string[];
allowedMethod: string | string[];
allowedHeader?: string | string[];
exposeHeader?: string | string[];
maxAgeSeconds?: number;
}
interface GetBucketCORSResult {
rules: CORSRule[];
}// Configure CORS
const corsRules = [{
allowedOrigin: ['http://localhost:3000', 'https://example.com'],
allowedMethod: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeader: ['*'],
exposeHeader: ['ETag', 'x-oss-request-id'],
maxAgeSeconds: 3600
}];
await client.putBucketCORS('my-bucket', corsRules);async function putBucketReferer(name: string, allowEmpty: boolean, referers: string[], options?: RequestOptions): Promise<PutBucketRefererResult>;
async function getBucketReferer(name: string, options?: RequestOptions): Promise<GetBucketRefererResult>;
async function deleteBucketReferer(name: string, options?: RequestOptions): Promise<DeleteBucketRefererResult>;
interface GetBucketRefererResult {
allowEmpty: boolean;
referers: string[];
}async function putBucketLifecycle(name: string, rules: LifecycleRule[], options?: RequestOptions): Promise<PutBucketLifecycleResult>;
async function getBucketLifecycle(name: string, options?: RequestOptions): Promise<GetBucketLifecycleResult>;
async function deleteBucketLifecycle(name: string, options?: RequestOptions): Promise<DeleteBucketLifecycleResult>;
interface LifecycleRule {
id: string;
prefix?: string;
status: 'Enabled' | 'Disabled';
days?: number;
date?: string;
expiredObjectDeleteMarker?: boolean;
abortMultipartUpload?: {
days?: number;
createdBeforeDate?: string;
};
transition?: LifecycleTransition[];
}
interface LifecycleTransition {
days?: number;
date?: string;
storageClass: 'IA' | 'Archive' | 'ColdArchive';
}async function putBucketWebsite(name: string, config: WebsiteConfig, options?: RequestOptions): Promise<PutBucketWebsiteResult>;
async function getBucketWebsite(name: string, options?: RequestOptions): Promise<GetBucketWebsiteResult>;
async function deleteBucketWebsite(name: string, options?: RequestOptions): Promise<DeleteBucketWebsiteResult>;
interface WebsiteConfig {
index: string;
error?: string;
supportSubDir?: boolean;
type?: number;
routingRules?: RoutingRule[];
}
interface RoutingRule {
condition?: RoutingCondition;
redirect: RoutingRedirect;
}async function putBucketEncryption(name: string, config: EncryptionConfig, options?: RequestOptions): Promise<PutBucketEncryptionResult>;
async function getBucketEncryption(name: string, options?: RequestOptions): Promise<GetBucketEncryptionResult>;
async function deleteBucketEncryption(name: string, options?: RequestOptions): Promise<DeleteBucketEncryptionResult>;
interface EncryptionConfig {
sseAlgorithm: 'KMS' | 'AES256';
kmsMasterKeyID?: string;
}async function putBucketVersioning(name: string, status: 'Enabled' | 'Suspended', options?: RequestOptions): Promise<PutBucketVersioningResult>;
async function getBucketVersioning(name: string, options?: RequestOptions): Promise<GetBucketVersioningResult>;
interface GetBucketVersioningResult {
status: 'Enabled' | 'Suspended' | 'Disabled';
}async function putBucketRequestPayment(name: string, payer: 'BucketOwner' | 'Requester', options?: RequestOptions): Promise<PutBucketRequestPaymentResult>;
async function getBucketRequestPayment(name: string, options?: RequestOptions): Promise<GetBucketRequestPaymentResult>;
interface GetBucketRequestPaymentResult {
payer: 'BucketOwner' | 'Requester';
}async function putBucketPolicy(name: string, policy: PolicyDocument, options?: RequestOptions): Promise<PutBucketPolicyResult>;
async function getBucketPolicy(name: string, options?: RequestOptions): Promise<GetBucketPolicyResult>;
async function deleteBucketPolicy(name: string, options?: RequestOptions): Promise<DeleteBucketPolicyResult>;
interface PolicyDocument {
Version: string;
Statement: PolicyStatement[];
}
interface PolicyStatement {
Sid?: string;
Effect: 'Allow' | 'Deny';
Principal?: string | string[] | { [key: string]: string | string[] };
Action: string | string[];
Resource: string | string[];
Condition?: { [key: string]: { [key: string]: string | string[] } };
}async function putBucketTags(name: string, tags: BucketTag[], options?: RequestOptions): Promise<PutBucketTagsResult>;
async function getBucketTags(name: string, options?: RequestOptions): Promise<GetBucketTagsResult>;
async function deleteBucketTags(name: string, options?: RequestOptions): Promise<DeleteBucketTagsResult>;
interface BucketTag {
key: string;
value: string;
}
interface GetBucketTagsResult {
tags: BucketTag[];
}async function putBucketInventory(name: string, inventory: InventoryConfig, options?: RequestOptions): Promise<PutBucketInventoryResult>;
async function getBucketInventory(name: string, inventoryId: string, options?: RequestOptions): Promise<GetBucketInventoryResult>;
async function deleteBucketInventory(name: string, inventoryId: string, options?: RequestOptions): Promise<DeleteBucketInventoryResult>;
async function listBucketInventory(name: string, options?: RequestOptions): Promise<ListBucketInventoryResult>;
interface InventoryConfig {
id: string;
isEnabled: boolean;
filter?: InventoryFilter;
destination: InventoryDestination;
schedule: InventorySchedule;
includedObjectVersions: 'All' | 'Current';
optionalFields?: string[];
}async function initiateBucketWorm(name: string, days: number, options?: RequestOptions): Promise<InitiateBucketWormResult>;
async function abortBucketWorm(name: string, options?: RequestOptions): Promise<AbortBucketWormResult>;
async function completeBucketWorm(name: string, options?: RequestOptions): Promise<CompleteBucketWormResult>;
async function extendBucketWorm(name: string, days: number, options?: RequestOptions): Promise<ExtendBucketWormResult>;
async function getBucketWorm(name: string, options?: RequestOptions): Promise<GetBucketWormResult>;
interface GetBucketWormResult {
wormId: string;
state: 'InProgress' | 'Locked';
retentionPeriodInDays: number;
creationDate: Date;
}interface RequestOptions {
timeout?: number | number[];
headers?: Record<string, string>;
ctx?: any;
}interface BasicResult {
status: number;
headers: Record<string, string>;
size?: number;
rt?: number;
}
// Most operations return BasicResult or extend it with additional properties
type PutBucketACLResult = BasicResult;
type DeleteBucketResult = BasicResult;
type PutBucketLoggingResult = BasicResult;
// ... etc