// 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 Storages extends APIResource { /** * Create a new storage configuration for cloud storage providers like AWS S3, * Cloudflare R2, etc. The storage credentials will be validated before saving. * * @example * ```ts * const storage = await client.storages.create({ * storage: { * access_key_id: '1234567890', * bucket: 'my-bucket', * provider: 'aws', * region: 'us-east-1', * secret_access_key: '1234567890', * }, * }); * ``` */ create(params: StorageCreateParams, options?: RequestOptions): APIPromise { const { storage } = params; return ( this._client.post('/api/storages', { body: storage, ...options, __security: { projectAccessTokenAuth: true }, }) as APIPromise<{ data: Storage }> )._thenUnwrap((obj) => obj.data); } /** * Retrieve details of a specific storage configuration by its id. * * @example * ```ts * const storage = await client.storages.retrieve('storageId'); * ``` */ retrieve(storageID: string, options?: RequestOptions): APIPromise { return ( this._client.get(path`/api/storages/${storageID}`, { ...options, __security: { projectAccessTokenAuth: true }, }) as APIPromise<{ data: Storage }> )._thenUnwrap((obj) => obj.data); } /** * Update customer-owned storage settings. Prefix changes apply to final outputs * that have not been uploaded yet. Existing files keep their stored object keys. * * @example * ```ts * await client.storages.update('storageId'); * ``` */ update(storageID: string, body: StorageUpdateParams, options?: RequestOptions): APIPromise { return this._client.patch(path`/api/storages/${storageID}`, { body, ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), __security: { projectAccessTokenAuth: true }, }); } /** * Retrieve a list of all storage configurations for the current project. * * @example * ```ts * const storages = await client.storages.list(); * ``` */ list(options?: RequestOptions): APIPromise { return this._client.get('/api/storages', { ...options, __security: { projectAccessTokenAuth: true } }); } /** * Delete a storage configuration. The storage must not be currently attached to * the project. * * @example * ```ts * await client.storages.delete('storageId'); * ``` */ delete(storageID: string, options?: RequestOptions): APIPromise { return this._client.delete(path`/api/storages/${storageID}`, { ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), __security: { projectAccessTokenAuth: true }, }); } } /** * A customer-owned storage connection using the standard S3 API. */ export type Storage = Storage.Chunkify | Storage.Cloudflare | Storage.Aws | Storage.S3Compatible; export namespace Storage { export interface Chunkify { /** * Unique identifier of the storage configuration */ id: string; /** * Created at timestamp */ created_at: string; /** * Provider specifies the storage provider. */ provider: 'chunkify'; /** * Region specifies the region of the storage provider. */ region: | 'us-east-1' | 'us-east-2' | 'us-west-1' | 'us-west-2' | 'eu-west-1' | 'eu-west-2' | 'ap-northeast-1' | 'ap-southeast-1'; /** * Unique identifier of the storage configuration */ slug: string; } export interface Cloudflare { /** * Unique identifier of the storage configuration */ id: string; /** * Canonical object-key prefix prepended to every final job output in this * customer-owned storage. An empty string means the bucket root. */ base_prefix: string; /** * Bucket is the name of the storage bucket. */ bucket: string; /** * Created at timestamp */ created_at: string; /** * Endpoint is the endpoint of the storage provider. */ endpoint: string; /** * Location specifies the location of the storage provider. */ location: 'US' | 'EU' | 'ASIA'; /** * Provider specifies the storage provider. */ provider: 'cloudflare'; /** * Public indicates whether the storage is publicly accessible. */ public: boolean; /** * Region specifies the region of the storage provider. */ region: 'auto'; /** * Unique identifier of the storage configuration */ slug: string; /** * Optional customer-managed HTTPS delivery origin used to build stable CDN URLs * for objects in this storage. */ cdn_base_url?: string | null; } export interface Aws { /** * Unique identifier of the storage configuration */ id: string; /** * Canonical object-key prefix prepended to every final job output in this * customer-owned storage. An empty string means the bucket root. */ base_prefix: string; /** * Bucket is the name of the storage bucket. */ bucket: string; /** * Created at timestamp */ created_at: string; /** * Provider specifies the storage provider. */ provider: 'aws'; /** * Public indicates whether the storage is publicly accessible. */ public: boolean; /** * Region specifies the region of the storage provider. */ region: | 'us-east-1' | 'us-east-2' | 'us-central-1' | 'us-west-1' | 'us-west-2' | 'eu-west-1' | 'eu-west-2' | 'eu-west-3' | 'eu-central-1' | 'eu-north-1' | 'ap-east-1' | 'ap-east-2' | 'ap-northeast-1' | 'ap-northeast-2' | 'ap-south-1' | 'ap-southeast-1' | 'ap-southeast-2'; /** * Unique identifier of the storage configuration */ slug: string; /** * Optional customer-managed HTTPS delivery origin used to build stable CDN URLs * for objects in this storage. */ cdn_base_url?: string | null; } /** * A customer-owned storage connection using the standard S3 API. */ export interface S3Compatible { /** * Unique identifier of the storage configuration */ id: string; /** * Addressing style detected during connection validation and used for later S3 * operations. */ addressing_style: 'virtual' | 'path'; /** * Canonical object-key prefix prepended to every final job output in this * customer-owned storage. An empty string means the bucket root. */ base_prefix: string; /** * Bucket is the name of the storage bucket. */ bucket: string; /** * Created at timestamp */ created_at: string; /** * Public HTTPS origin for the S3-compatible service. Credentials, paths, queries, * fragments, and non-public destinations are rejected. */ endpoint: string; /** * Chunkify workload location. This is independent from the provider signing * region. */ location: 'US' | 'EU' | 'ASIA'; /** * Stable provider identifier for generic S3-compatible storage. */ provider: 's3_compatible'; /** * Public indicates whether the storage is publicly accessible. */ public: boolean; /** * Provider region used for S3 request signing. This is independent from the * Chunkify workload location. */ region: string; /** * Unique identifier of the storage configuration */ slug: string; /** * Optional customer-managed HTTPS delivery origin used to build stable CDN URLs * for objects in this storage. */ cdn_base_url?: string | null; } } /** * Response containing the list of storages configurations for a project */ export interface StorageListResponse { /** * Data contains the storage items */ data: Array; /** * Status indicates the response status "success" */ status: 'success'; } export interface StorageCreateParams { /** * The parameters for creating a new storage configuration. */ storage: | StorageCreateParams.Aws | StorageCreateParams.Chunkify | StorageCreateParams.Cloudflare | StorageCreateParams.S3Compatible; } export namespace StorageCreateParams { /** * Storage parameters for AWS S3 storage. */ export interface Aws { /** * AccessKeyId is the access key for the storage provider. Required if not using * Chunkify storage. */ access_key_id: string; /** * Bucket is the name of the storage bucket. */ bucket: string; /** * Provider specifies the storage provider. */ provider: 'aws'; /** * Region specifies the region of the storage provider. */ region: | 'us-east-1' | 'us-east-2' | 'us-central-1' | 'us-west-1' | 'us-west-2' | 'eu-west-1' | 'eu-west-2' | 'eu-west-3' | 'eu-central-1' | 'eu-north-1' | 'ap-east-1' | 'ap-east-2' | 'ap-northeast-1' | 'ap-northeast-2' | 'ap-south-1' | 'ap-southeast-1' | 'ap-southeast-2'; /** * SecretAccessKey is the secret key for the storage provider. Required if not * using Chunkify storage. */ secret_access_key: string; /** * Object-key prefix for final job outputs. The API normalizes it without a leading * slash and with one trailing slash. Omit it or send an empty string to use the * bucket root. */ base_prefix?: string; /** * Optional customer-managed HTTPS delivery origin. It must not contain * credentials, a path, query string, or fragment. */ cdn_base_url?: string | null; /** * Public indicates whether the storage is publicly accessible. */ public?: boolean; } /** * Storage parameters for Chunkify ephemeral storage. */ export interface Chunkify { /** * Provider specifies the storage provider. */ provider: 'chunkify'; /** * Region specifies the region of the storage provider. */ region: | 'us-east-1' | 'us-east-2' | 'us-west-1' | 'us-west-2' | 'eu-west-1' | 'eu-west-2' | 'ap-northeast-1' | 'ap-southeast-1'; /** * Unsupported for Chunkify-managed temporary storage. Requests that provide this * field are rejected. */ cdn_base_url?: string | null; } /** * Storage parameters for Cloudflare R2 storage. */ export interface Cloudflare { /** * AccessKeyId is the access key for the storage provider. */ access_key_id: string; /** * Bucket is the name of the storage bucket. */ bucket: string; /** * Endpoint is the endpoint of the storage provider. */ endpoint: string; /** * Location specifies the location of the storage provider. */ location: 'US' | 'EU' | 'ASIA'; /** * Provider specifies the storage provider. */ provider: 'cloudflare'; /** * Region must be set to 'auto'. */ region: 'auto'; /** * SecretAccessKey is the secret key for the storage provider. */ secret_access_key: string; /** * Object-key prefix for final job outputs. The API normalizes it without a leading * slash and with one trailing slash. Omit it or send an empty string to use the * bucket root. */ base_prefix?: string; /** * Optional customer-managed HTTPS delivery origin. It must not contain * credentials, a path, query string, or fragment. */ cdn_base_url?: string | null; /** * Public indicates whether the storage is publicly accessible. */ public?: boolean; } /** * Storage parameters for a public S3-compatible service such as MinIO, Wasabi, or * Backblaze B2. */ export interface S3Compatible { /** * Access key for the storage provider. */ access_key_id: string; /** * Bucket is the name of the storage bucket. */ bucket: string; /** * Public HTTPS origin for the S3-compatible service. Credentials, paths, queries, * fragments, and non-public destinations are rejected. */ endpoint: string; /** * Chunkify workload location. It controls where Chunkify processes the workload * and is independent from the provider region. */ location: 'US' | 'EU' | 'ASIA'; /** * Stable provider identifier for generic S3-compatible storage. */ provider: 's3_compatible'; /** * Explicit provider region used for S3 request signing. Vendor-specific * identifiers are accepted. */ region: string; /** * Secret key for the storage provider. */ secret_access_key: string; /** * Object-key prefix for final job outputs. The API normalizes it without a leading * slash and with one trailing slash. Omit it or send an empty string to use the * bucket root. */ base_prefix?: string; /** * Optional customer-managed HTTPS delivery origin. It must not contain * credentials, a path, query string, or fragment. */ cdn_base_url?: string | null; /** * Whether the bucket is publicly readable. */ public?: boolean; } } export interface StorageUpdateParams { /** * Object-key prefix for future final job outputs. Existing files keep their stored * object keys. Send an empty string to use the bucket root. */ base_prefix?: string; /** * Customer-managed HTTPS delivery origin, or null to remove the current value. */ cdn_base_url?: string | null; } export declare namespace Storages { export { type Storage as Storage, type StorageListResponse as StorageListResponse, type StorageCreateParams as StorageCreateParams, type StorageUpdateParams as StorageUpdateParams, }; }