import { RequestClient } from '@uppy/companion-client'; import { BasePlugin, type DefinePluginOpts, EventManager, type PluginOpts, type Uppy } from '@uppy/core'; import type { Body, Meta, RequestOptions, UppyFile } from '@uppy/utils'; import MultipartUploader from './MultipartUploader.js'; import type { MultipartUploadResultWithSignal, UploadPartBytesResult, UploadResult, UploadResultWithSignal } from './utils.js'; type PartUploadedCallback = (file: UppyFile, part: { PartNumber: number; ETag: string; }) => void; declare module '@uppy/core' { interface UppyEventMap { 's3-multipart:part-uploaded': PartUploadedCallback; } interface PluginTypeRegistry { AwsS3Multipart: AwsS3Multipart; } } export interface AwsS3STSResponse { credentials: { AccessKeyId: string; SecretAccessKey: string; SessionToken: string; Expiration?: string; }; bucket: string; region: string; } type MaybePromise = T | Promise; type SignPartOptions = { uploadId: string; key: string; partNumber: number; body: Blob; signal?: AbortSignal; }; export type AwsS3UploadParameters = { method: 'POST'; url: string; fields: Record; expires?: number; headers?: Record; } | { method?: 'PUT'; url: string; fields?: Record; expires?: number; headers?: Record; }; export interface AwsS3Part { PartNumber?: number; Size?: number; ETag?: string; } type AWSS3WithCompanion = { endpoint: ConstructorParameters>[1]['companionUrl']; headers?: ConstructorParameters>[1]['companionHeaders']; cookiesRule?: ConstructorParameters>[1]['companionCookiesRule']; getTemporarySecurityCredentials?: true; }; type AWSS3WithoutCompanion = { getTemporarySecurityCredentials?: (options?: { signal?: AbortSignal; }) => MaybePromise; uploadPartBytes?: (options: { signature: AwsS3UploadParameters; body: FormData | Blob; size?: number; onProgress: any; onComplete: any; signal?: AbortSignal; }) => Promise; }; type AWSS3NonMultipartWithCompanionMandatory = {}; type AWSS3NonMultipartWithoutCompanionMandatory = { getUploadParameters: (file: UppyFile, options: RequestOptions) => MaybePromise; }; type AWSS3NonMultipartWithCompanion = AWSS3WithCompanion & AWSS3NonMultipartWithCompanionMandatory & { shouldUseMultipart: false; }; type AWSS3NonMultipartWithoutCompanion = AWSS3WithoutCompanion & AWSS3NonMultipartWithoutCompanionMandatory & { shouldUseMultipart: false; }; type AWSS3MultipartWithoutCompanionMandatorySignPart = { signPart: (file: UppyFile, opts: SignPartOptions) => MaybePromise; }; type AWSS3MultipartWithoutCompanionMandatory = { getChunkSize?: (file: { size: number; }) => number; createMultipartUpload: (file: UppyFile) => MaybePromise; listParts: (file: UppyFile, opts: UploadResultWithSignal) => MaybePromise; abortMultipartUpload: (file: UppyFile, opts: UploadResultWithSignal) => MaybePromise; completeMultipartUpload: (file: UppyFile, opts: { uploadId: string; key: string; parts: AwsS3Part[]; signal: AbortSignal; }) => MaybePromise<{ location?: string; }>; } & AWSS3MultipartWithoutCompanionMandatorySignPart; type AWSS3MultipartWithoutCompanion = AWSS3WithoutCompanion & AWSS3MultipartWithoutCompanionMandatory & { shouldUseMultipart?: true; }; type AWSS3MultipartWithCompanion = AWSS3WithCompanion & Partial> & { shouldUseMultipart?: true; }; type AWSS3MaybeMultipartWithCompanion = AWSS3WithCompanion & Partial> & AWSS3NonMultipartWithCompanionMandatory & { shouldUseMultipart: (file: UppyFile) => boolean; }; type AWSS3MaybeMultipartWithoutCompanion = AWSS3WithoutCompanion & AWSS3MultipartWithoutCompanionMandatory & AWSS3NonMultipartWithoutCompanionMandatory & { shouldUseMultipart: (file: UppyFile) => boolean; }; interface _AwsS3MultipartOptions extends PluginOpts { allowedMetaFields?: string[] | boolean; limit?: number; retryDelays?: number[] | null; } export type AwsS3MultipartOptions = _AwsS3MultipartOptions & (AWSS3NonMultipartWithCompanion | AWSS3NonMultipartWithoutCompanion | AWSS3MultipartWithCompanion | AWSS3MultipartWithoutCompanion | AWSS3MaybeMultipartWithCompanion | AWSS3MaybeMultipartWithoutCompanion); export type { AwsS3MultipartOptions as AwsS3Options }; declare const defaultOptions: { allowedMetaFields: true; limit: number; getTemporarySecurityCredentials: any; shouldUseMultipart: true; retryDelays: number[]; }; export type { AwsBody } from './utils.js'; export default class AwsS3Multipart extends BasePlugin, keyof typeof defaultOptions> & Pick, 'getChunkSize' | 'createMultipartUpload' | 'listParts' | 'abortMultipartUpload' | 'completeMultipartUpload'> & Required> & Partial & AWSS3MultipartWithoutCompanionMandatorySignPart & AWSS3NonMultipartWithoutCompanionMandatory, M, B> { #private; static VERSION: string; protected requests: any; protected uploaderEvents: Record | null>; protected uploaders: Record | null>; constructor(uppy: Uppy, opts?: AwsS3MultipartOptions); setOptions(newOptions: Partial>): void; /** * Clean up all references for a file's upload: the MultipartUploader instance, * any events related to the file, and the Companion WebSocket connection. * * Set `opts.abort` to tell S3 that the multipart upload is cancelled and must be removed. * This should be done when the user cancels the upload, not when the upload is completed or errored. */ resetUploaderReferences(fileID: string, opts?: { abort: boolean; }): void; createMultipartUpload(file: UppyFile, signal?: AbortSignal): Promise; listParts(file: UppyFile, { key, uploadId, signal }: UploadResultWithSignal, oldSignal?: AbortSignal): Promise; completeMultipartUpload(file: UppyFile, { key, uploadId, parts, signal }: MultipartUploadResultWithSignal, oldSignal?: AbortSignal): Promise; createSignedURL(file: UppyFile, options: SignPartOptions): Promise; signPart(file: UppyFile, { uploadId, key, partNumber, signal }: SignPartOptions): Promise; abortMultipartUpload(file: UppyFile, { key, uploadId, signal }: UploadResultWithSignal): Promise; getUploadParameters(file: UppyFile, options: RequestOptions): Promise; static uploadPartBytes({ signature: { url, expires, headers, method }, body, size, onProgress, onComplete, signal, }: { signature: AwsS3UploadParameters; body: FormData | Blob; size?: number; onProgress: any; onComplete: any; signal?: AbortSignal; }): Promise; install(): void; uninstall(): void; } export type uploadPartBytes = (typeof AwsS3Multipart)['uploadPartBytes']; export type { MultipartUploadResult, MultipartUploadResultWithSignal, UploadPartBytesResult, UploadResult, UploadResultWithSignal, } from './utils.js'; //# sourceMappingURL=index.d.ts.map