cloudflare
Version:
The official TypeScript library for the Cloudflare API
406 lines (351 loc) • 10.7 kB
text/typescript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../../core/resource';
import { APIPromise } from '../../../core/api-promise';
import { buildHeaders } from '../../../internal/headers';
import { RequestOptions } from '../../../internal/request-options';
import { path } from '../../../internal/utils/path';
export class BaseLifecycle extends APIResource {
static override readonly _key: readonly ['r2', 'buckets', 'lifecycle'] = Object.freeze([
'r2',
'buckets',
'lifecycle',
] as const);
/**
* Replaces the object lifecycle rules for an R2 bucket. Rules match object-key
* prefixes and can expire objects, abort incomplete multipart uploads, or
* transition objects to Infrequent Access storage.
*
* @example
* ```ts
* const lifecycle = await client.r2.buckets.lifecycle.update(
* 'example-bucket',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
update(
bucketName: string,
params: LifecycleUpdateParams,
options?: RequestOptions,
): APIPromise<LifecycleUpdateResponse> {
const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction, ...body } = params;
return (
this._client.put(path`/accounts/${account_id}/r2/buckets/${bucketName}/lifecycle`, {
body,
...options,
headers: buildHeaders([
{
...(cfR2Jurisdiction?.toString() != null ?
{ 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() }
: undefined),
},
options?.headers,
]),
}) as APIPromise<{ result: LifecycleUpdateResponse }>
)._thenUnwrap((obj) => obj.result);
}
/**
* Get object lifecycle rules for a bucket.
*
* @example
* ```ts
* const lifecycle = await client.r2.buckets.lifecycle.get(
* 'example-bucket',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(
bucketName: string,
params: LifecycleGetParams,
options?: RequestOptions,
): APIPromise<LifecycleGetResponse> {
const { account_id, 'cf-r2-jurisdiction': cfR2Jurisdiction } = params;
return (
this._client.get(path`/accounts/${account_id}/r2/buckets/${bucketName}/lifecycle`, {
...options,
headers: buildHeaders([
{
...(cfR2Jurisdiction?.toString() != null ?
{ 'cf-r2-jurisdiction': cfR2Jurisdiction?.toString() }
: undefined),
},
options?.headers,
]),
}) as APIPromise<{ result: LifecycleGetResponse }>
)._thenUnwrap((obj) => obj.result);
}
}
export class Lifecycle extends BaseLifecycle {}
export type LifecycleUpdateResponse = unknown;
export interface LifecycleGetResponse {
rules?: Array<LifecycleGetResponse.Rule>;
}
export namespace LifecycleGetResponse {
export interface Rule {
/**
* Unique identifier for this rule.
*/
id: string;
/**
* Conditions that apply to all transitions of this rule.
*/
conditions: Rule.Conditions;
/**
* Whether or not this rule is in effect.
*/
enabled: boolean;
/**
* Transition to abort ongoing multipart uploads.
*/
abortMultipartUploadsTransition?: Rule.AbortMultipartUploadsTransition;
/**
* Transition to delete objects.
*/
deleteObjectsTransition?: Rule.DeleteObjectsTransition;
/**
* Transitions to change the storage class of objects.
*/
storageClassTransitions?: Array<Rule.StorageClassTransition>;
}
export namespace Rule {
/**
* Conditions that apply to all transitions of this rule.
*/
export interface Conditions {
/**
* Transitions will only apply to objects/uploads in the bucket that start with the
* given prefix, an empty prefix can be provided to scope rule to all
* objects/uploads.
*/
prefix: string;
}
/**
* Transition to abort ongoing multipart uploads.
*/
export interface AbortMultipartUploadsTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
condition?: AbortMultipartUploadsTransition.Condition;
}
export namespace AbortMultipartUploadsTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
export interface Condition {
maxAge: number;
type: 'Age';
}
}
/**
* Transition to delete objects.
*/
export interface DeleteObjectsTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
condition?:
| DeleteObjectsTransition.R2LifecycleAgeCondition
| DeleteObjectsTransition.R2LifecycleDateCondition;
}
export namespace DeleteObjectsTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
export interface R2LifecycleAgeCondition {
maxAge: number;
type: 'Age';
}
/**
* Condition for lifecycle transitions to apply on a specific date.
*/
export interface R2LifecycleDateCondition {
date: string;
type: 'Date';
}
}
export interface StorageClassTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
condition:
| StorageClassTransition.R2LifecycleAgeCondition
| StorageClassTransition.R2LifecycleDateCondition;
storageClass: 'InfrequentAccess';
}
export namespace StorageClassTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
export interface R2LifecycleAgeCondition {
maxAge: number;
type: 'Age';
}
/**
* Condition for lifecycle transitions to apply on a specific date.
*/
export interface R2LifecycleDateCondition {
date: string;
type: 'Date';
}
}
}
}
export interface LifecycleUpdateParams {
/**
* Path param: Cloudflare account ID that owns the R2 resource.
*/
account_id: string;
/**
* Body param
*/
rules?: Array<LifecycleUpdateParams.Rule>;
/**
* Header param: Jurisdiction where objects in this bucket are guaranteed to be
* stored.
*/
'cf-r2-jurisdiction'?: 'default' | 'eu' | 'us' | 'fedramp' | 'fedramp-high';
}
export namespace LifecycleUpdateParams {
export interface Rule {
/**
* Unique identifier for this rule.
*/
id: string;
/**
* Conditions that apply to all transitions of this rule.
*/
conditions: Rule.Conditions;
/**
* Whether or not this rule is in effect.
*/
enabled: boolean;
/**
* Transition to abort ongoing multipart uploads.
*/
abortMultipartUploadsTransition?: Rule.AbortMultipartUploadsTransition;
/**
* Transition to delete objects.
*/
deleteObjectsTransition?: Rule.DeleteObjectsTransition;
/**
* Transitions to change the storage class of objects.
*/
storageClassTransitions?: Array<Rule.StorageClassTransition>;
}
export namespace Rule {
/**
* Conditions that apply to all transitions of this rule.
*/
export interface Conditions {
/**
* Transitions will only apply to objects/uploads in the bucket that start with the
* given prefix, an empty prefix can be provided to scope rule to all
* objects/uploads.
*/
prefix: string;
}
/**
* Transition to abort ongoing multipart uploads.
*/
export interface AbortMultipartUploadsTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
condition?: AbortMultipartUploadsTransition.Condition;
}
export namespace AbortMultipartUploadsTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
export interface Condition {
maxAge: number;
type: 'Age';
}
}
/**
* Transition to delete objects.
*/
export interface DeleteObjectsTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
condition?:
| DeleteObjectsTransition.R2LifecycleAgeCondition
| DeleteObjectsTransition.R2LifecycleDateCondition;
}
export namespace DeleteObjectsTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
export interface R2LifecycleAgeCondition {
maxAge: number;
type: 'Age';
}
/**
* Condition for lifecycle transitions to apply on a specific date.
*/
export interface R2LifecycleDateCondition {
date: string;
type: 'Date';
}
}
export interface StorageClassTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
condition:
| StorageClassTransition.R2LifecycleAgeCondition
| StorageClassTransition.R2LifecycleDateCondition;
storageClass: 'InfrequentAccess';
}
export namespace StorageClassTransition {
/**
* Condition for lifecycle transitions to apply after an object reaches an age in
* seconds.
*/
export interface R2LifecycleAgeCondition {
maxAge: number;
type: 'Age';
}
/**
* Condition for lifecycle transitions to apply on a specific date.
*/
export interface R2LifecycleDateCondition {
date: string;
type: 'Date';
}
}
}
}
export interface LifecycleGetParams {
/**
* Path param: Cloudflare account ID that owns the R2 resource.
*/
account_id: string;
/**
* Header param: Jurisdiction where objects in this bucket are guaranteed to be
* stored.
*/
'cf-r2-jurisdiction'?: 'default' | 'eu' | 'us' | 'fedramp' | 'fedramp-high';
}
export declare namespace Lifecycle {
export {
type LifecycleUpdateResponse as LifecycleUpdateResponse,
type LifecycleGetResponse as LifecycleGetResponse,
type LifecycleUpdateParams as LifecycleUpdateParams,
type LifecycleGetParams as LifecycleGetParams,
};
}