@settlemint/sdk-minio 2.1.5-pr3ad019ac → 2.1.5-pr7397fec3
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.
- package/README.md +267 -0
- package/dist/minio.cjs +34 -57
- package/dist/minio.cjs.map +1 -1
- package/dist/minio.d.cts +30 -190
- package/dist/minio.d.ts +30 -190
- package/dist/minio.mjs +33 -48
- package/dist/minio.mjs.map +1 -1
- package/package.json +2 -2
package/dist/minio.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client
|
|
1
|
+
import { Client } from 'minio';
|
|
2
2
|
export { Client, ItemBucketMetadata } from 'minio';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { Buffer } from 'node:buffer';
|
|
@@ -28,178 +28,38 @@ declare const ServerClientOptionsSchema: z.ZodObject<{
|
|
|
28
28
|
type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @template T The return type of the operation
|
|
34
|
-
*/
|
|
35
|
-
interface MinioOperation<T> {
|
|
36
|
-
execute: (client: Client) => Promise<T>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Creates an operation to list objects in a bucket
|
|
40
|
-
*
|
|
41
|
-
* @param bucket - The bucket name to list objects from
|
|
42
|
-
* @param prefix - Optional prefix to filter objects (like a folder path)
|
|
43
|
-
* @returns A MinioOperation that lists objects when executed
|
|
44
|
-
* @throws Will throw an error if the operation fails
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* import { createListObjectsOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
48
|
-
*
|
|
49
|
-
* const listOperation = createListObjectsOperation("my-bucket", "folder/");
|
|
50
|
-
* const objects = await executeMinioOperation(client, listOperation);
|
|
51
|
-
*/
|
|
52
|
-
declare function createListObjectsOperation(bucket: string, prefix?: string): MinioOperation<Array<{
|
|
53
|
-
name: string;
|
|
54
|
-
prefix?: string;
|
|
55
|
-
size: number;
|
|
56
|
-
etag: string;
|
|
57
|
-
lastModified: Date;
|
|
58
|
-
}>>;
|
|
59
|
-
/**
|
|
60
|
-
* Creates an operation to get an object's metadata
|
|
61
|
-
*
|
|
62
|
-
* @param bucket - The bucket name containing the object
|
|
63
|
-
* @param objectName - The object name/path
|
|
64
|
-
* @returns A MinioOperation that gets object stats when executed
|
|
65
|
-
* @throws Will throw an error if the operation fails
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* import { createStatObjectOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
69
|
-
*
|
|
70
|
-
* const statOperation = createStatObjectOperation("my-bucket", "folder/file.txt");
|
|
71
|
-
* const stats = await executeMinioOperation(client, statOperation);
|
|
72
|
-
*/
|
|
73
|
-
declare function createStatObjectOperation(bucket: string, objectName: string): MinioOperation<{
|
|
74
|
-
size: number;
|
|
75
|
-
etag: string;
|
|
76
|
-
metaData: Record<string, string>;
|
|
77
|
-
lastModified: Date;
|
|
78
|
-
}>;
|
|
79
|
-
/**
|
|
80
|
-
* Creates an operation to upload a buffer to MinIO
|
|
81
|
-
*
|
|
82
|
-
* @param bucket - The bucket name to upload to
|
|
83
|
-
* @param objectName - The object name/path to create
|
|
84
|
-
* @param buffer - The buffer containing the file data
|
|
85
|
-
* @param metadata - Optional metadata to attach to the object
|
|
86
|
-
* @returns A MinioOperation that uploads the buffer when executed
|
|
87
|
-
* @throws Will throw an error if the operation fails
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* import { createUploadOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
91
|
-
*
|
|
92
|
-
* const buffer = Buffer.from("file content");
|
|
93
|
-
* const uploadOperation = createUploadOperation("my-bucket", "folder/file.txt", buffer, { "content-type": "text/plain" });
|
|
94
|
-
* const result = await executeMinioOperation(client, uploadOperation);
|
|
95
|
-
*/
|
|
96
|
-
declare function createUploadOperation(bucket: string, objectName: string, buffer: Buffer, metadata?: ItemBucketMetadata): MinioOperation<{
|
|
97
|
-
etag: string;
|
|
98
|
-
}>;
|
|
99
|
-
/**
|
|
100
|
-
* Creates an operation to delete an object from MinIO
|
|
101
|
-
*
|
|
102
|
-
* @param bucket - The bucket name containing the object
|
|
103
|
-
* @param objectName - The object name/path to delete
|
|
104
|
-
* @returns A MinioOperation that deletes the object when executed
|
|
105
|
-
* @throws Will throw an error if the operation fails
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* import { createDeleteOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
109
|
-
*
|
|
110
|
-
* const deleteOperation = createDeleteOperation("my-bucket", "folder/file.txt");
|
|
111
|
-
* await executeMinioOperation(client, deleteOperation);
|
|
112
|
-
*/
|
|
113
|
-
declare function createDeleteOperation(bucket: string, objectName: string): MinioOperation<void>;
|
|
114
|
-
/**
|
|
115
|
-
* Creates an operation to generate a presigned URL for an object
|
|
116
|
-
*
|
|
117
|
-
* @param bucket - The bucket name containing the object
|
|
118
|
-
* @param objectName - The object name/path
|
|
119
|
-
* @param expirySeconds - How long the URL should be valid for in seconds
|
|
120
|
-
* @returns A MinioOperation that creates a presigned URL when executed
|
|
121
|
-
* @throws Will throw an error if the operation fails
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* import { createPresignedUrlOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
125
|
-
*
|
|
126
|
-
* const urlOperation = createPresignedUrlOperation("my-bucket", "folder/file.txt", 3600);
|
|
127
|
-
* const url = await executeMinioOperation(client, urlOperation);
|
|
128
|
-
*/
|
|
129
|
-
declare function createPresignedUrlOperation(bucket: string, objectName: string, expirySeconds: number): MinioOperation<string>;
|
|
130
|
-
/**
|
|
131
|
-
* Creates an operation to generate a presigned PUT URL for direct uploads
|
|
132
|
-
*
|
|
133
|
-
* @param bucket - The bucket name to upload to
|
|
134
|
-
* @param objectName - The object name/path to create
|
|
135
|
-
* @param expirySeconds - How long the URL should be valid for in seconds
|
|
136
|
-
* @returns A MinioOperation that creates a presigned PUT URL when executed
|
|
137
|
-
* @throws Will throw an error if the operation fails
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* import { createPresignedPutOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
141
|
-
*
|
|
142
|
-
* const putUrlOperation = createPresignedPutOperation("my-bucket", "folder/file.txt", 3600);
|
|
143
|
-
* const url = await executeMinioOperation(client, putUrlOperation);
|
|
144
|
-
*/
|
|
145
|
-
declare function createPresignedPutOperation(bucket: string, objectName: string, expirySeconds: number): MinioOperation<string>;
|
|
146
|
-
/**
|
|
147
|
-
* Creates a simplified upload function bound to a specific client
|
|
148
|
-
*
|
|
149
|
-
* @param client - The MinIO client to use for uploads
|
|
150
|
-
* @returns A function that uploads buffers to MinIO
|
|
151
|
-
* @throws Will throw an error if the operation fails
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* import { createSimpleUploadOperation, getMinioClient } from "@settlemint/sdk-minio";
|
|
155
|
-
*
|
|
156
|
-
* const client = await getMinioClient();
|
|
157
|
-
* const uploadFn = createSimpleUploadOperation(client);
|
|
158
|
-
* const result = await uploadFn(buffer, "my-bucket", "folder/file.txt", { "content-type": "text/plain" });
|
|
159
|
-
*/
|
|
160
|
-
declare function createSimpleUploadOperation(client: Client): (buffer: Buffer, bucket: string, objectName: string, metadata?: ItemBucketMetadata) => Promise<{
|
|
161
|
-
etag: string;
|
|
162
|
-
}>;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Helper type to extract the inferred type from a Zod schema.
|
|
166
|
-
*
|
|
167
|
-
* @template T - The Zod schema type
|
|
168
|
-
*/
|
|
169
|
-
type Static<T extends z.ZodType> = z.infer<T>;
|
|
170
|
-
/**
|
|
171
|
-
* Schema for file metadata stored in MinIO.
|
|
172
|
-
* Defines the structure and validation rules for file information.
|
|
31
|
+
* Type representing file metadata after validation.
|
|
173
32
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
size: z.ZodNumber;
|
|
179
|
-
uploadedAt: z.ZodString;
|
|
180
|
-
etag: z.ZodString;
|
|
181
|
-
url: z.ZodOptional<z.ZodString>;
|
|
182
|
-
}, "strip", z.ZodTypeAny, {
|
|
183
|
-
id: string;
|
|
184
|
-
name: string;
|
|
185
|
-
contentType: string;
|
|
186
|
-
size: number;
|
|
187
|
-
uploadedAt: string;
|
|
188
|
-
etag: string;
|
|
189
|
-
url?: string | undefined;
|
|
190
|
-
}, {
|
|
33
|
+
interface FileMetadata {
|
|
34
|
+
/**
|
|
35
|
+
* The unique identifier for the file.
|
|
36
|
+
*/
|
|
191
37
|
id: string;
|
|
38
|
+
/**
|
|
39
|
+
* The name of the file.
|
|
40
|
+
*/
|
|
192
41
|
name: string;
|
|
42
|
+
/**
|
|
43
|
+
* The content type of the file.
|
|
44
|
+
*/
|
|
193
45
|
contentType: string;
|
|
46
|
+
/**
|
|
47
|
+
* The size of the file in bytes.
|
|
48
|
+
*/
|
|
194
49
|
size: number;
|
|
50
|
+
/**
|
|
51
|
+
* The date and time the file was uploaded.
|
|
52
|
+
*/
|
|
195
53
|
uploadedAt: string;
|
|
54
|
+
/**
|
|
55
|
+
* The ETag of the file.
|
|
56
|
+
*/
|
|
196
57
|
etag: string;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
type FileMetadata = Static<typeof FileMetadataSchema>;
|
|
58
|
+
/**
|
|
59
|
+
* The URL of the file.
|
|
60
|
+
*/
|
|
61
|
+
url?: string;
|
|
62
|
+
}
|
|
203
63
|
/**
|
|
204
64
|
* Default bucket name to use for file storage when none is specified.
|
|
205
65
|
*/
|
|
@@ -230,7 +90,7 @@ declare function getFilesList(client: Client, prefix?: string, bucket?: string):
|
|
|
230
90
|
* Gets a single file by its object name
|
|
231
91
|
*
|
|
232
92
|
* @param client - The MinIO client to use
|
|
233
|
-
* @param
|
|
93
|
+
* @param fileId - The file identifier/path
|
|
234
94
|
* @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)
|
|
235
95
|
* @returns File metadata with presigned URL
|
|
236
96
|
* @throws Will throw an error if the file doesn't exist or client initialization fails
|
|
@@ -246,12 +106,12 @@ declare function getFilesList(client: Client, prefix?: string, bucket?: string):
|
|
|
246
106
|
*
|
|
247
107
|
* const file = await getFileByObjectName(client, "documents/report.pdf");
|
|
248
108
|
*/
|
|
249
|
-
declare function
|
|
109
|
+
declare function getFileById(client: Client, fileId: string, bucket?: string): Promise<FileMetadata>;
|
|
250
110
|
/**
|
|
251
111
|
* Deletes a file from storage
|
|
252
112
|
*
|
|
253
113
|
* @param client - The MinIO client to use
|
|
254
|
-
* @param fileId - The file identifier/path
|
|
114
|
+
* @param fileId - The file identifier/path
|
|
255
115
|
* @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)
|
|
256
116
|
* @returns Success status
|
|
257
117
|
* @throws Will throw an error if deletion fails or client initialization fails
|
|
@@ -329,26 +189,6 @@ declare function createPresignedUploadUrl(client: Client, fileName: string, path
|
|
|
329
189
|
*/
|
|
330
190
|
declare function uploadFile(client: Client, buffer: Buffer, objectName: string, contentType: string, bucket?: string): Promise<FileMetadata>;
|
|
331
191
|
|
|
332
|
-
/**
|
|
333
|
-
* Executes a MinIO operation using the provided client
|
|
334
|
-
*
|
|
335
|
-
* @param client - MinIO client to use
|
|
336
|
-
* @param operation - The operation to execute
|
|
337
|
-
* @returns The result of the operation execution
|
|
338
|
-
* @throws Will throw an error if the operation fails
|
|
339
|
-
*
|
|
340
|
-
* @example
|
|
341
|
-
* import { createServerMinioClient, createListObjectsOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
342
|
-
* const { client } = createServerMinioClient({
|
|
343
|
-
* instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
|
|
344
|
-
* accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
|
|
345
|
-
* secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
|
|
346
|
-
* });
|
|
347
|
-
* const listOperation = createListObjectsOperation("my-bucket", "prefix/");
|
|
348
|
-
* const result = await executeMinioOperation(client, listOperation);
|
|
349
|
-
*/
|
|
350
|
-
declare function executeMinioOperation<T>(client: Client, operation: MinioOperation<T>): Promise<T>;
|
|
351
|
-
|
|
352
192
|
/**
|
|
353
193
|
* Creates a MinIO client for server-side use with authentication.
|
|
354
194
|
*
|
|
@@ -370,4 +210,4 @@ declare function createServerMinioClient(options: ServerClientOptions): {
|
|
|
370
210
|
client: Client;
|
|
371
211
|
};
|
|
372
212
|
|
|
373
|
-
export { DEFAULT_BUCKET, type FileMetadata,
|
|
213
|
+
export { DEFAULT_BUCKET, type FileMetadata, createPresignedUploadUrl, createServerMinioClient, deleteFile, getFileById, getFilesList, uploadFile };
|
package/dist/minio.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client
|
|
1
|
+
import { Client } from 'minio';
|
|
2
2
|
export { Client, ItemBucketMetadata } from 'minio';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { Buffer } from 'node:buffer';
|
|
@@ -28,178 +28,38 @@ declare const ServerClientOptionsSchema: z.ZodObject<{
|
|
|
28
28
|
type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @template T The return type of the operation
|
|
34
|
-
*/
|
|
35
|
-
interface MinioOperation<T> {
|
|
36
|
-
execute: (client: Client) => Promise<T>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Creates an operation to list objects in a bucket
|
|
40
|
-
*
|
|
41
|
-
* @param bucket - The bucket name to list objects from
|
|
42
|
-
* @param prefix - Optional prefix to filter objects (like a folder path)
|
|
43
|
-
* @returns A MinioOperation that lists objects when executed
|
|
44
|
-
* @throws Will throw an error if the operation fails
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* import { createListObjectsOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
48
|
-
*
|
|
49
|
-
* const listOperation = createListObjectsOperation("my-bucket", "folder/");
|
|
50
|
-
* const objects = await executeMinioOperation(client, listOperation);
|
|
51
|
-
*/
|
|
52
|
-
declare function createListObjectsOperation(bucket: string, prefix?: string): MinioOperation<Array<{
|
|
53
|
-
name: string;
|
|
54
|
-
prefix?: string;
|
|
55
|
-
size: number;
|
|
56
|
-
etag: string;
|
|
57
|
-
lastModified: Date;
|
|
58
|
-
}>>;
|
|
59
|
-
/**
|
|
60
|
-
* Creates an operation to get an object's metadata
|
|
61
|
-
*
|
|
62
|
-
* @param bucket - The bucket name containing the object
|
|
63
|
-
* @param objectName - The object name/path
|
|
64
|
-
* @returns A MinioOperation that gets object stats when executed
|
|
65
|
-
* @throws Will throw an error if the operation fails
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* import { createStatObjectOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
69
|
-
*
|
|
70
|
-
* const statOperation = createStatObjectOperation("my-bucket", "folder/file.txt");
|
|
71
|
-
* const stats = await executeMinioOperation(client, statOperation);
|
|
72
|
-
*/
|
|
73
|
-
declare function createStatObjectOperation(bucket: string, objectName: string): MinioOperation<{
|
|
74
|
-
size: number;
|
|
75
|
-
etag: string;
|
|
76
|
-
metaData: Record<string, string>;
|
|
77
|
-
lastModified: Date;
|
|
78
|
-
}>;
|
|
79
|
-
/**
|
|
80
|
-
* Creates an operation to upload a buffer to MinIO
|
|
81
|
-
*
|
|
82
|
-
* @param bucket - The bucket name to upload to
|
|
83
|
-
* @param objectName - The object name/path to create
|
|
84
|
-
* @param buffer - The buffer containing the file data
|
|
85
|
-
* @param metadata - Optional metadata to attach to the object
|
|
86
|
-
* @returns A MinioOperation that uploads the buffer when executed
|
|
87
|
-
* @throws Will throw an error if the operation fails
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* import { createUploadOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
91
|
-
*
|
|
92
|
-
* const buffer = Buffer.from("file content");
|
|
93
|
-
* const uploadOperation = createUploadOperation("my-bucket", "folder/file.txt", buffer, { "content-type": "text/plain" });
|
|
94
|
-
* const result = await executeMinioOperation(client, uploadOperation);
|
|
95
|
-
*/
|
|
96
|
-
declare function createUploadOperation(bucket: string, objectName: string, buffer: Buffer, metadata?: ItemBucketMetadata): MinioOperation<{
|
|
97
|
-
etag: string;
|
|
98
|
-
}>;
|
|
99
|
-
/**
|
|
100
|
-
* Creates an operation to delete an object from MinIO
|
|
101
|
-
*
|
|
102
|
-
* @param bucket - The bucket name containing the object
|
|
103
|
-
* @param objectName - The object name/path to delete
|
|
104
|
-
* @returns A MinioOperation that deletes the object when executed
|
|
105
|
-
* @throws Will throw an error if the operation fails
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* import { createDeleteOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
109
|
-
*
|
|
110
|
-
* const deleteOperation = createDeleteOperation("my-bucket", "folder/file.txt");
|
|
111
|
-
* await executeMinioOperation(client, deleteOperation);
|
|
112
|
-
*/
|
|
113
|
-
declare function createDeleteOperation(bucket: string, objectName: string): MinioOperation<void>;
|
|
114
|
-
/**
|
|
115
|
-
* Creates an operation to generate a presigned URL for an object
|
|
116
|
-
*
|
|
117
|
-
* @param bucket - The bucket name containing the object
|
|
118
|
-
* @param objectName - The object name/path
|
|
119
|
-
* @param expirySeconds - How long the URL should be valid for in seconds
|
|
120
|
-
* @returns A MinioOperation that creates a presigned URL when executed
|
|
121
|
-
* @throws Will throw an error if the operation fails
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* import { createPresignedUrlOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
125
|
-
*
|
|
126
|
-
* const urlOperation = createPresignedUrlOperation("my-bucket", "folder/file.txt", 3600);
|
|
127
|
-
* const url = await executeMinioOperation(client, urlOperation);
|
|
128
|
-
*/
|
|
129
|
-
declare function createPresignedUrlOperation(bucket: string, objectName: string, expirySeconds: number): MinioOperation<string>;
|
|
130
|
-
/**
|
|
131
|
-
* Creates an operation to generate a presigned PUT URL for direct uploads
|
|
132
|
-
*
|
|
133
|
-
* @param bucket - The bucket name to upload to
|
|
134
|
-
* @param objectName - The object name/path to create
|
|
135
|
-
* @param expirySeconds - How long the URL should be valid for in seconds
|
|
136
|
-
* @returns A MinioOperation that creates a presigned PUT URL when executed
|
|
137
|
-
* @throws Will throw an error if the operation fails
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* import { createPresignedPutOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
141
|
-
*
|
|
142
|
-
* const putUrlOperation = createPresignedPutOperation("my-bucket", "folder/file.txt", 3600);
|
|
143
|
-
* const url = await executeMinioOperation(client, putUrlOperation);
|
|
144
|
-
*/
|
|
145
|
-
declare function createPresignedPutOperation(bucket: string, objectName: string, expirySeconds: number): MinioOperation<string>;
|
|
146
|
-
/**
|
|
147
|
-
* Creates a simplified upload function bound to a specific client
|
|
148
|
-
*
|
|
149
|
-
* @param client - The MinIO client to use for uploads
|
|
150
|
-
* @returns A function that uploads buffers to MinIO
|
|
151
|
-
* @throws Will throw an error if the operation fails
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* import { createSimpleUploadOperation, getMinioClient } from "@settlemint/sdk-minio";
|
|
155
|
-
*
|
|
156
|
-
* const client = await getMinioClient();
|
|
157
|
-
* const uploadFn = createSimpleUploadOperation(client);
|
|
158
|
-
* const result = await uploadFn(buffer, "my-bucket", "folder/file.txt", { "content-type": "text/plain" });
|
|
159
|
-
*/
|
|
160
|
-
declare function createSimpleUploadOperation(client: Client): (buffer: Buffer, bucket: string, objectName: string, metadata?: ItemBucketMetadata) => Promise<{
|
|
161
|
-
etag: string;
|
|
162
|
-
}>;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Helper type to extract the inferred type from a Zod schema.
|
|
166
|
-
*
|
|
167
|
-
* @template T - The Zod schema type
|
|
168
|
-
*/
|
|
169
|
-
type Static<T extends z.ZodType> = z.infer<T>;
|
|
170
|
-
/**
|
|
171
|
-
* Schema for file metadata stored in MinIO.
|
|
172
|
-
* Defines the structure and validation rules for file information.
|
|
31
|
+
* Type representing file metadata after validation.
|
|
173
32
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
size: z.ZodNumber;
|
|
179
|
-
uploadedAt: z.ZodString;
|
|
180
|
-
etag: z.ZodString;
|
|
181
|
-
url: z.ZodOptional<z.ZodString>;
|
|
182
|
-
}, "strip", z.ZodTypeAny, {
|
|
183
|
-
id: string;
|
|
184
|
-
name: string;
|
|
185
|
-
contentType: string;
|
|
186
|
-
size: number;
|
|
187
|
-
uploadedAt: string;
|
|
188
|
-
etag: string;
|
|
189
|
-
url?: string | undefined;
|
|
190
|
-
}, {
|
|
33
|
+
interface FileMetadata {
|
|
34
|
+
/**
|
|
35
|
+
* The unique identifier for the file.
|
|
36
|
+
*/
|
|
191
37
|
id: string;
|
|
38
|
+
/**
|
|
39
|
+
* The name of the file.
|
|
40
|
+
*/
|
|
192
41
|
name: string;
|
|
42
|
+
/**
|
|
43
|
+
* The content type of the file.
|
|
44
|
+
*/
|
|
193
45
|
contentType: string;
|
|
46
|
+
/**
|
|
47
|
+
* The size of the file in bytes.
|
|
48
|
+
*/
|
|
194
49
|
size: number;
|
|
50
|
+
/**
|
|
51
|
+
* The date and time the file was uploaded.
|
|
52
|
+
*/
|
|
195
53
|
uploadedAt: string;
|
|
54
|
+
/**
|
|
55
|
+
* The ETag of the file.
|
|
56
|
+
*/
|
|
196
57
|
etag: string;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
type FileMetadata = Static<typeof FileMetadataSchema>;
|
|
58
|
+
/**
|
|
59
|
+
* The URL of the file.
|
|
60
|
+
*/
|
|
61
|
+
url?: string;
|
|
62
|
+
}
|
|
203
63
|
/**
|
|
204
64
|
* Default bucket name to use for file storage when none is specified.
|
|
205
65
|
*/
|
|
@@ -230,7 +90,7 @@ declare function getFilesList(client: Client, prefix?: string, bucket?: string):
|
|
|
230
90
|
* Gets a single file by its object name
|
|
231
91
|
*
|
|
232
92
|
* @param client - The MinIO client to use
|
|
233
|
-
* @param
|
|
93
|
+
* @param fileId - The file identifier/path
|
|
234
94
|
* @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)
|
|
235
95
|
* @returns File metadata with presigned URL
|
|
236
96
|
* @throws Will throw an error if the file doesn't exist or client initialization fails
|
|
@@ -246,12 +106,12 @@ declare function getFilesList(client: Client, prefix?: string, bucket?: string):
|
|
|
246
106
|
*
|
|
247
107
|
* const file = await getFileByObjectName(client, "documents/report.pdf");
|
|
248
108
|
*/
|
|
249
|
-
declare function
|
|
109
|
+
declare function getFileById(client: Client, fileId: string, bucket?: string): Promise<FileMetadata>;
|
|
250
110
|
/**
|
|
251
111
|
* Deletes a file from storage
|
|
252
112
|
*
|
|
253
113
|
* @param client - The MinIO client to use
|
|
254
|
-
* @param fileId - The file identifier/path
|
|
114
|
+
* @param fileId - The file identifier/path
|
|
255
115
|
* @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)
|
|
256
116
|
* @returns Success status
|
|
257
117
|
* @throws Will throw an error if deletion fails or client initialization fails
|
|
@@ -329,26 +189,6 @@ declare function createPresignedUploadUrl(client: Client, fileName: string, path
|
|
|
329
189
|
*/
|
|
330
190
|
declare function uploadFile(client: Client, buffer: Buffer, objectName: string, contentType: string, bucket?: string): Promise<FileMetadata>;
|
|
331
191
|
|
|
332
|
-
/**
|
|
333
|
-
* Executes a MinIO operation using the provided client
|
|
334
|
-
*
|
|
335
|
-
* @param client - MinIO client to use
|
|
336
|
-
* @param operation - The operation to execute
|
|
337
|
-
* @returns The result of the operation execution
|
|
338
|
-
* @throws Will throw an error if the operation fails
|
|
339
|
-
*
|
|
340
|
-
* @example
|
|
341
|
-
* import { createServerMinioClient, createListObjectsOperation, executeMinioOperation } from "@settlemint/sdk-minio";
|
|
342
|
-
* const { client } = createServerMinioClient({
|
|
343
|
-
* instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
|
|
344
|
-
* accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
|
|
345
|
-
* secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
|
|
346
|
-
* });
|
|
347
|
-
* const listOperation = createListObjectsOperation("my-bucket", "prefix/");
|
|
348
|
-
* const result = await executeMinioOperation(client, listOperation);
|
|
349
|
-
*/
|
|
350
|
-
declare function executeMinioOperation<T>(client: Client, operation: MinioOperation<T>): Promise<T>;
|
|
351
|
-
|
|
352
192
|
/**
|
|
353
193
|
* Creates a MinIO client for server-side use with authentication.
|
|
354
194
|
*
|
|
@@ -370,4 +210,4 @@ declare function createServerMinioClient(options: ServerClientOptions): {
|
|
|
370
210
|
client: Client;
|
|
371
211
|
};
|
|
372
212
|
|
|
373
|
-
export { DEFAULT_BUCKET, type FileMetadata,
|
|
213
|
+
export { DEFAULT_BUCKET, type FileMetadata, createPresignedUploadUrl, createServerMinioClient, deleteFile, getFileById, getFilesList, uploadFile };
|
package/dist/minio.mjs
CHANGED
|
@@ -15,6 +15,30 @@ var ServerClientOptionsSchema = z.object({
|
|
|
15
15
|
secretKey: z.string()
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
// src/helpers/schema.ts
|
|
19
|
+
import { z as z2 } from "zod";
|
|
20
|
+
var FileMetadataSchema = z2.object({
|
|
21
|
+
id: z2.string(),
|
|
22
|
+
name: z2.string(),
|
|
23
|
+
contentType: z2.string(),
|
|
24
|
+
size: z2.number(),
|
|
25
|
+
uploadedAt: z2.string().datetime(),
|
|
26
|
+
etag: z2.string(),
|
|
27
|
+
url: z2.string().url().optional()
|
|
28
|
+
});
|
|
29
|
+
var DEFAULT_BUCKET = "uploads";
|
|
30
|
+
|
|
31
|
+
// src/helpers/functions.ts
|
|
32
|
+
import { ensureServer as ensureServer2 } from "@settlemint/sdk-utils/runtime";
|
|
33
|
+
import { validate } from "@settlemint/sdk-utils/validation";
|
|
34
|
+
|
|
35
|
+
// src/helpers/executor.ts
|
|
36
|
+
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
37
|
+
async function executeMinioOperation(client, operation) {
|
|
38
|
+
ensureServer();
|
|
39
|
+
return operation.execute(client);
|
|
40
|
+
}
|
|
41
|
+
|
|
18
42
|
// src/helpers/operations.ts
|
|
19
43
|
function createListObjectsOperation(bucket, prefix = "") {
|
|
20
44
|
return {
|
|
@@ -50,13 +74,6 @@ function createStatObjectOperation(bucket, objectName) {
|
|
|
50
74
|
}
|
|
51
75
|
};
|
|
52
76
|
}
|
|
53
|
-
function createUploadOperation(bucket, objectName, buffer, metadata) {
|
|
54
|
-
return {
|
|
55
|
-
execute: async (client) => {
|
|
56
|
-
return client.putObject(bucket, objectName, buffer, void 0, metadata);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
77
|
function createDeleteOperation(bucket, objectName) {
|
|
61
78
|
return {
|
|
62
79
|
execute: async (client) => {
|
|
@@ -84,30 +101,6 @@ function createSimpleUploadOperation(client) {
|
|
|
84
101
|
};
|
|
85
102
|
}
|
|
86
103
|
|
|
87
|
-
// src/helpers/functions.ts
|
|
88
|
-
import { ensureServer as ensureServer2 } from "@settlemint/sdk-utils/runtime";
|
|
89
|
-
import { validate } from "@settlemint/sdk-utils/validation";
|
|
90
|
-
|
|
91
|
-
// src/helpers/executor.ts
|
|
92
|
-
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
93
|
-
async function executeMinioOperation(client, operation) {
|
|
94
|
-
ensureServer();
|
|
95
|
-
return operation.execute(client);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// src/helpers/schema.ts
|
|
99
|
-
import { z as z2 } from "zod";
|
|
100
|
-
var FileMetadataSchema = z2.object({
|
|
101
|
-
id: z2.string(),
|
|
102
|
-
name: z2.string(),
|
|
103
|
-
contentType: z2.string(),
|
|
104
|
-
size: z2.number(),
|
|
105
|
-
uploadedAt: z2.string().datetime(),
|
|
106
|
-
etag: z2.string(),
|
|
107
|
-
url: z2.string().url().optional()
|
|
108
|
-
});
|
|
109
|
-
var DEFAULT_BUCKET = "uploads";
|
|
110
|
-
|
|
111
104
|
// src/helpers/functions.ts
|
|
112
105
|
function normalizePath(path, fileName) {
|
|
113
106
|
if (path.length > 1e3) {
|
|
@@ -153,15 +146,15 @@ async function getFilesList(client, prefix = "", bucket = DEFAULT_BUCKET) {
|
|
|
153
146
|
throw new Error(`Failed to list files: ${error instanceof Error ? error.message : String(error)}`);
|
|
154
147
|
}
|
|
155
148
|
}
|
|
156
|
-
async function
|
|
149
|
+
async function getFileById(client, fileId, bucket = DEFAULT_BUCKET) {
|
|
157
150
|
ensureServer2();
|
|
158
|
-
console.log(`Getting file details for: ${
|
|
151
|
+
console.log(`Getting file details for: ${fileId} in bucket: ${bucket}`);
|
|
159
152
|
try {
|
|
160
|
-
const statOperation = createStatObjectOperation(bucket,
|
|
153
|
+
const statOperation = createStatObjectOperation(bucket, fileId);
|
|
161
154
|
const statResult = await executeMinioOperation(client, statOperation);
|
|
162
155
|
const presignedUrlOperation = createPresignedUrlOperation(
|
|
163
156
|
bucket,
|
|
164
|
-
|
|
157
|
+
fileId,
|
|
165
158
|
3600
|
|
166
159
|
// 1 hour expiry
|
|
167
160
|
);
|
|
@@ -176,8 +169,8 @@ async function getFileByObjectName(client, objectName, bucket = DEFAULT_BUCKET)
|
|
|
176
169
|
size = statResult.size;
|
|
177
170
|
}
|
|
178
171
|
const fileMetadata = {
|
|
179
|
-
id:
|
|
180
|
-
name:
|
|
172
|
+
id: fileId,
|
|
173
|
+
name: fileId.split("/").pop() || fileId,
|
|
181
174
|
contentType: statResult.metaData["content-type"] || "application/octet-stream",
|
|
182
175
|
size,
|
|
183
176
|
uploadedAt: statResult.lastModified.toISOString(),
|
|
@@ -186,8 +179,8 @@ async function getFileByObjectName(client, objectName, bucket = DEFAULT_BUCKET)
|
|
|
186
179
|
};
|
|
187
180
|
return validate(FileMetadataSchema, fileMetadata);
|
|
188
181
|
} catch (error) {
|
|
189
|
-
console.error(`Failed to get file ${
|
|
190
|
-
throw new Error(`Failed to get file ${
|
|
182
|
+
console.error(`Failed to get file ${fileId}:`, error);
|
|
183
|
+
throw new Error(`Failed to get file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
191
184
|
}
|
|
192
185
|
}
|
|
193
186
|
async function deleteFile(client, fileId, bucket = DEFAULT_BUCKET) {
|
|
@@ -268,18 +261,10 @@ function createServerMinioClient(options) {
|
|
|
268
261
|
}
|
|
269
262
|
export {
|
|
270
263
|
DEFAULT_BUCKET,
|
|
271
|
-
createDeleteOperation,
|
|
272
|
-
createListObjectsOperation,
|
|
273
|
-
createPresignedPutOperation,
|
|
274
264
|
createPresignedUploadUrl,
|
|
275
|
-
createPresignedUrlOperation,
|
|
276
265
|
createServerMinioClient,
|
|
277
|
-
createSimpleUploadOperation,
|
|
278
|
-
createStatObjectOperation,
|
|
279
|
-
createUploadOperation,
|
|
280
266
|
deleteFile,
|
|
281
|
-
|
|
282
|
-
getFileByObjectName,
|
|
267
|
+
getFileById,
|
|
283
268
|
getFilesList,
|
|
284
269
|
uploadFile
|
|
285
270
|
};
|