@hdriel/aws-utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,320 @@
1
+ import * as _aws_sdk_client_iam from '@aws-sdk/client-iam';
2
+ import { IAMClient } from '@aws-sdk/client-iam';
3
+ import { InvokeCommandOutput } from '@aws-sdk/client-lambda';
4
+ import { Request as Request$1, Response, NextFunction, RequestHandler } from 'express';
5
+ import { Logger } from 'stack-trace-logger';
6
+ import { StringValue } from 'ms';
7
+ import { Buffer } from 'buffer';
8
+ import { Readable } from 'node:stream';
9
+ import { S3Client, ListBucketsCommandInput, Bucket, PublicAccessBlockConfiguration, CreateBucketCommandOutput, HeadBucketCommandInput, DeleteBucketCommandOutput, PutObjectCommandOutput, DeleteObjectsCommandOutput, HeadObjectCommandOutput, DeleteObjectCommandOutput } from '@aws-sdk/client-s3';
10
+ import { Multer } from 'multer';
11
+ import { Unit } from 'bytes';
12
+
13
+ declare class IAMUtil {
14
+ private readonly iam;
15
+ constructor({ accessKeyId, secretAccessKey, endpoint, region, debug, }?: {
16
+ accessKeyId?: string;
17
+ secretAccessKey?: string;
18
+ endpoint?: string;
19
+ region?: string;
20
+ debug?: boolean;
21
+ });
22
+ get client(): IAMClient;
23
+ getUserList(): Promise<_aws_sdk_client_iam.ListUsersCommandOutput>;
24
+ listUsers(maxItems?: number): Promise<_aws_sdk_client_iam.User[] | null | undefined>;
25
+ }
26
+
27
+ declare class LambdaUtil<T> {
28
+ private readonly lambda;
29
+ private readonly serviceFunctionName;
30
+ constructor({ accessKeyId, secretAccessKey, endpoint, region, serviceFunctionName, debug, }: {
31
+ serviceFunctionName: string;
32
+ accessKeyId?: string;
33
+ secretAccessKey?: string;
34
+ endpoint?: string;
35
+ region?: string;
36
+ debug?: boolean;
37
+ });
38
+ private directInvoke;
39
+ runLambdaInDryRunMode(payload?: T): Promise<InvokeCommandOutput['Payload']>;
40
+ triggerLambdaEvent<T>(payload?: T): Promise<InvokeCommandOutput['Payload']>;
41
+ runAndGetLambdaResponse(payload?: T): Promise<InvokeCommandOutput['Payload']>;
42
+ }
43
+
44
+ declare enum ACLs {
45
+ private = "private",
46
+ publicRead = "public-read",
47
+ publicReadWrite = "public-read-write"
48
+ }
49
+
50
+ interface File {
51
+ fieldname: string;
52
+ originalname: string;
53
+ encoding: string;
54
+ mimetype: string;
55
+ destination: string;
56
+ filename: string;
57
+ path: string;
58
+ size: number;
59
+ }
60
+ interface FILES3_METADATA extends File {
61
+ directory: string;
62
+ }
63
+ type FILE_EXT = 'jpg' | 'jpeg' | 'png' | 'gif' | 'bmp' | 'webp' | 'svg' | 'ico' | 'tif' | 'tiff' | 'heic' | 'heif' | 'raw' | 'cr2' | 'nef' | 'arw' | 'mp4' | 'avi' | 'mov' | 'wmv' | 'flv' | 'mkv' | 'webm' | 'mpeg' | 'mpg' | 'm4v' | '3gp' | 'ogv' | 'ts' | 'mts' | 'm2ts' | 'pdf' | 'doc' | 'docx' | 'xls' | 'xlsx' | 'ppt' | 'pptx' | 'odt' | 'ods' | 'odp' | 'rtf' | 'pages' | 'numbers' | 'key' | 'txt' | 'csv' | 'json' | 'xml' | 'md' | 'log' | 'yaml' | 'yml' | 'ini' | 'conf' | 'cfg' | 'zip' | 'rar' | '7z' | 'tar' | 'gz' | 'bz2' | 'xz' | 'iso' | 'mp3' | 'wav' | 'ogg' | 'flac' | 'aac' | 'm4a' | 'wma' | 'aiff' | 'ape' | 'opus' | 'js' | 'ts' | 'jsx' | 'tsx' | 'py' | 'java' | 'c' | 'cpp' | 'h' | 'cs' | 'php' | 'rb' | 'go' | 'rs' | 'swift' | 'kt' | 'scala' | 'html' | 'htm' | 'css' | 'scss' | 'sass' | 'less' | 'ttf' | 'otf' | 'woff' | 'woff2' | 'eot' | 'obj' | 'fbx' | 'stl' | 'dae' | 'blend' | '3ds' | 'gltf' | 'glb' | 'exe' | 'dll' | 'so' | 'dylib' | 'bin' | 'dmg' | 'pkg' | 'deb' | 'rpm' | 'apk';
64
+ type FILE_TYPE = 'image' | 'video' | 'application' | 'text' | 'audio';
65
+ type ByteUnitStringValue = `${number}${Unit}`;
66
+ interface TreeFileItem {
67
+ name: string;
68
+ path: string;
69
+ type: 'directory' | 'file';
70
+ size: number;
71
+ lastModified: Date;
72
+ }
73
+ interface TreeDirectoryItem {
74
+ name: string;
75
+ path: string;
76
+ type: 'directory' | 'file';
77
+ children: Array<TreeDirectoryItem | TreeFileItem>;
78
+ }
79
+
80
+ interface ContentFile {
81
+ Key: string;
82
+ Name: string;
83
+ LastModified: Date;
84
+ ETag: string;
85
+ Size: number;
86
+ StorageClass: string;
87
+ Owner: {
88
+ DisplayName?: string;
89
+ ID?: string;
90
+ };
91
+ }
92
+ interface FileUploadResponse {
93
+ ETag: string;
94
+ Location: string;
95
+ Key: string;
96
+ Bucket: string;
97
+ }
98
+ interface UploadedS3File extends Express.Multer.File {
99
+ bucket: string;
100
+ key: string;
101
+ acl: string;
102
+ contentType: string;
103
+ contentDisposition: null;
104
+ storageClass: string;
105
+ serverSideEncryption: null;
106
+ metadata: FILES3_METADATA;
107
+ location: string;
108
+ etag: string;
109
+ }
110
+ interface S3UploadOptions {
111
+ acl?: ACLs;
112
+ maxFilesCount?: undefined | number | null;
113
+ maxFileSize?: ByteUnitStringValue | number;
114
+ filename?: string | ((req: Request, file: File) => string | Promise<string>);
115
+ fileType?: FILE_TYPE | FILE_TYPE[];
116
+ fileExt?: FILE_EXT | FILE_EXT[];
117
+ metadata?: Record<string, string> | ((req: Request, file: File) => Record<string, string> | Promise<Record<string, string>>);
118
+ }
119
+ interface BucketInfo {
120
+ name: string;
121
+ region: string;
122
+ endpoint: string;
123
+ exists: boolean;
124
+ bucketRegion?: string;
125
+ accessPointAlias?: boolean;
126
+ creationDate?: Date;
127
+ acl?: Array<{
128
+ grantee?: string;
129
+ permission?: string;
130
+ }>;
131
+ publicAccessBlock?: {
132
+ BlockPublicAcls?: boolean;
133
+ IgnorePublicAcls?: boolean;
134
+ BlockPublicPolicy?: boolean;
135
+ RestrictPublicBuckets?: boolean;
136
+ };
137
+ policy?: any;
138
+ versioning?: string;
139
+ encryption?: {
140
+ enabled: boolean;
141
+ type?: string;
142
+ };
143
+ }
144
+
145
+ declare class S3BucketUtil {
146
+ readonly s3Client: S3Client;
147
+ readonly bucket: string;
148
+ readonly endpoint: string;
149
+ readonly region: string;
150
+ readonly logger?: Logger;
151
+ readonly reqId: string | null;
152
+ private readonly maxUploadFileSizeRestriction;
153
+ constructor({ logger, bucket, reqId, accessKeyId, secretAccessKey, endpoint, region, s3ForcePathStyle, maxUploadFileSizeRestriction, }: {
154
+ logger?: Logger;
155
+ bucket: string;
156
+ reqId?: string;
157
+ accessKeyId?: string;
158
+ secretAccessKey?: string;
159
+ endpoint?: string;
160
+ region?: string;
161
+ s3ForcePathStyle?: boolean;
162
+ maxUploadFileSizeRestriction?: ByteUnitStringValue;
163
+ });
164
+ get link(): string;
165
+ private execute;
166
+ getBucketList(options?: Partial<ListBucketsCommandInput>, includePublicAccess?: boolean): Promise<Array<Bucket & {
167
+ PublicAccessBlockConfiguration?: PublicAccessBlockConfiguration;
168
+ }> | null>;
169
+ isBucketExists(): Promise<boolean>;
170
+ private initAsPublicBucket;
171
+ private initAsPrivateBucket;
172
+ initBucket(acl?: ACLs, includeConstraintLocation?: boolean): Promise<CreateBucketCommandOutput | undefined>;
173
+ private emptyBucket;
174
+ bucketInfo(options?: Partial<HeadBucketCommandInput>): Promise<BucketInfo>;
175
+ destroyBucket(forceDeleteAllFilesBeforeDestroyBucket?: boolean): Promise<DeleteBucketCommandOutput | undefined>;
176
+ createDirectory(directoryPath: string): Promise<PutObjectCommandOutput>;
177
+ deleteDirectory(directoryPath: string): Promise<DeleteObjectsCommandOutput | null>;
178
+ directoryList(directoryPath?: string): Promise<{
179
+ directories: string[];
180
+ files: ContentFile[];
181
+ }>;
182
+ /**
183
+ * Get all files recursively (example for search/indexing)
184
+ * @param directoryPath
185
+ */
186
+ directoryListRecursive(directoryPath?: string): Promise<{
187
+ directories: string[];
188
+ files: Array<ContentFile & {
189
+ Name: string;
190
+ }>;
191
+ }>;
192
+ /**
193
+ * Get tree files recursively (example for build file explorer UI)
194
+ * @param directoryPath - the directory start from
195
+ * @example
196
+ * const tree = await s3Util.getDirectoryTree('uploads');
197
+ * // {
198
+ * // name: 'uploads',
199
+ * // path: 'uploads/',
200
+ * // type: 'directory',
201
+ * // children: [
202
+ * // {
203
+ * // name: 'logo.png',
204
+ * // path: 'uploads/logo.png',
205
+ * // type: 'file',
206
+ * // size: 12345,
207
+ * // lastModified: Date
208
+ * // },
209
+ * // {
210
+ * // name: 'images',
211
+ * // path: 'uploads/images/',
212
+ * // type: 'directory',
213
+ * // children: [
214
+ * // { name: 'photo1.jpg', type: 'file', ... },
215
+ * // { name: 'photo2.jpg', type: 'file', ... }
216
+ * // ]
217
+ * // }
218
+ * // ]
219
+ * // }
220
+ */
221
+ directoryTree(directoryPath?: string): Promise<TreeDirectoryItem>;
222
+ fileInfo(filePath: string): Promise<HeadObjectCommandOutput>;
223
+ fileListInfo(directoryPath?: string, fileNamePrefix?: string): Promise<ContentFile[]>;
224
+ taggingFile(filePath: string, tagVersion?: string): Promise<boolean>;
225
+ fileVersion(filePath: string): Promise<string>;
226
+ fileUrl(filePath: string, expiresIn?: number | StringValue): Promise<string>;
227
+ sizeOf(filePath: string, unit?: 'bytes' | 'KB' | 'MB' | 'GB'): Promise<number>;
228
+ fileExists(filePath: string): Promise<boolean>;
229
+ fileContent(filePath: string, format?: 'buffer' | 'base64' | 'utf8'): Promise<Buffer | string>;
230
+ uploadFile(filePath: string, fileData: Buffer | Readable | string | Uint8Array, acl?: ACLs, version?: string): Promise<FileUploadResponse & {
231
+ test: string;
232
+ }>;
233
+ deleteFile(filePath: string): Promise<DeleteObjectCommandOutput>;
234
+ private streamObjectFile;
235
+ private streamVideoFile;
236
+ getStreamZipFileCtr({ filePath, filename: _filename, compressionLevel, }: {
237
+ filePath: string | string[];
238
+ filename?: string;
239
+ compressionLevel?: number;
240
+ }): Promise<(req: Request$1 & any, res: Response & any, next: NextFunction & any) => Promise<void>>;
241
+ getStreamFileCtrl({ filePath, filename }: {
242
+ filePath: string;
243
+ filename?: string;
244
+ }): Promise<(req: Request$1 & any, res: Response & any, next: NextFunction & any) => Promise<void>>;
245
+ getStreamVideoFileCtrl({ fileKey, allowedWhitelist, contentType, streamTimeoutMS, bufferMB, }: {
246
+ contentType?: string;
247
+ fileKey: string;
248
+ allowedWhitelist?: string[];
249
+ bufferMB?: number | undefined;
250
+ streamTimeoutMS?: number | undefined;
251
+ }): Promise<(req: Request$1 & any, res: Response & any, next: NextFunction & any) => Promise<any>>;
252
+ private static fileFilter;
253
+ private getFileSize;
254
+ getUploadFileMW(directory?: string, { acl, maxFileSize, filename: _filename, fileType, fileExt, metadata: customMetadata, }?: S3UploadOptions): Multer;
255
+ /**
256
+ * Middleware for uploading a single file
257
+ * Adds the uploaded file info to req.s3File
258
+ */
259
+ uploadSingleFile(fieldName: string, directory: string, options?: S3UploadOptions): (req: Request$1 & {
260
+ s3File?: UploadedS3File;
261
+ } & any, res: Response, next: NextFunction & any) => void;
262
+ /**
263
+ * Middleware for uploading multiple files with the same field name
264
+ * Adds the uploaded files info to req.s3Files
265
+ */
266
+ uploadMultipleFiles(fieldName: string, directory: string, options?: S3UploadOptions): (req: Request$1 & {
267
+ s3Files?: UploadedS3File[];
268
+ } & any, res: Response, next: NextFunction & any) => void;
269
+ /**
270
+ * Middleware for uploading multiple files with different field names
271
+ * Adds the uploaded files info to req.s3FilesByField
272
+ */
273
+ uploadFieldsFiles(fields: Array<{
274
+ name: string;
275
+ directory: string;
276
+ maxCount?: number;
277
+ options?: S3UploadOptions;
278
+ }>): RequestHandler;
279
+ /**
280
+ * Middleware for uploading any files (mixed field names)
281
+ * Adds the uploaded files info to req.s3AllFiles
282
+ */
283
+ uploadAnyFiles(directory: string, maxCount?: number, options?: S3UploadOptions): RequestHandler;
284
+ }
285
+
286
+ declare class SNSUtil<T> {
287
+ private readonly sns;
288
+ private readonly topicArn;
289
+ constructor({ accessKeyId, secretAccessKey, endpoint, region, topicArn, debug, }: {
290
+ topicArn: string;
291
+ accessKeyId?: string;
292
+ secretAccessKey?: string;
293
+ endpoint?: string;
294
+ region?: string;
295
+ debug?: boolean;
296
+ });
297
+ publishTopicMessage(message: T): Promise<void>;
298
+ }
299
+
300
+ declare class AWSConfigSharingUtil {
301
+ static accessKeyId: string;
302
+ static secretAccessKey: string;
303
+ static endpoint: string;
304
+ static region: string;
305
+ constructor();
306
+ static setConfig({ accessKeyId, secretAccessKey, endpoint, region, }: {
307
+ accessKeyId?: string | undefined;
308
+ secretAccessKey?: string | undefined;
309
+ endpoint?: string | undefined;
310
+ region?: string | undefined;
311
+ }): void;
312
+ static getConfig(): {
313
+ accessKeyId: string;
314
+ secretAccessKey: string;
315
+ region: string;
316
+ endpoint: string;
317
+ };
318
+ }
319
+
320
+ export { ACLs, AWSConfigSharingUtil, type BucketInfo, type FILE_EXT, type FILE_TYPE, IAMUtil, LambdaUtil, S3BucketUtil, SNSUtil, type TreeDirectoryItem, type TreeFileItem, type UploadedS3File };
@@ -0,0 +1,320 @@
1
+ import * as _aws_sdk_client_iam from '@aws-sdk/client-iam';
2
+ import { IAMClient } from '@aws-sdk/client-iam';
3
+ import { InvokeCommandOutput } from '@aws-sdk/client-lambda';
4
+ import { Request as Request$1, Response, NextFunction, RequestHandler } from 'express';
5
+ import { Logger } from 'stack-trace-logger';
6
+ import { StringValue } from 'ms';
7
+ import { Buffer } from 'buffer';
8
+ import { Readable } from 'node:stream';
9
+ import { S3Client, ListBucketsCommandInput, Bucket, PublicAccessBlockConfiguration, CreateBucketCommandOutput, HeadBucketCommandInput, DeleteBucketCommandOutput, PutObjectCommandOutput, DeleteObjectsCommandOutput, HeadObjectCommandOutput, DeleteObjectCommandOutput } from '@aws-sdk/client-s3';
10
+ import { Multer } from 'multer';
11
+ import { Unit } from 'bytes';
12
+
13
+ declare class IAMUtil {
14
+ private readonly iam;
15
+ constructor({ accessKeyId, secretAccessKey, endpoint, region, debug, }?: {
16
+ accessKeyId?: string;
17
+ secretAccessKey?: string;
18
+ endpoint?: string;
19
+ region?: string;
20
+ debug?: boolean;
21
+ });
22
+ get client(): IAMClient;
23
+ getUserList(): Promise<_aws_sdk_client_iam.ListUsersCommandOutput>;
24
+ listUsers(maxItems?: number): Promise<_aws_sdk_client_iam.User[] | null | undefined>;
25
+ }
26
+
27
+ declare class LambdaUtil<T> {
28
+ private readonly lambda;
29
+ private readonly serviceFunctionName;
30
+ constructor({ accessKeyId, secretAccessKey, endpoint, region, serviceFunctionName, debug, }: {
31
+ serviceFunctionName: string;
32
+ accessKeyId?: string;
33
+ secretAccessKey?: string;
34
+ endpoint?: string;
35
+ region?: string;
36
+ debug?: boolean;
37
+ });
38
+ private directInvoke;
39
+ runLambdaInDryRunMode(payload?: T): Promise<InvokeCommandOutput['Payload']>;
40
+ triggerLambdaEvent<T>(payload?: T): Promise<InvokeCommandOutput['Payload']>;
41
+ runAndGetLambdaResponse(payload?: T): Promise<InvokeCommandOutput['Payload']>;
42
+ }
43
+
44
+ declare enum ACLs {
45
+ private = "private",
46
+ publicRead = "public-read",
47
+ publicReadWrite = "public-read-write"
48
+ }
49
+
50
+ interface File {
51
+ fieldname: string;
52
+ originalname: string;
53
+ encoding: string;
54
+ mimetype: string;
55
+ destination: string;
56
+ filename: string;
57
+ path: string;
58
+ size: number;
59
+ }
60
+ interface FILES3_METADATA extends File {
61
+ directory: string;
62
+ }
63
+ type FILE_EXT = 'jpg' | 'jpeg' | 'png' | 'gif' | 'bmp' | 'webp' | 'svg' | 'ico' | 'tif' | 'tiff' | 'heic' | 'heif' | 'raw' | 'cr2' | 'nef' | 'arw' | 'mp4' | 'avi' | 'mov' | 'wmv' | 'flv' | 'mkv' | 'webm' | 'mpeg' | 'mpg' | 'm4v' | '3gp' | 'ogv' | 'ts' | 'mts' | 'm2ts' | 'pdf' | 'doc' | 'docx' | 'xls' | 'xlsx' | 'ppt' | 'pptx' | 'odt' | 'ods' | 'odp' | 'rtf' | 'pages' | 'numbers' | 'key' | 'txt' | 'csv' | 'json' | 'xml' | 'md' | 'log' | 'yaml' | 'yml' | 'ini' | 'conf' | 'cfg' | 'zip' | 'rar' | '7z' | 'tar' | 'gz' | 'bz2' | 'xz' | 'iso' | 'mp3' | 'wav' | 'ogg' | 'flac' | 'aac' | 'm4a' | 'wma' | 'aiff' | 'ape' | 'opus' | 'js' | 'ts' | 'jsx' | 'tsx' | 'py' | 'java' | 'c' | 'cpp' | 'h' | 'cs' | 'php' | 'rb' | 'go' | 'rs' | 'swift' | 'kt' | 'scala' | 'html' | 'htm' | 'css' | 'scss' | 'sass' | 'less' | 'ttf' | 'otf' | 'woff' | 'woff2' | 'eot' | 'obj' | 'fbx' | 'stl' | 'dae' | 'blend' | '3ds' | 'gltf' | 'glb' | 'exe' | 'dll' | 'so' | 'dylib' | 'bin' | 'dmg' | 'pkg' | 'deb' | 'rpm' | 'apk';
64
+ type FILE_TYPE = 'image' | 'video' | 'application' | 'text' | 'audio';
65
+ type ByteUnitStringValue = `${number}${Unit}`;
66
+ interface TreeFileItem {
67
+ name: string;
68
+ path: string;
69
+ type: 'directory' | 'file';
70
+ size: number;
71
+ lastModified: Date;
72
+ }
73
+ interface TreeDirectoryItem {
74
+ name: string;
75
+ path: string;
76
+ type: 'directory' | 'file';
77
+ children: Array<TreeDirectoryItem | TreeFileItem>;
78
+ }
79
+
80
+ interface ContentFile {
81
+ Key: string;
82
+ Name: string;
83
+ LastModified: Date;
84
+ ETag: string;
85
+ Size: number;
86
+ StorageClass: string;
87
+ Owner: {
88
+ DisplayName?: string;
89
+ ID?: string;
90
+ };
91
+ }
92
+ interface FileUploadResponse {
93
+ ETag: string;
94
+ Location: string;
95
+ Key: string;
96
+ Bucket: string;
97
+ }
98
+ interface UploadedS3File extends Express.Multer.File {
99
+ bucket: string;
100
+ key: string;
101
+ acl: string;
102
+ contentType: string;
103
+ contentDisposition: null;
104
+ storageClass: string;
105
+ serverSideEncryption: null;
106
+ metadata: FILES3_METADATA;
107
+ location: string;
108
+ etag: string;
109
+ }
110
+ interface S3UploadOptions {
111
+ acl?: ACLs;
112
+ maxFilesCount?: undefined | number | null;
113
+ maxFileSize?: ByteUnitStringValue | number;
114
+ filename?: string | ((req: Request, file: File) => string | Promise<string>);
115
+ fileType?: FILE_TYPE | FILE_TYPE[];
116
+ fileExt?: FILE_EXT | FILE_EXT[];
117
+ metadata?: Record<string, string> | ((req: Request, file: File) => Record<string, string> | Promise<Record<string, string>>);
118
+ }
119
+ interface BucketInfo {
120
+ name: string;
121
+ region: string;
122
+ endpoint: string;
123
+ exists: boolean;
124
+ bucketRegion?: string;
125
+ accessPointAlias?: boolean;
126
+ creationDate?: Date;
127
+ acl?: Array<{
128
+ grantee?: string;
129
+ permission?: string;
130
+ }>;
131
+ publicAccessBlock?: {
132
+ BlockPublicAcls?: boolean;
133
+ IgnorePublicAcls?: boolean;
134
+ BlockPublicPolicy?: boolean;
135
+ RestrictPublicBuckets?: boolean;
136
+ };
137
+ policy?: any;
138
+ versioning?: string;
139
+ encryption?: {
140
+ enabled: boolean;
141
+ type?: string;
142
+ };
143
+ }
144
+
145
+ declare class S3BucketUtil {
146
+ readonly s3Client: S3Client;
147
+ readonly bucket: string;
148
+ readonly endpoint: string;
149
+ readonly region: string;
150
+ readonly logger?: Logger;
151
+ readonly reqId: string | null;
152
+ private readonly maxUploadFileSizeRestriction;
153
+ constructor({ logger, bucket, reqId, accessKeyId, secretAccessKey, endpoint, region, s3ForcePathStyle, maxUploadFileSizeRestriction, }: {
154
+ logger?: Logger;
155
+ bucket: string;
156
+ reqId?: string;
157
+ accessKeyId?: string;
158
+ secretAccessKey?: string;
159
+ endpoint?: string;
160
+ region?: string;
161
+ s3ForcePathStyle?: boolean;
162
+ maxUploadFileSizeRestriction?: ByteUnitStringValue;
163
+ });
164
+ get link(): string;
165
+ private execute;
166
+ getBucketList(options?: Partial<ListBucketsCommandInput>, includePublicAccess?: boolean): Promise<Array<Bucket & {
167
+ PublicAccessBlockConfiguration?: PublicAccessBlockConfiguration;
168
+ }> | null>;
169
+ isBucketExists(): Promise<boolean>;
170
+ private initAsPublicBucket;
171
+ private initAsPrivateBucket;
172
+ initBucket(acl?: ACLs, includeConstraintLocation?: boolean): Promise<CreateBucketCommandOutput | undefined>;
173
+ private emptyBucket;
174
+ bucketInfo(options?: Partial<HeadBucketCommandInput>): Promise<BucketInfo>;
175
+ destroyBucket(forceDeleteAllFilesBeforeDestroyBucket?: boolean): Promise<DeleteBucketCommandOutput | undefined>;
176
+ createDirectory(directoryPath: string): Promise<PutObjectCommandOutput>;
177
+ deleteDirectory(directoryPath: string): Promise<DeleteObjectsCommandOutput | null>;
178
+ directoryList(directoryPath?: string): Promise<{
179
+ directories: string[];
180
+ files: ContentFile[];
181
+ }>;
182
+ /**
183
+ * Get all files recursively (example for search/indexing)
184
+ * @param directoryPath
185
+ */
186
+ directoryListRecursive(directoryPath?: string): Promise<{
187
+ directories: string[];
188
+ files: Array<ContentFile & {
189
+ Name: string;
190
+ }>;
191
+ }>;
192
+ /**
193
+ * Get tree files recursively (example for build file explorer UI)
194
+ * @param directoryPath - the directory start from
195
+ * @example
196
+ * const tree = await s3Util.getDirectoryTree('uploads');
197
+ * // {
198
+ * // name: 'uploads',
199
+ * // path: 'uploads/',
200
+ * // type: 'directory',
201
+ * // children: [
202
+ * // {
203
+ * // name: 'logo.png',
204
+ * // path: 'uploads/logo.png',
205
+ * // type: 'file',
206
+ * // size: 12345,
207
+ * // lastModified: Date
208
+ * // },
209
+ * // {
210
+ * // name: 'images',
211
+ * // path: 'uploads/images/',
212
+ * // type: 'directory',
213
+ * // children: [
214
+ * // { name: 'photo1.jpg', type: 'file', ... },
215
+ * // { name: 'photo2.jpg', type: 'file', ... }
216
+ * // ]
217
+ * // }
218
+ * // ]
219
+ * // }
220
+ */
221
+ directoryTree(directoryPath?: string): Promise<TreeDirectoryItem>;
222
+ fileInfo(filePath: string): Promise<HeadObjectCommandOutput>;
223
+ fileListInfo(directoryPath?: string, fileNamePrefix?: string): Promise<ContentFile[]>;
224
+ taggingFile(filePath: string, tagVersion?: string): Promise<boolean>;
225
+ fileVersion(filePath: string): Promise<string>;
226
+ fileUrl(filePath: string, expiresIn?: number | StringValue): Promise<string>;
227
+ sizeOf(filePath: string, unit?: 'bytes' | 'KB' | 'MB' | 'GB'): Promise<number>;
228
+ fileExists(filePath: string): Promise<boolean>;
229
+ fileContent(filePath: string, format?: 'buffer' | 'base64' | 'utf8'): Promise<Buffer | string>;
230
+ uploadFile(filePath: string, fileData: Buffer | Readable | string | Uint8Array, acl?: ACLs, version?: string): Promise<FileUploadResponse & {
231
+ test: string;
232
+ }>;
233
+ deleteFile(filePath: string): Promise<DeleteObjectCommandOutput>;
234
+ private streamObjectFile;
235
+ private streamVideoFile;
236
+ getStreamZipFileCtr({ filePath, filename: _filename, compressionLevel, }: {
237
+ filePath: string | string[];
238
+ filename?: string;
239
+ compressionLevel?: number;
240
+ }): Promise<(req: Request$1 & any, res: Response & any, next: NextFunction & any) => Promise<void>>;
241
+ getStreamFileCtrl({ filePath, filename }: {
242
+ filePath: string;
243
+ filename?: string;
244
+ }): Promise<(req: Request$1 & any, res: Response & any, next: NextFunction & any) => Promise<void>>;
245
+ getStreamVideoFileCtrl({ fileKey, allowedWhitelist, contentType, streamTimeoutMS, bufferMB, }: {
246
+ contentType?: string;
247
+ fileKey: string;
248
+ allowedWhitelist?: string[];
249
+ bufferMB?: number | undefined;
250
+ streamTimeoutMS?: number | undefined;
251
+ }): Promise<(req: Request$1 & any, res: Response & any, next: NextFunction & any) => Promise<any>>;
252
+ private static fileFilter;
253
+ private getFileSize;
254
+ getUploadFileMW(directory?: string, { acl, maxFileSize, filename: _filename, fileType, fileExt, metadata: customMetadata, }?: S3UploadOptions): Multer;
255
+ /**
256
+ * Middleware for uploading a single file
257
+ * Adds the uploaded file info to req.s3File
258
+ */
259
+ uploadSingleFile(fieldName: string, directory: string, options?: S3UploadOptions): (req: Request$1 & {
260
+ s3File?: UploadedS3File;
261
+ } & any, res: Response, next: NextFunction & any) => void;
262
+ /**
263
+ * Middleware for uploading multiple files with the same field name
264
+ * Adds the uploaded files info to req.s3Files
265
+ */
266
+ uploadMultipleFiles(fieldName: string, directory: string, options?: S3UploadOptions): (req: Request$1 & {
267
+ s3Files?: UploadedS3File[];
268
+ } & any, res: Response, next: NextFunction & any) => void;
269
+ /**
270
+ * Middleware for uploading multiple files with different field names
271
+ * Adds the uploaded files info to req.s3FilesByField
272
+ */
273
+ uploadFieldsFiles(fields: Array<{
274
+ name: string;
275
+ directory: string;
276
+ maxCount?: number;
277
+ options?: S3UploadOptions;
278
+ }>): RequestHandler;
279
+ /**
280
+ * Middleware for uploading any files (mixed field names)
281
+ * Adds the uploaded files info to req.s3AllFiles
282
+ */
283
+ uploadAnyFiles(directory: string, maxCount?: number, options?: S3UploadOptions): RequestHandler;
284
+ }
285
+
286
+ declare class SNSUtil<T> {
287
+ private readonly sns;
288
+ private readonly topicArn;
289
+ constructor({ accessKeyId, secretAccessKey, endpoint, region, topicArn, debug, }: {
290
+ topicArn: string;
291
+ accessKeyId?: string;
292
+ secretAccessKey?: string;
293
+ endpoint?: string;
294
+ region?: string;
295
+ debug?: boolean;
296
+ });
297
+ publishTopicMessage(message: T): Promise<void>;
298
+ }
299
+
300
+ declare class AWSConfigSharingUtil {
301
+ static accessKeyId: string;
302
+ static secretAccessKey: string;
303
+ static endpoint: string;
304
+ static region: string;
305
+ constructor();
306
+ static setConfig({ accessKeyId, secretAccessKey, endpoint, region, }: {
307
+ accessKeyId?: string | undefined;
308
+ secretAccessKey?: string | undefined;
309
+ endpoint?: string | undefined;
310
+ region?: string | undefined;
311
+ }): void;
312
+ static getConfig(): {
313
+ accessKeyId: string;
314
+ secretAccessKey: string;
315
+ region: string;
316
+ endpoint: string;
317
+ };
318
+ }
319
+
320
+ export { ACLs, AWSConfigSharingUtil, type BucketInfo, type FILE_EXT, type FILE_TYPE, IAMUtil, LambdaUtil, S3BucketUtil, SNSUtil, type TreeDirectoryItem, type TreeFileItem, type UploadedS3File };