import type * as ClientS3 from "@aws-sdk/client-s3"; import type * as LibStorage from "@aws-sdk/lib-storage"; import type * as PresignedPost from "@aws-sdk/s3-presigned-post"; import type * as RequestPresigner from "@aws-sdk/s3-request-presigner"; import type { Adapter } from "../index.js"; import { FilesError } from "../internal/errors.js"; import type { ProviderFilesErrorCode } from "../internal/errors.js"; /** * The subset of the `@aws-sdk/*` modules the S3 engine is built from. This * module only ever imports the SDK's *types* — the runtime values arrive * through this bundle, so nothing here puts `@aws-sdk/*` in the static import * graph. `files-sdk/s3` fills it from ordinary static imports (its consumers * install the SDK anyway); the lazy aws-sdk engine behind r2, minio, and * rustfs (`internal/s3-engine.ts`) fills it from dynamic imports, because * consumer bundlers resolve even dynamically-reached chunks at build time and * hard-error on a *static* import of an absent optional peer (rolldown-vite's * optional-peer-dep placeholder, #105). */ export interface S3Sdk { clientS3: Pick; presignedPost: Pick; requestPresigner: Pick; } export interface S3AdapterOptions { /** S3 bucket name. The adapter scopes all operations to it. */ bucket: string; /** * AWS region the bucket lives in (e.g. `us-east-1`). Falls back to * `AWS_REGION`, then `AWS_DEFAULT_REGION`; required if neither is set. */ region?: string; /** * Override the S3 service endpoint. Use this to point at S3-compatible * services (DigitalOcean Spaces, Wasabi, Backblaze B2, LocalStack, etc.). * * With an explicit endpoint the client sends request checksums, and * validates response checksums, only when the operation requires them * (`requestChecksumCalculation` / `responseChecksumValidation` set to * `"WHEN_REQUIRED"`), because several S3-compatible services reject the * `x-amz-checksum-crc32` header newer SDKs add by default. Set * `AWS_REQUEST_CHECKSUM_CALCULATION` / `AWS_RESPONSE_CHECKSUM_VALIDATION` * to override. */ endpoint?: string; /** * Use path-style addressing (`https://endpoint/bucket/key`) instead of * virtual-hosted style (`https://bucket.endpoint/key`). Required by some * S3-compatible services and by LocalStack. */ forcePathStyle?: boolean; /** * Whether to expose the native conditional primitives (`If-Match` / * `If-None-Match` create, replace, exact read, delete, and copy). * * Defaults to `true` only when the client will talk to AWS S3: no * `endpoint` here and no `AWS_ENDPOINT_URL_S3` / `AWS_ENDPOINT_URL` * redirect in the environment, or one whose hostname is `amazonaws.com` / * `amazonaws.com.cn` (or a subdomain of either). S3-compatible services * differ in which conditional headers they honor, so the adapter fails * closed for them rather than risk an unconditional overwrite. The same * test decides whether the adapter declares S3 event records * (`capabilities.events`). * * A shared-config `endpoint_url` (profile- or service-level) is invisible * at construction, so it is caught at request time instead: a conditional * request whose resolved hostname is not `amazonaws.com` or * `amazonaws.com.cn` (or a subdomain of either) fails closed before it is * sent. AWS-hosted endpoints (VPC, FIPS, dual-stack, GovCloud, the China * regions) all resolve under those suffixes and need no override. * * Set `true` to opt an S3-compatible endpoint that you have verified * honors `If-Match` / `If-None-Match` in — this skips both the constructor * check and the request-time hostname check — or `false` to disable the * primitives on a canonical bucket. */ conditional?: boolean; /** * Static credentials. Skip to use the AWS credential chain (env vars, * IAM role, shared profile, EC2/ECS/EKS instance metadata). */ credentials?: { accessKeyId: string; secretAccessKey: string; sessionToken?: string; }; /** * Origin used to build URLs from `url()`. When set, `url(key)` returns * `${publicBaseUrl}/${key}` and skips signing — appropriate for buckets * fronted by a CDN, public-read policy, or custom domain. When unset, * `url()` falls back to a presigned `GetObject` URL (see * {@link defaultUrlExpiresIn}). An explicit `url(key, { expiresIn })` or * `responseContentDisposition` still presigns even when this is set, since a * permanent link can't expire or carry the override. * * A trailing slash on the base is tolerated. Each key segment is * URL-encoded (the `/` separators are kept), so pass raw keys; a * pre-encoded key would be double-encoded. */ publicBaseUrl?: string; /** * Default expiry, in seconds, for the presigned URLs returned by * `url()` when no per-call `expiresIn` is given. Defaults to 3600 (1 hour). * Per-call `url(key, { expiresIn })` overrides. */ defaultUrlExpiresIn?: number; /** * Override the fallback message used when an unknown error has no * `message` of its own, and the label on the adapter's own errors. * Internal — set by the S3-compatible wrappers (r2, minio, wasabi, …) so * their users see "R2 error" instead of "S3 error". * @internal */ defaultProviderMessage?: string; } export type S3Adapter = Adapter & { readonly bucket: string; }; export declare const loadLibStorage: (importLibStorage?: () => Promise) => Promise; /** * Map an `@aws-sdk/client-s3` error (or any thrown value with the same * shape) to a {@link FilesError} — e.g. for errors from calls made on * `files.raw`. The optional `messages` argument overrides the per-code * fallback strings used when the error carries no message of its own. (The * adapter itself, and the S3-compatible wrappers, relabel through * `defaultProviderMessage` instead.) */ export declare const mapS3Error: (cause: unknown, messages?: Partial>) => FilesError; export declare const createS3Adapter: (sdk: S3Sdk, opts: S3AdapterOptions) => S3Adapter; //# sourceMappingURL=core.d.ts.map