@settlemint/sdk-minio 2.1.4 → 2.1.5-pr594fad44

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 CHANGED
@@ -29,7 +29,18 @@
29
29
  - [About](#about)
30
30
  - [API Reference](#api-reference)
31
31
  - [Functions](#functions)
32
+ - [createPresignedUploadUrl()](#createpresigneduploadurl)
32
33
  - [createServerMinioClient()](#createserverminioclient)
34
+ - [deleteFile()](#deletefile)
35
+ - [getFileById()](#getfilebyid)
36
+ - [getFilesList()](#getfileslist)
37
+ - [uploadFile()](#uploadfile)
38
+ - [Type Aliases](#type-aliases)
39
+ - [FileMetadata](#filemetadata)
40
+ - [Static\<T\>](#statict)
41
+ - [Variables](#variables)
42
+ - [DEFAULT\_BUCKET](#default_bucket)
43
+ - [FileMetadataSchema](#filemetadataschema)
33
44
  - [Contributing](#contributing)
34
45
  - [License](#license)
35
46
 
@@ -43,11 +54,68 @@ For detailed information about using MinIO with the SettleMint platform, check o
43
54
 
44
55
  ### Functions
45
56
 
57
+ #### createPresignedUploadUrl()
58
+
59
+ > **createPresignedUploadUrl**(`client`, `fileName`, `path`, `bucket`, `expirySeconds`): `Promise`\<`string`\>
60
+
61
+ Defined in: [sdk/minio/src/helpers/functions.ts:242](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/helpers/functions.ts#L242)
62
+
63
+ Creates a presigned upload URL for direct browser uploads
64
+
65
+ ##### Parameters
66
+
67
+ | Parameter | Type | Default value | Description |
68
+ | ------ | ------ | ------ | ------ |
69
+ | `client` | `Client` | `undefined` | The MinIO client to use |
70
+ | `fileName` | `string` | `undefined` | The file name to use |
71
+ | `path` | `string` | `""` | Optional path/folder |
72
+ | `bucket` | `string` | `DEFAULT_BUCKET` | Optional bucket name (defaults to DEFAULT_BUCKET) |
73
+ | `expirySeconds` | `number` | `3600` | How long the URL should be valid for |
74
+
75
+ ##### Returns
76
+
77
+ `Promise`\<`string`\>
78
+
79
+ Presigned URL for PUT operation
80
+
81
+ ##### Throws
82
+
83
+ Will throw an error if URL creation fails or client initialization fails
84
+
85
+ ##### Example
86
+
87
+ ```ts
88
+ import { createServerMinioClient, createPresignedUploadUrl } from "@settlemint/sdk-minio";
89
+
90
+ const { client } = createServerMinioClient({
91
+ instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
92
+ accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
93
+ secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
94
+ });
95
+
96
+ // Generate the presigned URL on the server
97
+ const url = await createPresignedUploadUrl(client, "report.pdf", "documents/");
98
+
99
+ // Send the URL to the client/browser via HTTP response
100
+ return Response.json({ uploadUrl: url });
101
+
102
+ // Then in the browser:
103
+ const response = await fetch('/api/get-upload-url');
104
+ const { uploadUrl } = await response.json();
105
+ await fetch(uploadUrl, {
106
+ method: 'PUT',
107
+ headers: { 'Content-Type': 'application/pdf' },
108
+ body: pdfFile
109
+ });
110
+ ```
111
+
112
+ ***
113
+
46
114
  #### createServerMinioClient()
47
115
 
48
116
  > **createServerMinioClient**(`options`): `object`
49
117
 
50
- Defined in: [sdk/minio/src/minio.ts:23](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/minio.ts#L23)
118
+ Defined in: [sdk/minio/src/minio.ts:23](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/minio.ts#L23)
51
119
 
52
120
  Creates a MinIO client for server-side use with authentication.
53
121
 
@@ -68,7 +136,7 @@ An object containing the initialized MinIO client
68
136
 
69
137
  | Name | Type | Defined in |
70
138
  | ------ | ------ | ------ |
71
- | `client` | `Client` | [sdk/minio/src/minio.ts:23](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/minio.ts#L23) |
139
+ | `client` | `Client` | [sdk/minio/src/minio.ts:23](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/minio.ts#L23) |
72
140
 
73
141
  ##### Throws
74
142
 
@@ -87,6 +155,224 @@ const { client } = createServerMinioClient({
87
155
  client.listBuckets();
88
156
  ```
89
157
 
158
+ ***
159
+
160
+ #### deleteFile()
161
+
162
+ > **deleteFile**(`client`, `fileId`, `bucket`): `Promise`\<`boolean`\>
163
+
164
+ Defined in: [sdk/minio/src/helpers/functions.ts:195](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/helpers/functions.ts#L195)
165
+
166
+ Deletes a file from storage
167
+
168
+ ##### Parameters
169
+
170
+ | Parameter | Type | Default value | Description |
171
+ | ------ | ------ | ------ | ------ |
172
+ | `client` | `Client` | `undefined` | The MinIO client to use |
173
+ | `fileId` | `string` | `undefined` | The file identifier/path |
174
+ | `bucket` | `string` | `DEFAULT_BUCKET` | Optional bucket name (defaults to DEFAULT_BUCKET) |
175
+
176
+ ##### Returns
177
+
178
+ `Promise`\<`boolean`\>
179
+
180
+ Success status
181
+
182
+ ##### Throws
183
+
184
+ Will throw an error if deletion fails or client initialization fails
185
+
186
+ ##### Example
187
+
188
+ ```ts
189
+ import { createServerMinioClient, deleteFile } from "@settlemint/sdk-minio";
190
+
191
+ const { client } = createServerMinioClient({
192
+ instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
193
+ accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
194
+ secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
195
+ });
196
+
197
+ await deleteFile(client, "documents/report.pdf");
198
+ ```
199
+
200
+ ***
201
+
202
+ #### getFileById()
203
+
204
+ > **getFileById**(`client`, `fileId`, `bucket`): `Promise`\<\{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}\>
205
+
206
+ Defined in: [sdk/minio/src/helpers/functions.ts:122](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/helpers/functions.ts#L122)
207
+
208
+ Gets a single file by its object name
209
+
210
+ ##### Parameters
211
+
212
+ | Parameter | Type | Default value | Description |
213
+ | ------ | ------ | ------ | ------ |
214
+ | `client` | `Client` | `undefined` | The MinIO client to use |
215
+ | `fileId` | `string` | `undefined` | The file identifier/path |
216
+ | `bucket` | `string` | `DEFAULT_BUCKET` | Optional bucket name (defaults to DEFAULT_BUCKET) |
217
+
218
+ ##### Returns
219
+
220
+ `Promise`\<\{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}\>
221
+
222
+ File metadata with presigned URL
223
+
224
+ ##### Throws
225
+
226
+ Will throw an error if the file doesn't exist or client initialization fails
227
+
228
+ ##### Example
229
+
230
+ ```ts
231
+ import { createServerMinioClient, getFileByObjectName } from "@settlemint/sdk-minio";
232
+
233
+ const { client } = createServerMinioClient({
234
+ instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
235
+ accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
236
+ secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
237
+ });
238
+
239
+ const file = await getFileByObjectName(client, "documents/report.pdf");
240
+ ```
241
+
242
+ ***
243
+
244
+ #### getFilesList()
245
+
246
+ > **getFilesList**(`client`, `prefix`, `bucket`): `Promise`\<`object`[]\>
247
+
248
+ Defined in: [sdk/minio/src/helpers/functions.ts:61](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/helpers/functions.ts#L61)
249
+
250
+ Gets a list of files with optional prefix filter
251
+
252
+ ##### Parameters
253
+
254
+ | Parameter | Type | Default value | Description |
255
+ | ------ | ------ | ------ | ------ |
256
+ | `client` | `Client` | `undefined` | The MinIO client to use |
257
+ | `prefix` | `string` | `""` | Optional prefix to filter files (like a folder path) |
258
+ | `bucket` | `string` | `DEFAULT_BUCKET` | Optional bucket name (defaults to DEFAULT_BUCKET) |
259
+
260
+ ##### Returns
261
+
262
+ `Promise`\<`object`[]\>
263
+
264
+ Array of file metadata objects
265
+
266
+ ##### Throws
267
+
268
+ Will throw an error if the operation fails or client initialization fails
269
+
270
+ ##### Example
271
+
272
+ ```ts
273
+ import { createServerMinioClient, getFilesList } from "@settlemint/sdk-minio";
274
+
275
+ const { client } = createServerMinioClient({
276
+ instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
277
+ accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
278
+ secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
279
+ });
280
+
281
+ const files = await getFilesList(client, "documents/");
282
+ ```
283
+
284
+ ***
285
+
286
+ #### uploadFile()
287
+
288
+ > **uploadFile**(`client`, `buffer`, `objectName`, `contentType`, `bucket`): `Promise`\<\{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}\>
289
+
290
+ Defined in: [sdk/minio/src/helpers/functions.ts:292](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/helpers/functions.ts#L292)
291
+
292
+ Uploads a buffer directly to storage
293
+
294
+ ##### Parameters
295
+
296
+ | Parameter | Type | Default value | Description |
297
+ | ------ | ------ | ------ | ------ |
298
+ | `client` | `Client` | `undefined` | The MinIO client to use |
299
+ | `buffer` | `Buffer` | `undefined` | The buffer to upload |
300
+ | `objectName` | `string` | `undefined` | The full object name/path |
301
+ | `contentType` | `string` | `undefined` | The content type of the file |
302
+ | `bucket` | `string` | `DEFAULT_BUCKET` | Optional bucket name (defaults to DEFAULT_BUCKET) |
303
+
304
+ ##### Returns
305
+
306
+ `Promise`\<\{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}\>
307
+
308
+ The uploaded file metadata
309
+
310
+ ##### Throws
311
+
312
+ Will throw an error if upload fails or client initialization fails
313
+
314
+ ##### Example
315
+
316
+ ```ts
317
+ import { createServerMinioClient, uploadBuffer } from "@settlemint/sdk-minio";
318
+
319
+ const { client } = createServerMinioClient({
320
+ instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
321
+ accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
322
+ secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
323
+ });
324
+
325
+ const buffer = Buffer.from("Hello, world!");
326
+ const uploadedFile = await uploadFile(client, buffer, "documents/hello.txt", "text/plain");
327
+ ```
328
+
329
+ ### Type Aliases
330
+
331
+ #### FileMetadata
332
+
333
+ > **FileMetadata** = [`Static`](#static)\<*typeof* [`FileMetadataSchema`](#filemetadataschema)\>
334
+
335
+ Defined in: [sdk/minio/src/helpers/schema.ts:29](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/helpers/schema.ts#L29)
336
+
337
+ Type representing file metadata after validation.
338
+
339
+ ***
340
+
341
+ #### Static\<T\>
342
+
343
+ > **Static**\<`T`\> = [`Static`](#static)\<`T`\>
344
+
345
+ Defined in: [sdk/minio/src/helpers/schema.ts:8](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/helpers/schema.ts#L8)
346
+
347
+ Helper type to extract the inferred type from a Zod schema.
348
+
349
+ ##### Type Parameters
350
+
351
+ | Type Parameter | Description |
352
+ | ------ | ------ |
353
+ | `T` *extends* `z.ZodType` | The Zod schema type |
354
+
355
+ ### Variables
356
+
357
+ #### DEFAULT\_BUCKET
358
+
359
+ > `const` **DEFAULT\_BUCKET**: `"uploads"` = `"uploads"`
360
+
361
+ Defined in: [sdk/minio/src/helpers/schema.ts:34](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/helpers/schema.ts#L34)
362
+
363
+ Default bucket name to use for file storage when none is specified.
364
+
365
+ ***
366
+
367
+ #### FileMetadataSchema
368
+
369
+ > `const` **FileMetadataSchema**: `ZodObject`\<\{ `contentType`: `ZodString`; `etag`: `ZodString`; `id`: `ZodString`; `name`: `ZodString`; `size`: `ZodNumber`; `uploadedAt`: `ZodString`; `url`: `ZodOptional`\<`ZodString`\>; \}, `"strip"`, `ZodTypeAny`, \{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}, \{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}\>
370
+
371
+ Defined in: [sdk/minio/src/helpers/schema.ts:16](https://github.com/settlemint/sdk/blob/v2.1.4/sdk/minio/src/helpers/schema.ts#L16)
372
+
373
+ Schema for file metadata stored in MinIO.
374
+ Defines the structure and validation rules for file information.
375
+
90
376
  ## Contributing
91
377
 
92
378
  We welcome contributions from the community! Please check out our [Contributing](https://github.com/settlemint/sdk/blob/main/.github/CONTRIBUTING.md) guide to learn how you can help improve the SettleMint SDK through bug reports, feature requests, documentation updates, or code contributions.
package/dist/minio.cjs CHANGED
@@ -20,31 +20,263 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/minio.ts
21
21
  var minio_exports = {};
22
22
  __export(minio_exports, {
23
- createServerMinioClient: () => createServerMinioClient
23
+ DEFAULT_BUCKET: () => DEFAULT_BUCKET,
24
+ createPresignedUploadUrl: () => createPresignedUploadUrl,
25
+ createServerMinioClient: () => createServerMinioClient,
26
+ deleteFile: () => deleteFile,
27
+ getFileById: () => getFileById,
28
+ getFilesList: () => getFilesList,
29
+ uploadFile: () => uploadFile
24
30
  });
25
31
  module.exports = __toCommonJS(minio_exports);
26
- var import_runtime = require("@settlemint/sdk-utils/runtime");
27
- var import_validation2 = require("@settlemint/sdk-utils/validation");
32
+ var import_runtime3 = require("@settlemint/sdk-utils/runtime");
33
+ var import_validation3 = require("@settlemint/sdk-utils/validation");
28
34
  var import_minio = require("minio");
29
35
 
30
36
  // src/helpers/client-options.schema.ts
31
37
  var import_validation = require("@settlemint/sdk-utils/validation");
32
38
  var import_zod = require("zod");
33
- var ClientOptionsSchema = import_zod.z.object({
39
+ var ServerClientOptionsSchema = import_zod.z.object({
34
40
  /** The URL of the MinIO instance to connect to */
35
- instance: import_validation.UrlSchema
36
- });
37
- var ServerClientOptionsSchema = ClientOptionsSchema.extend({
41
+ instance: import_validation.UrlSchema,
38
42
  /** The MinIO access key used to authenticate with the MinIO server */
39
43
  accessKey: import_zod.z.string(),
40
44
  /** The MinIO secret key used to authenticate with the MinIO server */
41
45
  secretKey: import_zod.z.string()
42
46
  });
43
47
 
48
+ // src/helpers/functions.ts
49
+ var import_runtime2 = require("@settlemint/sdk-utils/runtime");
50
+ var import_validation2 = require("@settlemint/sdk-utils/validation");
51
+
52
+ // src/helpers/executor.ts
53
+ var import_runtime = require("@settlemint/sdk-utils/runtime");
54
+ async function executeMinioOperation(client, operation) {
55
+ (0, import_runtime.ensureServer)();
56
+ return operation.execute(client);
57
+ }
58
+
59
+ // src/helpers/operations.ts
60
+ function createListObjectsOperation(bucket, prefix = "") {
61
+ return {
62
+ execute: async (client) => {
63
+ const objectsStream = client.listObjects(bucket, prefix, true);
64
+ const objects = [];
65
+ return new Promise((resolve, reject) => {
66
+ objectsStream.on("data", (obj) => {
67
+ if (obj.name && typeof obj.size === "number" && obj.etag && obj.lastModified) {
68
+ objects.push({
69
+ name: obj.name,
70
+ prefix: obj.prefix,
71
+ size: obj.size,
72
+ etag: obj.etag,
73
+ lastModified: obj.lastModified
74
+ });
75
+ }
76
+ });
77
+ objectsStream.on("error", (err) => {
78
+ reject(err);
79
+ });
80
+ objectsStream.on("end", () => {
81
+ resolve(objects);
82
+ });
83
+ });
84
+ }
85
+ };
86
+ }
87
+ function createStatObjectOperation(bucket, objectName) {
88
+ return {
89
+ execute: async (client) => {
90
+ return client.statObject(bucket, objectName);
91
+ }
92
+ };
93
+ }
94
+ function createDeleteOperation(bucket, objectName) {
95
+ return {
96
+ execute: async (client) => {
97
+ return client.removeObject(bucket, objectName);
98
+ }
99
+ };
100
+ }
101
+ function createPresignedUrlOperation(bucket, objectName, expirySeconds) {
102
+ return {
103
+ execute: async (client) => {
104
+ return client.presignedGetObject(bucket, objectName, expirySeconds);
105
+ }
106
+ };
107
+ }
108
+ function createPresignedPutOperation(bucket, objectName, expirySeconds) {
109
+ return {
110
+ execute: async (client) => {
111
+ return client.presignedPutObject(bucket, objectName, expirySeconds);
112
+ }
113
+ };
114
+ }
115
+ function createSimpleUploadOperation(client) {
116
+ return async (buffer, bucket, objectName, metadata) => {
117
+ return client.putObject(bucket, objectName, buffer, void 0, metadata);
118
+ };
119
+ }
120
+
121
+ // src/helpers/schema.ts
122
+ var import_zod2 = require("zod");
123
+ var FileMetadataSchema = import_zod2.z.object({
124
+ id: import_zod2.z.string(),
125
+ name: import_zod2.z.string(),
126
+ contentType: import_zod2.z.string(),
127
+ size: import_zod2.z.number(),
128
+ uploadedAt: import_zod2.z.string().datetime(),
129
+ etag: import_zod2.z.string(),
130
+ url: import_zod2.z.string().url().optional()
131
+ });
132
+ var DEFAULT_BUCKET = "uploads";
133
+
134
+ // src/helpers/functions.ts
135
+ function normalizePath(path, fileName) {
136
+ if (path.length > 1e3) {
137
+ throw new Error("Path is too long");
138
+ }
139
+ const cleanPath = path.replace(/\/+$/, "");
140
+ if (!cleanPath) {
141
+ return fileName;
142
+ }
143
+ return `${cleanPath}/${fileName}`;
144
+ }
145
+ async function getFilesList(client, prefix = "", bucket = DEFAULT_BUCKET) {
146
+ (0, import_runtime2.ensureServer)();
147
+ console.log(`Listing files with prefix: "${prefix}" in bucket: "${bucket}"`);
148
+ try {
149
+ const listOperation = createListObjectsOperation(bucket, prefix);
150
+ const objects = await executeMinioOperation(client, listOperation);
151
+ console.log(`Found ${objects.length} files in MinIO`);
152
+ const fileObjects = await Promise.all(
153
+ objects.map(async (obj) => {
154
+ const presignedUrlOperation = createPresignedUrlOperation(
155
+ bucket,
156
+ obj.name,
157
+ 3600
158
+ // 1 hour expiry
159
+ );
160
+ const url = await executeMinioOperation(client, presignedUrlOperation);
161
+ return {
162
+ id: obj.name,
163
+ name: obj.name.split("/").pop() || obj.name,
164
+ contentType: "application/octet-stream",
165
+ // Default type
166
+ size: obj.size,
167
+ uploadedAt: obj.lastModified.toISOString(),
168
+ etag: obj.etag,
169
+ url
170
+ };
171
+ })
172
+ );
173
+ return (0, import_validation2.validate)(FileMetadataSchema.array(), fileObjects);
174
+ } catch (error) {
175
+ console.error("Failed to list files:", error);
176
+ throw new Error(`Failed to list files: ${error instanceof Error ? error.message : String(error)}`);
177
+ }
178
+ }
179
+ async function getFileById(client, fileId, bucket = DEFAULT_BUCKET) {
180
+ (0, import_runtime2.ensureServer)();
181
+ console.log(`Getting file details for: ${fileId} in bucket: ${bucket}`);
182
+ try {
183
+ const statOperation = createStatObjectOperation(bucket, fileId);
184
+ const statResult = await executeMinioOperation(client, statOperation);
185
+ const presignedUrlOperation = createPresignedUrlOperation(
186
+ bucket,
187
+ fileId,
188
+ 3600
189
+ // 1 hour expiry
190
+ );
191
+ const url = await executeMinioOperation(client, presignedUrlOperation);
192
+ let size = 0;
193
+ if (statResult.metaData["content-length"]) {
194
+ const parsedSize = Number.parseInt(statResult.metaData["content-length"], 10);
195
+ if (!Number.isNaN(parsedSize)) {
196
+ size = parsedSize;
197
+ }
198
+ } else if (typeof statResult.size === "number" && !Number.isNaN(statResult.size)) {
199
+ size = statResult.size;
200
+ }
201
+ const fileMetadata = {
202
+ id: fileId,
203
+ name: fileId.split("/").pop() || fileId,
204
+ contentType: statResult.metaData["content-type"] || "application/octet-stream",
205
+ size,
206
+ uploadedAt: statResult.lastModified.toISOString(),
207
+ etag: statResult.etag,
208
+ url
209
+ };
210
+ return (0, import_validation2.validate)(FileMetadataSchema, fileMetadata);
211
+ } catch (error) {
212
+ console.error(`Failed to get file ${fileId}:`, error);
213
+ throw new Error(`Failed to get file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);
214
+ }
215
+ }
216
+ async function deleteFile(client, fileId, bucket = DEFAULT_BUCKET) {
217
+ (0, import_runtime2.ensureServer)();
218
+ try {
219
+ const deleteOperation = createDeleteOperation(bucket, fileId);
220
+ await executeMinioOperation(client, deleteOperation);
221
+ return true;
222
+ } catch (error) {
223
+ console.error(`Failed to delete file ${fileId}:`, error);
224
+ throw new Error(`Failed to delete file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);
225
+ }
226
+ }
227
+ async function createPresignedUploadUrl(client, fileName, path = "", bucket = DEFAULT_BUCKET, expirySeconds = 3600) {
228
+ (0, import_runtime2.ensureServer)();
229
+ try {
230
+ const safeFileName = fileName.replace(/[^a-zA-Z0-9._-]/g, "_");
231
+ const objectName = normalizePath(path, safeFileName);
232
+ const presignedPutOperation = createPresignedPutOperation(bucket, objectName, expirySeconds);
233
+ const url = await executeMinioOperation(client, presignedPutOperation);
234
+ if (!url) {
235
+ throw new Error("Failed to generate presigned upload URL");
236
+ }
237
+ return url;
238
+ } catch (error) {
239
+ console.error("Failed to create presigned upload URL:", error);
240
+ throw new Error(`Failed to create presigned upload URL: ${error instanceof Error ? error.message : String(error)}`);
241
+ }
242
+ }
243
+ async function uploadFile(client, buffer, objectName, contentType, bucket = DEFAULT_BUCKET) {
244
+ (0, import_runtime2.ensureServer)();
245
+ try {
246
+ const metadata = {
247
+ "content-type": contentType,
248
+ "upload-time": (/* @__PURE__ */ new Date()).toISOString()
249
+ };
250
+ const simpleUploadFn = createSimpleUploadOperation(client);
251
+ const result = await simpleUploadFn(buffer, bucket, objectName, metadata);
252
+ const presignedUrlOperation = createPresignedUrlOperation(
253
+ bucket,
254
+ objectName,
255
+ 3600
256
+ // 1 hour expiry
257
+ );
258
+ const url = await executeMinioOperation(client, presignedUrlOperation);
259
+ const fileName = objectName.split("/").pop() || objectName;
260
+ const fileMetadata = {
261
+ id: objectName,
262
+ name: fileName,
263
+ contentType,
264
+ size: buffer.length,
265
+ uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
266
+ etag: result.etag,
267
+ url
268
+ };
269
+ return (0, import_validation2.validate)(FileMetadataSchema, fileMetadata);
270
+ } catch (error) {
271
+ console.error("Failed to upload file:", error);
272
+ throw new Error(`Failed to upload file: ${error instanceof Error ? error.message : String(error)}`);
273
+ }
274
+ }
275
+
44
276
  // src/minio.ts
45
277
  function createServerMinioClient(options) {
46
- (0, import_runtime.ensureServer)();
47
- const validatedOptions = (0, import_validation2.validate)(ServerClientOptionsSchema, options);
278
+ (0, import_runtime3.ensureServer)();
279
+ const validatedOptions = (0, import_validation3.validate)(ServerClientOptionsSchema, options);
48
280
  const url = new URL(validatedOptions.instance);
49
281
  return {
50
282
  client: new import_minio.Client({
@@ -59,6 +291,12 @@ function createServerMinioClient(options) {
59
291
  }
60
292
  // Annotate the CommonJS export names for ESM import in node:
61
293
  0 && (module.exports = {
62
- createServerMinioClient
294
+ DEFAULT_BUCKET,
295
+ createPresignedUploadUrl,
296
+ createServerMinioClient,
297
+ deleteFile,
298
+ getFileById,
299
+ getFilesList,
300
+ uploadFile
63
301
  });
64
302
  //# sourceMappingURL=minio.cjs.map