client.d.mts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. /// <reference types="node" />
  4. /// <reference types="node" />
  5. import * as http from 'node:http';
  6. import * as https from 'node:https';
  7. import * as stream from 'node:stream';
  8. import { CredentialProvider } from "../CredentialProvider.mjs";
  9. import type { SelectResults } from "../helpers.mjs";
  10. import { CopyDestinationOptions, CopySourceOptions, LEGAL_HOLD_STATUS } from "../helpers.mjs";
  11. import type { NotificationEvent } from "../notification.mjs";
  12. import { NotificationConfig, NotificationPoller } from "../notification.mjs";
  13. import { CopyConditions } from "./copy-conditions.mjs";
  14. import { Extensions } from "./extensions.mjs";
  15. import { PostPolicy } from "./post-policy.mjs";
  16. import type { Region } from "./s3-endpoints.mjs";
  17. import type { Binary, BucketItem, BucketItemFromList, BucketItemStat, BucketStream, BucketVersioningConfiguration, CopyObjectResult, EncryptionConfig, GetObjectLegalHoldOptions, GetObjectOpts, GetObjectRetentionOpts, IncompleteUploadedBucketItem, IRequest, ItemBucketMetadata, LifecycleConfig, LifeCycleConfigParam, ListObjectQueryOpts, ListObjectV2Res, NotificationConfigResult, ObjectInfo, ObjectLockInfo, ObjectMetaData, ObjectRetentionInfo, PostPolicyResult, PreSignRequestParams, PutObjectLegalHoldOptions, RemoveObjectsParam, RemoveObjectsResponse, ReplicationConfig, ReplicationConfigOpts, RequestHeaders, ResultCallback, Retention, SelectOptions, StatObjectOpts, Tag, TaggingOpts, Tags, Transport, UploadedObjectInfo } from "./type.mjs";
  18. import type { ListMultipartResult, UploadedPart } from "./xml-parser.mjs";
  19. declare const requestOptionProperties: readonly ["agent", "ca", "cert", "ciphers", "clientCertEngine", "crl", "dhparam", "ecdhCurve", "family", "honorCipherOrder", "key", "passphrase", "pfx", "rejectUnauthorized", "secureOptions", "secureProtocol", "servername", "sessionIdContext"];
  20. export interface RetryOptions {
  21. /**
  22. * If this set to true, it will take precedence over all other retry options.
  23. * @default false
  24. */
  25. disableRetry?: boolean;
  26. /**
  27. * The maximum amount of retries for a request.
  28. * @default 1
  29. */
  30. maximumRetryCount?: number;
  31. /**
  32. * The minimum duration (in milliseconds) for the exponential backoff algorithm.
  33. * @default 100
  34. */
  35. baseDelayMs?: number;
  36. /**
  37. * The maximum duration (in milliseconds) for the exponential backoff algorithm.
  38. * @default 60000
  39. */
  40. maximumDelayMs?: number;
  41. }
  42. export interface ClientOptions {
  43. endPoint: string;
  44. accessKey?: string;
  45. secretKey?: string;
  46. useSSL?: boolean;
  47. port?: number;
  48. region?: Region;
  49. transport?: Transport;
  50. sessionToken?: string;
  51. partSize?: number;
  52. pathStyle?: boolean;
  53. credentialsProvider?: CredentialProvider;
  54. s3AccelerateEndpoint?: string;
  55. transportAgent?: http.Agent;
  56. retryOptions?: RetryOptions;
  57. }
  58. export type RequestOption = Partial<IRequest> & {
  59. method: string;
  60. bucketName?: string;
  61. objectName?: string;
  62. query?: string;
  63. pathStyle?: boolean;
  64. };
  65. export type NoResultCallback = (error: unknown) => void;
  66. export interface MakeBucketOpt {
  67. ObjectLocking?: boolean;
  68. }
  69. export interface RemoveOptions {
  70. versionId?: string;
  71. governanceBypass?: boolean;
  72. forceDelete?: boolean;
  73. }
  74. export declare class TypedClient {
  75. protected transport: Transport;
  76. protected host: string;
  77. protected port: number;
  78. protected protocol: string;
  79. protected accessKey: string;
  80. protected secretKey: string;
  81. protected sessionToken?: string;
  82. protected userAgent: string;
  83. protected anonymous: boolean;
  84. protected pathStyle: boolean;
  85. protected regionMap: Record<string, string>;
  86. region?: string;
  87. protected credentialsProvider?: CredentialProvider;
  88. partSize: number;
  89. protected overRidePartSize?: boolean;
  90. protected retryOptions: RetryOptions;
  91. protected maximumPartSize: number;
  92. protected maxObjectSize: number;
  93. enableSHA256: boolean;
  94. protected s3AccelerateEndpoint?: string;
  95. protected reqOptions: Record<string, unknown>;
  96. protected transportAgent: http.Agent;
  97. private readonly clientExtensions;
  98. constructor(params: ClientOptions);
  99. /**
  100. * Minio extensions that aren't necessary present for Amazon S3 compatible storage servers
  101. */
  102. get extensions(): Extensions;
  103. /**
  104. * @param endPoint - valid S3 acceleration end point
  105. */
  106. setS3TransferAccelerate(endPoint: string): void;
  107. /**
  108. * Sets the supported request options.
  109. */
  110. setRequestOptions(options: Pick<https.RequestOptions, (typeof requestOptionProperties)[number]>): void;
  111. /**
  112. * This is s3 Specific and does not hold validity in any other Object storage.
  113. */
  114. private getAccelerateEndPointIfSet;
  115. /**
  116. * Set application specific information.
  117. * Generates User-Agent in the following style.
  118. * MinIO (OS; ARCH) LIB/VER APP/VER
  119. */
  120. setAppInfo(appName: string, appVersion: string): void;
  121. /**
  122. * returns options object that can be used with http.request()
  123. * Takes care of constructing virtual-host-style or path-style hostname
  124. */
  125. protected getRequestOptions(opts: RequestOption & {
  126. region: string;
  127. }): IRequest & {
  128. host: string;
  129. headers: Record<string, string>;
  130. };
  131. setCredentialsProvider(credentialsProvider: CredentialProvider): Promise<void>;
  132. private checkAndRefreshCreds;
  133. private logStream?;
  134. /**
  135. * log the request, response, error
  136. */
  137. private logHTTP;
  138. /**
  139. * Enable tracing
  140. */
  141. traceOn(stream?: stream.Writable): void;
  142. /**
  143. * Disable tracing
  144. */
  145. traceOff(): void;
  146. /**
  147. * makeRequest is the primitive used by the apis for making S3 requests.
  148. * payload can be empty string in case of no payload.
  149. * statusCode is the expected statusCode. If response.statusCode does not match
  150. * we parse the XML error and call the callback with the error message.
  151. *
  152. * A valid region is passed by the calls - listBuckets, makeBucket and getBucketRegion.
  153. *
  154. * @internal
  155. */
  156. makeRequestAsync(options: RequestOption, payload?: Binary, expectedCodes?: number[], region?: string): Promise<http.IncomingMessage>;
  157. /**
  158. * new request with promise
  159. *
  160. * No need to drain response, response body is not valid
  161. */
  162. makeRequestAsyncOmit(options: RequestOption, payload?: Binary, statusCodes?: number[], region?: string): Promise<Omit<http.IncomingMessage, 'on'>>;
  163. /**
  164. * makeRequestStream will be used directly instead of makeRequest in case the payload
  165. * is available as a stream. for ex. putObject
  166. *
  167. * @internal
  168. */
  169. makeRequestStreamAsync(options: RequestOption, body: stream.Readable | Binary, sha256sum: string, statusCodes: number[], region: string): Promise<http.IncomingMessage>;
  170. /**
  171. * gets the region of the bucket
  172. *
  173. * @param bucketName
  174. *
  175. */
  176. getBucketRegionAsync(bucketName: string): Promise<string>;
  177. /**
  178. * makeRequest is the primitive used by the apis for making S3 requests.
  179. * payload can be empty string in case of no payload.
  180. * statusCode is the expected statusCode. If response.statusCode does not match
  181. * we parse the XML error and call the callback with the error message.
  182. * A valid region is passed by the calls - listBuckets, makeBucket and
  183. * getBucketRegion.
  184. *
  185. * @deprecated use `makeRequestAsync` instead
  186. */
  187. makeRequest(options: RequestOption, payload: Binary | undefined, expectedCodes: number[] | undefined, region: string | undefined, returnResponse: boolean, cb: (cb: unknown, result: http.IncomingMessage) => void): void;
  188. /**
  189. * makeRequestStream will be used directly instead of makeRequest in case the payload
  190. * is available as a stream. for ex. putObject
  191. *
  192. * @deprecated use `makeRequestStreamAsync` instead
  193. */
  194. makeRequestStream(options: RequestOption, stream: stream.Readable | Buffer, sha256sum: string, statusCodes: number[], region: string, returnResponse: boolean, cb: (cb: unknown, result: http.IncomingMessage) => void): void;
  195. /**
  196. * @deprecated use `getBucketRegionAsync` instead
  197. */
  198. getBucketRegion(bucketName: string, cb: (err: unknown, region: string) => void): Promise<void>;
  199. /**
  200. * Creates the bucket `bucketName`.
  201. *
  202. */
  203. makeBucket(bucketName: string, region?: Region, makeOpts?: MakeBucketOpt): Promise<void>;
  204. /**
  205. * To check if a bucket already exists.
  206. */
  207. bucketExists(bucketName: string): Promise<boolean>;
  208. removeBucket(bucketName: string): Promise<void>;
  209. /**
  210. * @deprecated use promise style API
  211. */
  212. removeBucket(bucketName: string, callback: NoResultCallback): void;
  213. /**
  214. * Callback is called with readable stream of the object content.
  215. */
  216. getObject(bucketName: string, objectName: string, getOpts?: GetObjectOpts): Promise<stream.Readable>;
  217. /**
  218. * Callback is called with readable stream of the partial object content.
  219. * @param bucketName
  220. * @param objectName
  221. * @param offset
  222. * @param length - length of the object that will be read in the stream (optional, if not specified we read the rest of the file from the offset)
  223. * @param getOpts
  224. */
  225. getPartialObject(bucketName: string, objectName: string, offset: number, length?: number, getOpts?: GetObjectOpts): Promise<stream.Readable>;
  226. /**
  227. * download object content to a file.
  228. * This method will create a temp file named `${filename}.${base64(etag)}.part.minio` when downloading.
  229. *
  230. * @param bucketName - name of the bucket
  231. * @param objectName - name of the object
  232. * @param filePath - path to which the object data will be written to
  233. * @param getOpts - Optional object get option
  234. */
  235. fGetObject(bucketName: string, objectName: string, filePath: string, getOpts?: GetObjectOpts): Promise<void>;
  236. /**
  237. * Stat information of the object.
  238. */
  239. statObject(bucketName: string, objectName: string, statOpts?: StatObjectOpts): Promise<BucketItemStat>;
  240. removeObject(bucketName: string, objectName: string, removeOpts?: RemoveOptions): Promise<void>;
  241. listIncompleteUploads(bucket: string, prefix: string, recursive: boolean): BucketStream<IncompleteUploadedBucketItem>;
  242. /**
  243. * Called by listIncompleteUploads to fetch a batch of incomplete uploads.
  244. */
  245. listIncompleteUploadsQuery(bucketName: string, prefix: string, keyMarker: string, uploadIdMarker: string, delimiter: string): Promise<ListMultipartResult>;
  246. /**
  247. * Initiate a new multipart upload.
  248. * @internal
  249. */
  250. initiateNewMultipartUpload(bucketName: string, objectName: string, headers: RequestHeaders): Promise<string>;
  251. /**
  252. * Internal Method to abort a multipart upload request in case of any errors.
  253. *
  254. * @param bucketName - Bucket Name
  255. * @param objectName - Object Name
  256. * @param uploadId - id of a multipart upload to cancel during compose object sequence.
  257. */
  258. abortMultipartUpload(bucketName: string, objectName: string, uploadId: string): Promise<void>;
  259. findUploadId(bucketName: string, objectName: string): Promise<string | undefined>;
  260. /**
  261. * this call will aggregate the parts on the server into a single object.
  262. */
  263. completeMultipartUpload(bucketName: string, objectName: string, uploadId: string, etags: {
  264. part: number;
  265. etag?: string;
  266. }[]): Promise<{
  267. etag: string;
  268. versionId: string | null;
  269. }>;
  270. /**
  271. * Get part-info of all parts of an incomplete upload specified by uploadId.
  272. */
  273. protected listParts(bucketName: string, objectName: string, uploadId: string): Promise<UploadedPart[]>;
  274. /**
  275. * Called by listParts to fetch a batch of part-info
  276. */
  277. private listPartsQuery;
  278. listBuckets(): Promise<BucketItemFromList[]>;
  279. /**
  280. * Calculate part size given the object size. Part size will be atleast this.partSize
  281. */
  282. calculatePartSize(size: number): number;
  283. /**
  284. * Uploads the object using contents from a file
  285. */
  286. fPutObject(bucketName: string, objectName: string, filePath: string, metaData?: ObjectMetaData): Promise<UploadedObjectInfo>;
  287. /**
  288. * Uploading a stream, "Buffer" or "string".
  289. * It's recommended to pass `size` argument with stream.
  290. */
  291. putObject(bucketName: string, objectName: string, stream: stream.Readable | Buffer | string, size?: number, metaData?: ItemBucketMetadata): Promise<UploadedObjectInfo>;
  292. /**
  293. * method to upload buffer in one call
  294. * @private
  295. */
  296. private uploadBuffer;
  297. /**
  298. * upload stream with MultipartUpload
  299. * @private
  300. */
  301. private uploadStream;
  302. removeBucketReplication(bucketName: string): Promise<void>;
  303. removeBucketReplication(bucketName: string, callback: NoResultCallback): void;
  304. setBucketReplication(bucketName: string, replicationConfig: ReplicationConfigOpts): void;
  305. setBucketReplication(bucketName: string, replicationConfig: ReplicationConfigOpts): Promise<void>;
  306. getBucketReplication(bucketName: string): void;
  307. getBucketReplication(bucketName: string): Promise<ReplicationConfig>;
  308. getObjectLegalHold(bucketName: string, objectName: string, getOpts?: GetObjectLegalHoldOptions, callback?: ResultCallback<LEGAL_HOLD_STATUS>): Promise<LEGAL_HOLD_STATUS>;
  309. setObjectLegalHold(bucketName: string, objectName: string, setOpts?: PutObjectLegalHoldOptions): void;
  310. /**
  311. * Get Tags associated with a Bucket
  312. */
  313. getBucketTagging(bucketName: string): Promise<Tag[]>;
  314. /**
  315. * Get the tags associated with a bucket OR an object
  316. */
  317. getObjectTagging(bucketName: string, objectName: string, getOpts?: GetObjectOpts): Promise<Tag[]>;
  318. /**
  319. * Set the policy on a bucket or an object prefix.
  320. */
  321. setBucketPolicy(bucketName: string, policy: string): Promise<void>;
  322. /**
  323. * Get the policy on a bucket or an object prefix.
  324. */
  325. getBucketPolicy(bucketName: string): Promise<string>;
  326. putObjectRetention(bucketName: string, objectName: string, retentionOpts?: Retention): Promise<void>;
  327. getObjectLockConfig(bucketName: string, callback: ResultCallback<ObjectLockInfo>): void;
  328. getObjectLockConfig(bucketName: string): void;
  329. getObjectLockConfig(bucketName: string): Promise<ObjectLockInfo>;
  330. setObjectLockConfig(bucketName: string, lockConfigOpts: Omit<ObjectLockInfo, 'objectLockEnabled'>): void;
  331. setObjectLockConfig(bucketName: string, lockConfigOpts: Omit<ObjectLockInfo, 'objectLockEnabled'>): Promise<void>;
  332. getBucketVersioning(bucketName: string): Promise<BucketVersioningConfiguration>;
  333. setBucketVersioning(bucketName: string, versionConfig: BucketVersioningConfiguration): Promise<void>;
  334. private setTagging;
  335. private removeTagging;
  336. setBucketTagging(bucketName: string, tags: Tags): Promise<void>;
  337. removeBucketTagging(bucketName: string): Promise<void>;
  338. setObjectTagging(bucketName: string, objectName: string, tags: Tags, putOpts?: TaggingOpts): Promise<void>;
  339. removeObjectTagging(bucketName: string, objectName: string, removeOpts: TaggingOpts): Promise<void>;
  340. selectObjectContent(bucketName: string, objectName: string, selectOpts: SelectOptions): Promise<SelectResults | undefined>;
  341. private applyBucketLifecycle;
  342. removeBucketLifecycle(bucketName: string): Promise<void>;
  343. setBucketLifecycle(bucketName: string, lifeCycleConfig: LifeCycleConfigParam): Promise<void>;
  344. getBucketLifecycle(bucketName: string): Promise<LifecycleConfig | null>;
  345. setBucketEncryption(bucketName: string, encryptionConfig?: EncryptionConfig): Promise<void>;
  346. getBucketEncryption(bucketName: string): Promise<any>;
  347. removeBucketEncryption(bucketName: string): Promise<void>;
  348. getObjectRetention(bucketName: string, objectName: string, getOpts?: GetObjectRetentionOpts): Promise<ObjectRetentionInfo | null | undefined>;
  349. removeObjects(bucketName: string, objectsList: RemoveObjectsParam): Promise<RemoveObjectsResponse[]>;
  350. removeIncompleteUpload(bucketName: string, objectName: string): Promise<void>;
  351. private copyObjectV1;
  352. private copyObjectV2;
  353. copyObject(source: CopySourceOptions, dest: CopyDestinationOptions): Promise<CopyObjectResult>;
  354. copyObject(targetBucketName: string, targetObjectName: string, sourceBucketNameAndObjectName: string, conditions?: CopyConditions): Promise<CopyObjectResult>;
  355. uploadPart(partConfig: {
  356. bucketName: string;
  357. objectName: string;
  358. uploadID: string;
  359. partNumber: number;
  360. headers: RequestHeaders;
  361. }, payload?: Binary): Promise<{
  362. etag: string;
  363. key: string;
  364. part: number;
  365. }>;
  366. composeObject(destObjConfig: CopyDestinationOptions, sourceObjList: CopySourceOptions[], {
  367. maxConcurrency
  368. }?: {
  369. maxConcurrency?: number | undefined;
  370. }): Promise<boolean | {
  371. etag: string;
  372. versionId: string | null;
  373. } | Promise<void> | CopyObjectResult>;
  374. presignedUrl(method: string, bucketName: string, objectName: string, expires?: number | PreSignRequestParams | undefined, reqParams?: PreSignRequestParams | Date, requestDate?: Date): Promise<string>;
  375. presignedGetObject(bucketName: string, objectName: string, expires?: number, respHeaders?: PreSignRequestParams | Date, requestDate?: Date): Promise<string>;
  376. presignedPutObject(bucketName: string, objectName: string, expires?: number): Promise<string>;
  377. newPostPolicy(): PostPolicy;
  378. presignedPostPolicy(postPolicy: PostPolicy): Promise<PostPolicyResult>;
  379. listObjectsQuery(bucketName: string, prefix?: string, marker?: string, listQueryOpts?: ListObjectQueryOpts): Promise<{
  380. objects: ObjectInfo[];
  381. isTruncated?: boolean | undefined;
  382. nextMarker?: string | undefined;
  383. versionIdMarker?: string | undefined;
  384. keyMarker?: string | undefined;
  385. }>;
  386. listObjects(bucketName: string, prefix?: string, recursive?: boolean, listOpts?: ListObjectQueryOpts | undefined): BucketStream<ObjectInfo>;
  387. listObjectsV2Query(bucketName: string, prefix: string, continuationToken: string, delimiter: string, maxKeys: number, startAfter: string): Promise<ListObjectV2Res>;
  388. listObjectsV2(bucketName: string, prefix?: string, recursive?: boolean, startAfter?: string): BucketStream<BucketItem>;
  389. setBucketNotification(bucketName: string, config: NotificationConfig): Promise<void>;
  390. removeAllBucketNotification(bucketName: string): Promise<void>;
  391. getBucketNotification(bucketName: string): Promise<NotificationConfigResult>;
  392. listenBucketNotification(bucketName: string, prefix: string, suffix: string, events: NotificationEvent[]): NotificationPoller;
  393. }
  394. export {};