@settlemint/sdk-minio 2.1.5-pr594fad44 → 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 CHANGED
@@ -35,12 +35,10 @@
35
35
  - [getFileById()](#getfilebyid)
36
36
  - [getFilesList()](#getfileslist)
37
37
  - [uploadFile()](#uploadfile)
38
- - [Type Aliases](#type-aliases)
38
+ - [Interfaces](#interfaces)
39
39
  - [FileMetadata](#filemetadata)
40
- - [Static\<T\>](#statict)
41
40
  - [Variables](#variables)
42
41
  - [DEFAULT\_BUCKET](#default_bucket)
43
- - [FileMetadataSchema](#filemetadataschema)
44
42
  - [Contributing](#contributing)
45
43
  - [License](#license)
46
44
 
@@ -58,7 +56,7 @@ For detailed information about using MinIO with the SettleMint platform, check o
58
56
 
59
57
  > **createPresignedUploadUrl**(`client`, `fileName`, `path`, `bucket`, `expirySeconds`): `Promise`\<`string`\>
60
58
 
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)
59
+ Defined in: [sdk/minio/src/helpers/functions.ts:243](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/functions.ts#L243)
62
60
 
63
61
  Creates a presigned upload URL for direct browser uploads
64
62
 
@@ -161,7 +159,7 @@ client.listBuckets();
161
159
 
162
160
  > **deleteFile**(`client`, `fileId`, `bucket`): `Promise`\<`boolean`\>
163
161
 
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)
162
+ Defined in: [sdk/minio/src/helpers/functions.ts:196](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/functions.ts#L196)
165
163
 
166
164
  Deletes a file from storage
167
165
 
@@ -201,9 +199,9 @@ await deleteFile(client, "documents/report.pdf");
201
199
 
202
200
  #### getFileById()
203
201
 
204
- > **getFileById**(`client`, `fileId`, `bucket`): `Promise`\<\{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}\>
202
+ > **getFileById**(`client`, `fileId`, `bucket`): `Promise`\<[`FileMetadata`](#filemetadata)\>
205
203
 
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)
204
+ Defined in: [sdk/minio/src/helpers/functions.ts:123](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/functions.ts#L123)
207
205
 
208
206
  Gets a single file by its object name
209
207
 
@@ -217,7 +215,7 @@ Gets a single file by its object name
217
215
 
218
216
  ##### Returns
219
217
 
220
- `Promise`\<\{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}\>
218
+ `Promise`\<[`FileMetadata`](#filemetadata)\>
221
219
 
222
220
  File metadata with presigned URL
223
221
 
@@ -243,9 +241,9 @@ const file = await getFileByObjectName(client, "documents/report.pdf");
243
241
 
244
242
  #### getFilesList()
245
243
 
246
- > **getFilesList**(`client`, `prefix`, `bucket`): `Promise`\<`object`[]\>
244
+ > **getFilesList**(`client`, `prefix`, `bucket`): `Promise`\<[`FileMetadata`](#filemetadata)[]\>
247
245
 
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)
246
+ Defined in: [sdk/minio/src/helpers/functions.ts:62](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/functions.ts#L62)
249
247
 
250
248
  Gets a list of files with optional prefix filter
251
249
 
@@ -259,7 +257,7 @@ Gets a list of files with optional prefix filter
259
257
 
260
258
  ##### Returns
261
259
 
262
- `Promise`\<`object`[]\>
260
+ `Promise`\<[`FileMetadata`](#filemetadata)[]\>
263
261
 
264
262
  Array of file metadata objects
265
263
 
@@ -285,9 +283,9 @@ const files = await getFilesList(client, "documents/");
285
283
 
286
284
  #### uploadFile()
287
285
 
288
- > **uploadFile**(`client`, `buffer`, `objectName`, `contentType`, `bucket`): `Promise`\<\{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}\>
286
+ > **uploadFile**(`client`, `buffer`, `objectName`, `contentType`, `bucket`): `Promise`\<[`FileMetadata`](#filemetadata)\>
289
287
 
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)
288
+ Defined in: [sdk/minio/src/helpers/functions.ts:293](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/functions.ts#L293)
291
289
 
292
290
  Uploads a buffer directly to storage
293
291
 
@@ -303,7 +301,7 @@ Uploads a buffer directly to storage
303
301
 
304
302
  ##### Returns
305
303
 
306
- `Promise`\<\{ `contentType`: `string`; `etag`: `string`; `id`: `string`; `name`: `string`; `size`: `number`; `uploadedAt`: `string`; `url?`: `string`; \}\>
304
+ `Promise`\<[`FileMetadata`](#filemetadata)\>
307
305
 
308
306
  The uploaded file metadata
309
307
 
@@ -326,31 +324,25 @@ const buffer = Buffer.from("Hello, world!");
326
324
  const uploadedFile = await uploadFile(client, buffer, "documents/hello.txt", "text/plain");
327
325
  ```
328
326
 
329
- ### Type Aliases
327
+ ### Interfaces
330
328
 
331
329
  #### FileMetadata
332
330
 
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)
331
+ Defined in: [sdk/minio/src/helpers/schema.ts:29](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/schema.ts#L29)
336
332
 
337
333
  Type representing file metadata after validation.
338
334
 
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
335
+ ##### Properties
350
336
 
351
- | Type Parameter | Description |
352
- | ------ | ------ |
353
- | `T` *extends* `z.ZodType` | The Zod schema type |
337
+ | Property | Type | Description | Defined in |
338
+ | ------ | ------ | ------ | ------ |
339
+ | <a id="contenttype"></a> `contentType` | `string` | The content type of the file. | [sdk/minio/src/helpers/schema.ts:41](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/schema.ts#L41) |
340
+ | <a id="etag"></a> `etag` | `string` | The ETag of the file. | [sdk/minio/src/helpers/schema.ts:56](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/schema.ts#L56) |
341
+ | <a id="id"></a> `id` | `string` | The unique identifier for the file. | [sdk/minio/src/helpers/schema.ts:33](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/schema.ts#L33) |
342
+ | <a id="name"></a> `name` | `string` | The name of the file. | [sdk/minio/src/helpers/schema.ts:37](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/schema.ts#L37) |
343
+ | <a id="size"></a> `size` | `number` | The size of the file in bytes. | [sdk/minio/src/helpers/schema.ts:46](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/schema.ts#L46) |
344
+ | <a id="uploadedat"></a> `uploadedAt` | `string` | The date and time the file was uploaded. | [sdk/minio/src/helpers/schema.ts:51](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/schema.ts#L51) |
345
+ | <a id="url"></a> `url?` | `string` | The URL of the file. | [sdk/minio/src/helpers/schema.ts:61](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/schema.ts#L61) |
354
346
 
355
347
  ### Variables
356
348
 
@@ -358,21 +350,10 @@ Helper type to extract the inferred type from a Zod schema.
358
350
 
359
351
  > `const` **DEFAULT\_BUCKET**: `"uploads"` = `"uploads"`
360
352
 
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)
353
+ Defined in: [sdk/minio/src/helpers/schema.ts:67](https://github.com/settlemint/sdk/blob/v2.1.5/sdk/minio/src/helpers/schema.ts#L67)
362
354
 
363
355
  Default bucket name to use for file storage when none is specified.
364
356
 
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
-
376
357
  ## Contributing
377
358
 
378
359
  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
@@ -45,6 +45,19 @@ var ServerClientOptionsSchema = import_zod.z.object({
45
45
  secretKey: import_zod.z.string()
46
46
  });
47
47
 
48
+ // src/helpers/schema.ts
49
+ var import_zod2 = require("zod");
50
+ var FileMetadataSchema = import_zod2.z.object({
51
+ id: import_zod2.z.string(),
52
+ name: import_zod2.z.string(),
53
+ contentType: import_zod2.z.string(),
54
+ size: import_zod2.z.number(),
55
+ uploadedAt: import_zod2.z.string().datetime(),
56
+ etag: import_zod2.z.string(),
57
+ url: import_zod2.z.string().url().optional()
58
+ });
59
+ var DEFAULT_BUCKET = "uploads";
60
+
48
61
  // src/helpers/functions.ts
49
62
  var import_runtime2 = require("@settlemint/sdk-utils/runtime");
50
63
  var import_validation2 = require("@settlemint/sdk-utils/validation");
@@ -118,19 +131,6 @@ function createSimpleUploadOperation(client) {
118
131
  };
119
132
  }
120
133
 
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
134
  // src/helpers/functions.ts
135
135
  function normalizePath(path, fileName) {
136
136
  if (path.length > 1e3) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/minio.ts","../src/helpers/client-options.schema.ts","../src/helpers/functions.ts","../src/helpers/executor.ts","../src/helpers/operations.ts","../src/helpers/schema.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { Client } from \"minio\";\nimport { type ServerClientOptions, ServerClientOptionsSchema } from \"./helpers/client-options.schema.js\";\n\n/**\n * Creates a MinIO client for server-side use with authentication.\n *\n * @param options - The server client options for configuring the MinIO client\n * @returns An object containing the initialized MinIO client\n * @throws Will throw an error if not called on the server or if the options fail validation\n *\n * @example\n * import { createServerMinioClient } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n * client.listBuckets();\n */\nexport function createServerMinioClient(options: ServerClientOptions): { client: Client } {\n ensureServer();\n const validatedOptions = validate(ServerClientOptionsSchema, options);\n\n const url = new URL(validatedOptions.instance);\n return {\n client: new Client({\n endPoint: url.hostname,\n accessKey: validatedOptions.accessKey,\n secretKey: validatedOptions.secretKey,\n useSSL: url.protocol !== \"http:\",\n port: url.port ? Number(url.port) : undefined,\n region: \"eu-central-1\",\n }),\n };\n}\n\n// Export high-level functions\nexport {\n getFilesList,\n getFileById,\n uploadFile,\n deleteFile,\n createPresignedUploadUrl,\n} from \"./helpers/functions.js\";\n\n// Export validation utilities and schemas\nexport {\n type FileMetadata,\n type FileMetadataSchema,\n type Static,\n DEFAULT_BUCKET,\n} from \"./helpers/schema.js\";\n\n// Re-export required types from minio\nexport type { Client, ItemBucketMetadata } from \"minio\";\n","import { UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { z } from \"zod\";\n\n/**\n * Schema for validating server client options for the MinIO client.\n */\nexport const ServerClientOptionsSchema = z.object({\n /** The URL of the MinIO instance to connect to */\n instance: UrlSchema,\n /** The MinIO access key used to authenticate with the MinIO server */\n accessKey: z.string(),\n /** The MinIO secret key used to authenticate with the MinIO server */\n secretKey: z.string(),\n});\n\n/**\n * Type definition for server client options derived from the ServerClientOptionsSchema.\n */\nexport type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;\n","import type { Buffer } from \"node:buffer\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport type { Client } from \"minio\";\nimport { executeMinioOperation } from \"./executor.js\";\nimport {\n createDeleteOperation,\n createListObjectsOperation,\n createPresignedPutOperation,\n createPresignedUrlOperation,\n createSimpleUploadOperation,\n createStatObjectOperation,\n} from \"./operations.js\";\nimport { DEFAULT_BUCKET, type FileMetadata, FileMetadataSchema } from \"./schema.js\";\n\n/**\n * Helper function to normalize paths and prevent double slashes\n *\n * @param path - The path to normalize\n * @param fileName - The filename to append\n * @returns The normalized path with filename\n * @throws Will throw an error if the path is too long (max 1000 characters)\n */\nfunction normalizePath(path: string, fileName: string): string {\n if (path.length > 1_000) {\n throw new Error(\"Path is too long\");\n }\n\n // Remove trailing slashes from path\n const cleanPath = path.replace(/\\/+$/, \"\");\n\n // If path is empty, return just the filename\n if (!cleanPath) {\n return fileName;\n }\n\n // Join with a single slash\n return `${cleanPath}/${fileName}`;\n}\n\n/**\n * Gets a list of files with optional prefix filter\n *\n * @param client - The MinIO client to use\n * @param prefix - Optional prefix to filter files (like a folder path)\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns Array of file metadata objects\n * @throws Will throw an error if the operation fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, getFilesList } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const files = await getFilesList(client, \"documents/\");\n */\nexport async function getFilesList(\n client: Client,\n prefix = \"\",\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata[]> {\n ensureServer();\n console.log(`Listing files with prefix: \"${prefix}\" in bucket: \"${bucket}\"`);\n\n try {\n const listOperation = createListObjectsOperation(bucket, prefix);\n const objects = await executeMinioOperation(client, listOperation);\n console.log(`Found ${objects.length} files in MinIO`);\n\n const fileObjects = await Promise.all(\n objects.map(async (obj): Promise<FileMetadata> => {\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n obj.name,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n return {\n id: obj.name,\n name: obj.name.split(\"/\").pop() || obj.name,\n contentType: \"application/octet-stream\", // Default type\n size: obj.size,\n uploadedAt: obj.lastModified.toISOString(),\n etag: obj.etag,\n url,\n };\n }),\n );\n\n return validate(FileMetadataSchema.array(), fileObjects);\n } catch (error) {\n console.error(\"Failed to list files:\", error);\n throw new Error(`Failed to list files: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Gets a single file by its object name\n *\n * @param client - The MinIO client to use\n * @param fileId - The file identifier/path\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns File metadata with presigned URL\n * @throws Will throw an error if the file doesn't exist or client initialization fails\n *\n * @example\n * import { createServerMinioClient, getFileByObjectName } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const file = await getFileByObjectName(client, \"documents/report.pdf\");\n */\nexport async function getFileById(\n client: Client,\n fileId: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n console.log(`Getting file details for: ${fileId} in bucket: ${bucket}`);\n\n try {\n // Get the file metadata\n const statOperation = createStatObjectOperation(bucket, fileId);\n const statResult = await executeMinioOperation(client, statOperation);\n\n // Generate a presigned URL for access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n fileId,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n // Try to get size from metadata first, then from stat result\n let size = 0;\n\n // Check for content-length in metadata\n if (statResult.metaData[\"content-length\"]) {\n const parsedSize = Number.parseInt(statResult.metaData[\"content-length\"], 10);\n if (!Number.isNaN(parsedSize)) {\n size = parsedSize;\n }\n }\n // Fallback to statResult.size if available and valid\n else if (typeof statResult.size === \"number\" && !Number.isNaN(statResult.size)) {\n size = statResult.size;\n }\n\n const fileMetadata: FileMetadata = {\n id: fileId,\n name: fileId.split(\"/\").pop() || fileId,\n contentType: statResult.metaData[\"content-type\"] || \"application/octet-stream\",\n size,\n uploadedAt: statResult.lastModified.toISOString(),\n etag: statResult.etag,\n url,\n };\n\n return validate(FileMetadataSchema, fileMetadata);\n } catch (error) {\n console.error(`Failed to get file ${fileId}:`, error);\n throw new Error(`Failed to get file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Deletes a file from storage\n *\n * @param client - The MinIO client to use\n * @param fileId - The file identifier/path\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns Success status\n * @throws Will throw an error if deletion fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, deleteFile } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * await deleteFile(client, \"documents/report.pdf\");\n */\nexport async function deleteFile(client: Client, fileId: string, bucket: string = DEFAULT_BUCKET): Promise<boolean> {\n ensureServer();\n try {\n const deleteOperation = createDeleteOperation(bucket, fileId);\n await executeMinioOperation(client, deleteOperation);\n return true;\n } catch (error) {\n console.error(`Failed to delete file ${fileId}:`, error);\n throw new Error(`Failed to delete file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Creates a presigned upload URL for direct browser uploads\n *\n * @param client - The MinIO client to use\n * @param fileName - The file name to use\n * @param path - Optional path/folder\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @param expirySeconds - How long the URL should be valid for\n * @returns Presigned URL for PUT operation\n * @throws Will throw an error if URL creation fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, createPresignedUploadUrl } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * // Generate the presigned URL on the server\n * const url = await createPresignedUploadUrl(client, \"report.pdf\", \"documents/\");\n *\n * // Send the URL to the client/browser via HTTP response\n * return Response.json({ uploadUrl: url });\n *\n * // Then in the browser:\n * const response = await fetch('/api/get-upload-url');\n * const { uploadUrl } = await response.json();\n * await fetch(uploadUrl, {\n * method: 'PUT',\n * headers: { 'Content-Type': 'application/pdf' },\n * body: pdfFile\n * });\n */\nexport async function createPresignedUploadUrl(\n client: Client,\n fileName: string,\n path = \"\",\n bucket: string = DEFAULT_BUCKET,\n expirySeconds = 3600,\n): Promise<string> {\n ensureServer();\n try {\n const safeFileName = fileName.replace(/[^a-zA-Z0-9._-]/g, \"_\");\n const objectName = normalizePath(path, safeFileName);\n\n // Create operation for presigned PUT URL\n const presignedPutOperation = createPresignedPutOperation(bucket, objectName, expirySeconds);\n\n const url = await executeMinioOperation(client, presignedPutOperation);\n if (!url) {\n throw new Error(\"Failed to generate presigned upload URL\");\n }\n\n return url;\n } catch (error) {\n console.error(\"Failed to create presigned upload URL:\", error);\n throw new Error(`Failed to create presigned upload URL: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Uploads a buffer directly to storage\n *\n * @param client - The MinIO client to use\n * @param buffer - The buffer to upload\n * @param objectName - The full object name/path\n * @param contentType - The content type of the file\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns The uploaded file metadata\n * @throws Will throw an error if upload fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, uploadBuffer } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const buffer = Buffer.from(\"Hello, world!\");\n * const uploadedFile = await uploadFile(client, buffer, \"documents/hello.txt\", \"text/plain\");\n */\nexport async function uploadFile(\n client: Client,\n buffer: Buffer,\n objectName: string,\n contentType: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n try {\n // Add file metadata\n const metadata = {\n \"content-type\": contentType,\n \"upload-time\": new Date().toISOString(),\n };\n\n // Use the createSimpleUploadOperation\n const simpleUploadFn = createSimpleUploadOperation(client);\n const result = await simpleUploadFn(buffer, bucket, objectName, metadata);\n\n // Generate a presigned URL for immediate access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n objectName,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n const fileName = objectName.split(\"/\").pop() || objectName;\n\n const fileMetadata: FileMetadata = {\n id: objectName,\n name: fileName,\n contentType,\n size: buffer.length,\n uploadedAt: new Date().toISOString(),\n etag: result.etag,\n url,\n };\n\n return validate(FileMetadataSchema, fileMetadata);\n } catch (error) {\n console.error(\"Failed to upload file:\", error);\n throw new Error(`Failed to upload file: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n","import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport type { Client } from \"minio\";\nimport type { MinioOperation } from \"./operations.js\";\n\n/**\n * Executes a MinIO operation using the provided client\n *\n * @param client - MinIO client to use\n * @param operation - The operation to execute\n * @returns The result of the operation execution\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createServerMinioClient, createListObjectsOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n * const listOperation = createListObjectsOperation(\"my-bucket\", \"prefix/\");\n * const result = await executeMinioOperation(client, listOperation);\n */\nexport async function executeMinioOperation<T>(client: Client, operation: MinioOperation<T>): Promise<T> {\n ensureServer();\n\n return operation.execute(client);\n}\n","import type { Buffer } from \"node:buffer\";\nimport type { Client, ItemBucketMetadata } from \"minio\";\n\n/**\n * Base interface for all MinIO operations\n *\n * @template T The return type of the operation\n */\nexport interface MinioOperation<T> {\n execute: (client: Client) => Promise<T>;\n}\n\n/**\n * Creates an operation to list objects in a bucket\n *\n * @param bucket - The bucket name to list objects from\n * @param prefix - Optional prefix to filter objects (like a folder path)\n * @returns A MinioOperation that lists objects when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createListObjectsOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const listOperation = createListObjectsOperation(\"my-bucket\", \"folder/\");\n * const objects = await executeMinioOperation(client, listOperation);\n */\nexport function createListObjectsOperation(\n bucket: string,\n prefix = \"\",\n): MinioOperation<\n Array<{\n name: string;\n prefix?: string;\n size: number;\n etag: string;\n lastModified: Date;\n }>\n> {\n return {\n execute: async (client: Client) => {\n const objectsStream = client.listObjects(bucket, prefix, true);\n const objects: Array<{\n name: string;\n prefix?: string;\n size: number;\n etag: string;\n lastModified: Date;\n }> = [];\n\n return new Promise((resolve, reject) => {\n objectsStream.on(\"data\", (obj) => {\n // Ensure required properties are not undefined before adding to the array\n if (obj.name && typeof obj.size === \"number\" && obj.etag && obj.lastModified) {\n objects.push({\n name: obj.name,\n prefix: obj.prefix,\n size: obj.size,\n etag: obj.etag,\n lastModified: obj.lastModified,\n });\n }\n });\n\n objectsStream.on(\"error\", (err) => {\n reject(err);\n });\n\n objectsStream.on(\"end\", () => {\n resolve(objects);\n });\n });\n },\n };\n}\n\n/**\n * Creates an operation to get an object's metadata\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path\n * @returns A MinioOperation that gets object stats when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createStatObjectOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const statOperation = createStatObjectOperation(\"my-bucket\", \"folder/file.txt\");\n * const stats = await executeMinioOperation(client, statOperation);\n */\nexport function createStatObjectOperation(\n bucket: string,\n objectName: string,\n): MinioOperation<{\n size: number;\n etag: string;\n metaData: Record<string, string>;\n lastModified: Date;\n}> {\n return {\n execute: async (client: Client) => {\n return client.statObject(bucket, objectName);\n },\n };\n}\n\n/**\n * Creates an operation to upload a buffer to MinIO\n *\n * @param bucket - The bucket name to upload to\n * @param objectName - The object name/path to create\n * @param buffer - The buffer containing the file data\n * @param metadata - Optional metadata to attach to the object\n * @returns A MinioOperation that uploads the buffer when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createUploadOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const buffer = Buffer.from(\"file content\");\n * const uploadOperation = createUploadOperation(\"my-bucket\", \"folder/file.txt\", buffer, { \"content-type\": \"text/plain\" });\n * const result = await executeMinioOperation(client, uploadOperation);\n */\nexport function createUploadOperation(\n bucket: string,\n objectName: string,\n buffer: Buffer,\n metadata?: ItemBucketMetadata,\n): MinioOperation<{ etag: string }> {\n return {\n execute: async (client: Client) => {\n return client.putObject(bucket, objectName, buffer, undefined, metadata);\n },\n };\n}\n\n/**\n * Creates an operation to delete an object from MinIO\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path to delete\n * @returns A MinioOperation that deletes the object when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createDeleteOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const deleteOperation = createDeleteOperation(\"my-bucket\", \"folder/file.txt\");\n * await executeMinioOperation(client, deleteOperation);\n */\nexport function createDeleteOperation(bucket: string, objectName: string): MinioOperation<void> {\n return {\n execute: async (client: Client) => {\n return client.removeObject(bucket, objectName);\n },\n };\n}\n\n/**\n * Creates an operation to generate a presigned URL for an object\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path\n * @param expirySeconds - How long the URL should be valid for in seconds\n * @returns A MinioOperation that creates a presigned URL when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createPresignedUrlOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const urlOperation = createPresignedUrlOperation(\"my-bucket\", \"folder/file.txt\", 3600);\n * const url = await executeMinioOperation(client, urlOperation);\n */\nexport function createPresignedUrlOperation(\n bucket: string,\n objectName: string,\n expirySeconds: number,\n): MinioOperation<string> {\n return {\n execute: async (client: Client) => {\n return client.presignedGetObject(bucket, objectName, expirySeconds);\n },\n };\n}\n\n/**\n * Creates an operation to generate a presigned PUT URL for direct uploads\n *\n * @param bucket - The bucket name to upload to\n * @param objectName - The object name/path to create\n * @param expirySeconds - How long the URL should be valid for in seconds\n * @returns A MinioOperation that creates a presigned PUT URL when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createPresignedPutOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const putUrlOperation = createPresignedPutOperation(\"my-bucket\", \"folder/file.txt\", 3600);\n * const url = await executeMinioOperation(client, putUrlOperation);\n */\nexport function createPresignedPutOperation(\n bucket: string,\n objectName: string,\n expirySeconds: number,\n): MinioOperation<string> {\n return {\n execute: async (client: Client) => {\n // The MinIO client only accepts the first three parameters for presignedPutObject\n // Metadata needs to be applied when actually uploading via the presigned URL\n return client.presignedPutObject(bucket, objectName, expirySeconds);\n },\n };\n}\n\n/**\n * Creates a simplified upload function bound to a specific client\n *\n * @param client - The MinIO client to use for uploads\n * @returns A function that uploads buffers to MinIO\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createSimpleUploadOperation, getMinioClient } from \"@settlemint/sdk-minio\";\n *\n * const client = await getMinioClient();\n * const uploadFn = createSimpleUploadOperation(client);\n * const result = await uploadFn(buffer, \"my-bucket\", \"folder/file.txt\", { \"content-type\": \"text/plain\" });\n */\nexport function createSimpleUploadOperation(client: Client) {\n return async (\n buffer: Buffer,\n bucket: string,\n objectName: string,\n metadata?: ItemBucketMetadata,\n ): Promise<{ etag: string }> => {\n return client.putObject(bucket, objectName, buffer, undefined, metadata);\n };\n}\n","import { z } from \"zod\";\n\n/**\n * Helper type to extract the inferred type from a Zod schema.\n *\n * @template T - The Zod schema type\n */\nexport type Static<T extends z.ZodType> = z.infer<T>;\n\n// ----- Schema Definitions -----\n\n/**\n * Schema for file metadata stored in MinIO.\n * Defines the structure and validation rules for file information.\n */\nexport const FileMetadataSchema = z.object({\n id: z.string(),\n name: z.string(),\n contentType: z.string(),\n size: z.number(),\n uploadedAt: z.string().datetime(),\n etag: z.string(),\n url: z.string().url().optional(),\n});\n\n/**\n * Type representing file metadata after validation.\n */\nexport type FileMetadata = Static<typeof FileMetadataSchema>;\n\n/**\n * Default bucket name to use for file storage when none is specified.\n */\nexport const DEFAULT_BUCKET = \"uploads\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,kBAA6B;AAC7B,IAAAC,qBAAyB;AACzB,mBAAuB;;;ACFvB,wBAA0B;AAC1B,iBAAkB;AAKX,IAAM,4BAA4B,aAAE,OAAO;AAAA;AAAA,EAEhD,UAAU;AAAA;AAAA,EAEV,WAAW,aAAE,OAAO;AAAA;AAAA,EAEpB,WAAW,aAAE,OAAO;AACtB,CAAC;;;ACZD,IAAAC,kBAA6B;AAC7B,IAAAC,qBAAyB;;;ACFzB,qBAA6B;AAsB7B,eAAsB,sBAAyB,QAAgB,WAA0C;AACvG,mCAAa;AAEb,SAAO,UAAU,QAAQ,MAAM;AACjC;;;ACAO,SAAS,2BACd,QACA,SAAS,IAST;AACA,SAAO;AAAA,IACL,SAAS,OAAO,WAAmB;AACjC,YAAM,gBAAgB,OAAO,YAAY,QAAQ,QAAQ,IAAI;AAC7D,YAAM,UAMD,CAAC;AAEN,aAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,sBAAc,GAAG,QAAQ,CAAC,QAAQ;AAEhC,cAAI,IAAI,QAAQ,OAAO,IAAI,SAAS,YAAY,IA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B;AAErE,UAAM,WAAW,WAAW,MAAM,GAAG,EAAE,IAAI,KAAK;AAEhD,UAAM,eAA6B;AAAA,MACjC,IAAI;AAAA,MACJ,MAAM;AAAA,MACN;AAAA,MACA,MAAM,OAAO;AAAA,MACb,aAAY,oBAAI,KAAK,GAAE,YAAY;AAAA,MACnC,MAAM,OAAO;AAAA,MACb;AAAA,IACF;AAEA,eAAO,6BAAS,oBAAoB,YAAY;AAAA,EAClD,SAAS,OAAO;AACd,YAAQ,MAAM,0BAA0B,KAAK;AAC7C,UAAM,IAAI,MAAM,0BAA0B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,EACpG;AACF;;;AFzTO,SAAS,wBAAwB,SAAkD;AACxF,oCAAa;AACb,QAAM,uBAAmB,6BAAS,2BAA2B,OAAO;AAEpE,QAAM,MAAM,IAAI,IAAI,iBAAiB,QAAQ;AAC7C,SAAO;AAAA,IACL,QAAQ,IAAI,oBAAO;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,WAAW,iBAAiB;AAAA,MAC5B,WAAW,iBAAiB;AAAA,MAC5B,QAAQ,IAAI,aAAa;AAAA,MACzB,MAAM,IAAI,OAAO,OAAO,IAAI,IAAI,IAAI;AAAA,MACpC,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;","names":["import_runtime","import_validation","import_runtime","import_validation","import_zod"]}
1
+ {"version":3,"sources":["../src/minio.ts","../src/helpers/client-options.schema.ts","../src/helpers/schema.ts","../src/helpers/functions.ts","../src/helpers/executor.ts","../src/helpers/operations.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { Client } from \"minio\";\nimport { type ServerClientOptions, ServerClientOptionsSchema } from \"./helpers/client-options.schema.js\";\n\n/**\n * Creates a MinIO client for server-side use with authentication.\n *\n * @param options - The server client options for configuring the MinIO client\n * @returns An object containing the initialized MinIO client\n * @throws Will throw an error if not called on the server or if the options fail validation\n *\n * @example\n * import { createServerMinioClient } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n * client.listBuckets();\n */\nexport function createServerMinioClient(options: ServerClientOptions): { client: Client } {\n ensureServer();\n const validatedOptions = validate(ServerClientOptionsSchema, options);\n\n const url = new URL(validatedOptions.instance);\n return {\n client: new Client({\n endPoint: url.hostname,\n accessKey: validatedOptions.accessKey,\n secretKey: validatedOptions.secretKey,\n useSSL: url.protocol !== \"http:\",\n port: url.port ? Number(url.port) : undefined,\n region: \"eu-central-1\",\n }),\n };\n}\n// Export validation utilities and schemas\nexport {\n type FileMetadata,\n DEFAULT_BUCKET,\n} from \"./helpers/schema.js\";\n\n// Export high-level functions\nexport {\n getFilesList,\n getFileById,\n uploadFile,\n deleteFile,\n createPresignedUploadUrl,\n} from \"./helpers/functions.js\";\n\n// Re-export required types from minio\nexport type { Client, ItemBucketMetadata } from \"minio\";\n","import { UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { z } from \"zod\";\n\n/**\n * Schema for validating server client options for the MinIO client.\n */\nexport const ServerClientOptionsSchema = z.object({\n /** The URL of the MinIO instance to connect to */\n instance: UrlSchema,\n /** The MinIO access key used to authenticate with the MinIO server */\n accessKey: z.string(),\n /** The MinIO secret key used to authenticate with the MinIO server */\n secretKey: z.string(),\n});\n\n/**\n * Type definition for server client options derived from the ServerClientOptionsSchema.\n */\nexport type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;\n","import { z } from \"zod\";\n\n/**\n * Helper type to extract the inferred type from a Zod schema.\n *\n * @template T - The Zod schema type\n */\nexport type Static<T extends z.ZodType> = z.infer<T>;\n\n// ----- Schema Definitions -----\n\n/**\n * Schema for file metadata stored in MinIO.\n * Defines the structure and validation rules for file information.\n */\nexport const FileMetadataSchema = z.object({\n id: z.string(),\n name: z.string(),\n contentType: z.string(),\n size: z.number(),\n uploadedAt: z.string().datetime(),\n etag: z.string(),\n url: z.string().url().optional(),\n});\n\n/**\n * Type representing file metadata after validation.\n */\nexport interface FileMetadata {\n /**\n * The unique identifier for the file.\n */\n id: string;\n /**\n * The name of the file.\n */\n name: string;\n /**\n * The content type of the file.\n */\n contentType: string;\n\n /**\n * The size of the file in bytes.\n */\n size: number;\n\n /**\n * The date and time the file was uploaded.\n */\n uploadedAt: string;\n\n /**\n * The ETag of the file.\n */\n etag: string;\n\n /**\n * The URL of the file.\n */\n url?: string;\n}\n\n/**\n * Default bucket name to use for file storage when none is specified.\n */\nexport const DEFAULT_BUCKET = \"uploads\";\n","import type { Buffer } from \"node:buffer\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport type { Client } from \"minio\";\nimport { executeMinioOperation } from \"./executor.js\";\nimport {\n createDeleteOperation,\n createListObjectsOperation,\n createPresignedPutOperation,\n createPresignedUrlOperation,\n createSimpleUploadOperation,\n createStatObjectOperation,\n} from \"./operations.js\";\nimport { DEFAULT_BUCKET, FileMetadataSchema } from \"./schema.js\";\nimport type { FileMetadata } from \"./schema.js\";\n\n/**\n * Helper function to normalize paths and prevent double slashes\n *\n * @param path - The path to normalize\n * @param fileName - The filename to append\n * @returns The normalized path with filename\n * @throws Will throw an error if the path is too long (max 1000 characters)\n */\nfunction normalizePath(path: string, fileName: string): string {\n if (path.length > 1_000) {\n throw new Error(\"Path is too long\");\n }\n\n // Remove trailing slashes from path\n const cleanPath = path.replace(/\\/+$/, \"\");\n\n // If path is empty, return just the filename\n if (!cleanPath) {\n return fileName;\n }\n\n // Join with a single slash\n return `${cleanPath}/${fileName}`;\n}\n\n/**\n * Gets a list of files with optional prefix filter\n *\n * @param client - The MinIO client to use\n * @param prefix - Optional prefix to filter files (like a folder path)\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns Array of file metadata objects\n * @throws Will throw an error if the operation fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, getFilesList } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const files = await getFilesList(client, \"documents/\");\n */\nexport async function getFilesList(\n client: Client,\n prefix = \"\",\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata[]> {\n ensureServer();\n console.log(`Listing files with prefix: \"${prefix}\" in bucket: \"${bucket}\"`);\n\n try {\n const listOperation = createListObjectsOperation(bucket, prefix);\n const objects = await executeMinioOperation(client, listOperation);\n console.log(`Found ${objects.length} files in MinIO`);\n\n const fileObjects = await Promise.all(\n objects.map(async (obj): Promise<FileMetadata> => {\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n obj.name,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n return {\n id: obj.name,\n name: obj.name.split(\"/\").pop() || obj.name,\n contentType: \"application/octet-stream\", // Default type\n size: obj.size,\n uploadedAt: obj.lastModified.toISOString(),\n etag: obj.etag,\n url,\n };\n }),\n );\n\n return validate(FileMetadataSchema.array(), fileObjects);\n } catch (error) {\n console.error(\"Failed to list files:\", error);\n throw new Error(`Failed to list files: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Gets a single file by its object name\n *\n * @param client - The MinIO client to use\n * @param fileId - The file identifier/path\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns File metadata with presigned URL\n * @throws Will throw an error if the file doesn't exist or client initialization fails\n *\n * @example\n * import { createServerMinioClient, getFileByObjectName } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const file = await getFileByObjectName(client, \"documents/report.pdf\");\n */\nexport async function getFileById(\n client: Client,\n fileId: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n console.log(`Getting file details for: ${fileId} in bucket: ${bucket}`);\n\n try {\n // Get the file metadata\n const statOperation = createStatObjectOperation(bucket, fileId);\n const statResult = await executeMinioOperation(client, statOperation);\n\n // Generate a presigned URL for access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n fileId,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n // Try to get size from metadata first, then from stat result\n let size = 0;\n\n // Check for content-length in metadata\n if (statResult.metaData[\"content-length\"]) {\n const parsedSize = Number.parseInt(statResult.metaData[\"content-length\"], 10);\n if (!Number.isNaN(parsedSize)) {\n size = parsedSize;\n }\n }\n // Fallback to statResult.size if available and valid\n else if (typeof statResult.size === \"number\" && !Number.isNaN(statResult.size)) {\n size = statResult.size;\n }\n\n const fileMetadata: FileMetadata = {\n id: fileId,\n name: fileId.split(\"/\").pop() || fileId,\n contentType: statResult.metaData[\"content-type\"] || \"application/octet-stream\",\n size,\n uploadedAt: statResult.lastModified.toISOString(),\n etag: statResult.etag,\n url,\n };\n\n return validate(FileMetadataSchema, fileMetadata);\n } catch (error) {\n console.error(`Failed to get file ${fileId}:`, error);\n throw new Error(`Failed to get file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Deletes a file from storage\n *\n * @param client - The MinIO client to use\n * @param fileId - The file identifier/path\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns Success status\n * @throws Will throw an error if deletion fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, deleteFile } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * await deleteFile(client, \"documents/report.pdf\");\n */\nexport async function deleteFile(client: Client, fileId: string, bucket: string = DEFAULT_BUCKET): Promise<boolean> {\n ensureServer();\n try {\n const deleteOperation = createDeleteOperation(bucket, fileId);\n await executeMinioOperation(client, deleteOperation);\n return true;\n } catch (error) {\n console.error(`Failed to delete file ${fileId}:`, error);\n throw new Error(`Failed to delete file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Creates a presigned upload URL for direct browser uploads\n *\n * @param client - The MinIO client to use\n * @param fileName - The file name to use\n * @param path - Optional path/folder\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @param expirySeconds - How long the URL should be valid for\n * @returns Presigned URL for PUT operation\n * @throws Will throw an error if URL creation fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, createPresignedUploadUrl } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * // Generate the presigned URL on the server\n * const url = await createPresignedUploadUrl(client, \"report.pdf\", \"documents/\");\n *\n * // Send the URL to the client/browser via HTTP response\n * return Response.json({ uploadUrl: url });\n *\n * // Then in the browser:\n * const response = await fetch('/api/get-upload-url');\n * const { uploadUrl } = await response.json();\n * await fetch(uploadUrl, {\n * method: 'PUT',\n * headers: { 'Content-Type': 'application/pdf' },\n * body: pdfFile\n * });\n */\nexport async function createPresignedUploadUrl(\n client: Client,\n fileName: string,\n path = \"\",\n bucket: string = DEFAULT_BUCKET,\n expirySeconds = 3600,\n): Promise<string> {\n ensureServer();\n try {\n const safeFileName = fileName.replace(/[^a-zA-Z0-9._-]/g, \"_\");\n const objectName = normalizePath(path, safeFileName);\n\n // Create operation for presigned PUT URL\n const presignedPutOperation = createPresignedPutOperation(bucket, objectName, expirySeconds);\n\n const url = await executeMinioOperation(client, presignedPutOperation);\n if (!url) {\n throw new Error(\"Failed to generate presigned upload URL\");\n }\n\n return url;\n } catch (error) {\n console.error(\"Failed to create presigned upload URL:\", error);\n throw new Error(`Failed to create presigned upload URL: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Uploads a buffer directly to storage\n *\n * @param client - The MinIO client to use\n * @param buffer - The buffer to upload\n * @param objectName - The full object name/path\n * @param contentType - The content type of the file\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns The uploaded file metadata\n * @throws Will throw an error if upload fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, uploadBuffer } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const buffer = Buffer.from(\"Hello, world!\");\n * const uploadedFile = await uploadFile(client, buffer, \"documents/hello.txt\", \"text/plain\");\n */\nexport async function uploadFile(\n client: Client,\n buffer: Buffer,\n objectName: string,\n contentType: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n try {\n // Add file metadata\n const metadata = {\n \"content-type\": contentType,\n \"upload-time\": new Date().toISOString(),\n };\n\n // Use the createSimpleUploadOperation\n const simpleUploadFn = createSimpleUploadOperation(client);\n const result = await simpleUploadFn(buffer, bucket, objectName, metadata);\n\n // Generate a presigned URL for immediate access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n objectName,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n const fileName = objectName.split(\"/\").pop() || objectName;\n\n const fileMetadata: FileMetadata = {\n id: objectName,\n name: fileName,\n contentType,\n size: buffer.length,\n uploadedAt: new Date().toISOString(),\n etag: result.etag,\n url,\n };\n\n return validate(FileMetadataSchema, fileMetadata);\n } catch (error) {\n console.error(\"Failed to upload file:\", error);\n throw new Error(`Failed to upload file: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n","import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport type { Client } from \"minio\";\nimport type { MinioOperation } from \"./operations.js\";\n\n/**\n * Executes a MinIO operation using the provided client\n *\n * @param client - MinIO client to use\n * @param operation - The operation to execute\n * @returns The result of the operation execution\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createServerMinioClient, createListObjectsOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n * const listOperation = createListObjectsOperation(\"my-bucket\", \"prefix/\");\n * const result = await executeMinioOperation(client, listOperation);\n */\nexport async function executeMinioOperation<T>(client: Client, operation: MinioOperation<T>): Promise<T> {\n ensureServer();\n\n return operation.execute(client);\n}\n","import type { Buffer } from \"node:buffer\";\nimport type { Client, ItemBucketMetadata } from \"minio\";\n\n/**\n * Base interface for all MinIO operations\n *\n * @template T The return type of the operation\n */\nexport interface MinioOperation<T> {\n execute: (client: Client) => Promise<T>;\n}\n\n/**\n * Creates an operation to list objects in a bucket\n *\n * @param bucket - The bucket name to list objects from\n * @param prefix - Optional prefix to filter objects (like a folder path)\n * @returns A MinioOperation that lists objects when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createListObjectsOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const listOperation = createListObjectsOperation(\"my-bucket\", \"folder/\");\n * const objects = await executeMinioOperation(client, listOperation);\n */\nexport function createListObjectsOperation(\n bucket: string,\n prefix = \"\",\n): MinioOperation<\n Array<{\n name: string;\n prefix?: string;\n size: number;\n etag: string;\n lastModified: Date;\n }>\n> {\n return {\n execute: async (client: Client) => {\n const objectsStream = client.listObjects(bucket, prefix, true);\n const objects: Array<{\n name: string;\n prefix?: string;\n size: number;\n etag: string;\n lastModified: Date;\n }> = [];\n\n return new Promise((resolve, reject) => {\n objectsStream.on(\"data\", (obj) => {\n // Ensure required properties are not undefined before adding to the array\n if (obj.name && typeof obj.size === \"number\" && obj.etag && obj.lastModified) {\n objects.push({\n name: obj.name,\n prefix: obj.prefix,\n size: obj.size,\n etag: obj.etag,\n lastModified: obj.lastModified,\n });\n }\n });\n\n objectsStream.on(\"error\", (err) => {\n reject(err);\n });\n\n objectsStream.on(\"end\", () => {\n resolve(objects);\n });\n });\n },\n };\n}\n\n/**\n * Creates an operation to get an object's metadata\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path\n * @returns A MinioOperation that gets object stats when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createStatObjectOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const statOperation = createStatObjectOperation(\"my-bucket\", \"folder/file.txt\");\n * const stats = await executeMinioOperation(client, statOperation);\n */\nexport function createStatObjectOperation(\n bucket: string,\n objectName: string,\n): MinioOperation<{\n size: number;\n etag: string;\n metaData: Record<string, string>;\n lastModified: Date;\n}> {\n return {\n execute: async (client: Client) => {\n return client.statObject(bucket, objectName);\n },\n };\n}\n\n/**\n * Creates an operation to upload a buffer to MinIO\n *\n * @param bucket - The bucket name to upload to\n * @param objectName - The object name/path to create\n * @param buffer - The buffer containing the file data\n * @param metadata - Optional metadata to attach to the object\n * @returns A MinioOperation that uploads the buffer when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createUploadOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const buffer = Buffer.from(\"file content\");\n * const uploadOperation = createUploadOperation(\"my-bucket\", \"folder/file.txt\", buffer, { \"content-type\": \"text/plain\" });\n * const result = await executeMinioOperation(client, uploadOperation);\n */\nexport function createUploadOperation(\n bucket: string,\n objectName: string,\n buffer: Buffer,\n metadata?: ItemBucketMetadata,\n): MinioOperation<{ etag: string }> {\n return {\n execute: async (client: Client) => {\n return client.putObject(bucket, objectName, buffer, undefined, metadata);\n },\n };\n}\n\n/**\n * Creates an operation to delete an object from MinIO\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path to delete\n * @returns A MinioOperation that deletes the object when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createDeleteOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const deleteOperation = createDeleteOperation(\"my-bucket\", \"folder/file.txt\");\n * await executeMinioOperation(client, deleteOperation);\n */\nexport function createDeleteOperation(bucket: string, objectName: string): MinioOperation<void> {\n return {\n execute: async (client: Client) => {\n return client.removeObject(bucket, objectName);\n },\n };\n}\n\n/**\n * Creates an operation to generate a presigned URL for an object\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path\n * @param expirySeconds - How long the URL should be valid for in seconds\n * @returns A MinioOperation that creates a presigned URL when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createPresignedUrlOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const urlOperation = createPresignedUrlOperation(\"my-bucket\", \"folder/file.txt\", 3600);\n * const url = await executeMinioOperation(client, urlOperation);\n */\nexport function createPresignedUrlOperation(\n bucket: string,\n objectName: string,\n expirySeconds: number,\n): MinioOperation<string> {\n return {\n execute: async (client: Client) => {\n return client.presignedGetObject(bucket, objectName, expirySeconds);\n },\n };\n}\n\n/**\n * Creates an operation to generate a presigned PUT URL for direct uploads\n *\n * @param bucket - The bucket name to upload to\n * @param objectName - The object name/path to create\n * @param expirySeconds - How long the URL should be valid for in seconds\n * @returns A MinioOperation that creates a presigned PUT URL when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createPresignedPutOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const putUrlOperation = createPresignedPutOperation(\"my-bucket\", \"folder/file.txt\", 3600);\n * const url = await executeMinioOperation(client, putUrlOperation);\n */\nexport function createPresignedPutOperation(\n bucket: string,\n objectName: string,\n expirySeconds: number,\n): MinioOperation<string> {\n return {\n execute: async (client: Client) => {\n // The MinIO client only accepts the first three parameters for presignedPutObject\n // Metadata needs to be applied when actually uploading via the presigned URL\n return client.presignedPutObject(bucket, objectName, expirySeconds);\n },\n };\n}\n\n/**\n * Creates a simplified upload function bound to a specific client\n *\n * @param client - The MinIO client to use for uploads\n * @returns A function that uploads buffers to MinIO\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createSimpleUploadOperation, getMinioClient } from \"@settlemint/sdk-minio\";\n *\n * const client = await getMinioClient();\n * const uploadFn = createSimpleUploadOperation(client);\n * const result = await uploadFn(buffer, \"my-bucket\", \"folder/file.txt\", { \"content-type\": \"text/plain\" });\n */\nexport function createSimpleUploadOperation(client: Client) {\n return async (\n buffer: Buffer,\n bucket: string,\n objectName: string,\n metadata?: ItemBucketMetadata,\n ): Promise<{ etag: string }> => {\n return client.putObject(bucket, objectName, buffer, undefined, metadata);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,kBAA6B;AAC7B,IAAAC,qBAAyB;AACzB,mBAAuB;;;ACFvB,wBAA0B;AAC1B,iBAAkB;AAKX,IAAM,4BAA4B,aAAE,OAAO;AAAA;AAAA,EAEhD,UAAU;AAAA;AAAA,EAEV,WAAW,aAAE,OAAO;AAAA;AAAA,EAEpB,WAAW,aAAE,OAAO;AACtB,CAAC;;;ACbD,IAAAC,cAAkB;AAeX,IAAM,qBAAqB,cAAE,OAAO;AAAA,EACzC,IAAI,cAAE,OAAO;AAAA,EACb,MAAM,cAAE,OAAO;AAAA,EACf,aAAa,cAAE,OAAO;AAAA,EACtB,MAAM,cAA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A,MACf,gBAAgB;AAAA,MAChB,gBAAe,oBAAI,KAAK,GAAE,YAAY;AAAA,IACxC;AAGA,UAAM,iBAAiB,4BAA4B,MAAM;AACzD,UAAM,SAAS,MAAM,eAAe,QAAQ,QAAQ,YAAY,QAAQ;AAGxE,UAAM,wBAAwB;AAAA,MAC5B;AAAA,MACA;AAAA,MACA;AAAA;AAAA,IACF;AACA,UAAM,MAAM,MAAM,sBAAsB,QAAQ,qBAAqB;AAErE,UAAM,WAAW,WAAW,MAAM,GAAG,EAAE,IAAI,KAAK;AAEhD,UAAM,eAA6B;AAAA,MACjC,IAAI;AAAA,MACJ,MAAM;AAAA,MACN;AAAA,MACA,MAAM,OAAO;AAAA,MACb,aAAY,oBAAI,KAAK,GAAE,YAAY;AAAA,MACnC,MAAM,OAAO;AAAA,MACb;AAAA,IACF;AAEA,eAAO,6BAAS,oBAAoB,YAAY;AAAA,EAClD,SAAS,OAAO;AACd,YAAQ,MAAM,0BAA0B,KAAK;AAC7C,UAAM,IAAI,MAAM,0BAA0B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,EACpG;AACF;;;AH1TO,SAAS,wBAAwB,SAAkD;AACxF,oCAAa;AACb,QAAM,uBAAmB,6BAAS,2BAA2B,OAAO;AAEpE,QAAM,MAAM,IAAI,IAAI,iBAAiB,QAAQ;AAC7C,SAAO;AAAA,IACL,QAAQ,IAAI,oBAAO;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,WAAW,iBAAiB;AAAA,MAC5B,WAAW,iBAAiB;AAAA,MAC5B,QAAQ,IAAI,aAAa;AAAA,MACzB,MAAM,IAAI,OAAO,OAAO,IAAI,IAAI,IAAI;AAAA,MACpC,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;","names":["import_runtime","import_validation","import_zod","import_runtime","import_validation"]}
package/dist/minio.d.cts CHANGED
@@ -28,44 +28,38 @@ declare const ServerClientOptionsSchema: z.ZodObject<{
28
28
  type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
29
29
 
30
30
  /**
31
- * Helper type to extract the inferred type from a Zod schema.
32
- *
33
- * @template T - The Zod schema type
34
- */
35
- type Static<T extends z.ZodType> = z.infer<T>;
36
- /**
37
- * Schema for file metadata stored in MinIO.
38
- * Defines the structure and validation rules for file information.
31
+ * Type representing file metadata after validation.
39
32
  */
40
- declare const FileMetadataSchema: z.ZodObject<{
41
- id: z.ZodString;
42
- name: z.ZodString;
43
- contentType: z.ZodString;
44
- size: z.ZodNumber;
45
- uploadedAt: z.ZodString;
46
- etag: z.ZodString;
47
- url: z.ZodOptional<z.ZodString>;
48
- }, "strip", z.ZodTypeAny, {
49
- id: string;
50
- name: string;
51
- contentType: string;
52
- size: number;
53
- uploadedAt: string;
54
- etag: string;
55
- url?: string | undefined;
56
- }, {
33
+ interface FileMetadata {
34
+ /**
35
+ * The unique identifier for the file.
36
+ */
57
37
  id: string;
38
+ /**
39
+ * The name of the file.
40
+ */
58
41
  name: string;
42
+ /**
43
+ * The content type of the file.
44
+ */
59
45
  contentType: string;
46
+ /**
47
+ * The size of the file in bytes.
48
+ */
60
49
  size: number;
50
+ /**
51
+ * The date and time the file was uploaded.
52
+ */
61
53
  uploadedAt: string;
54
+ /**
55
+ * The ETag of the file.
56
+ */
62
57
  etag: string;
63
- url?: string | undefined;
64
- }>;
65
- /**
66
- * Type representing file metadata after validation.
67
- */
68
- type FileMetadata = Static<typeof FileMetadataSchema>;
58
+ /**
59
+ * The URL of the file.
60
+ */
61
+ url?: string;
62
+ }
69
63
  /**
70
64
  * Default bucket name to use for file storage when none is specified.
71
65
  */
@@ -216,4 +210,4 @@ declare function createServerMinioClient(options: ServerClientOptions): {
216
210
  client: Client;
217
211
  };
218
212
 
219
- export { DEFAULT_BUCKET, type FileMetadata, FileMetadataSchema, type Static, createPresignedUploadUrl, createServerMinioClient, deleteFile, getFileById, getFilesList, uploadFile };
213
+ export { DEFAULT_BUCKET, type FileMetadata, createPresignedUploadUrl, createServerMinioClient, deleteFile, getFileById, getFilesList, uploadFile };
package/dist/minio.d.ts CHANGED
@@ -28,44 +28,38 @@ declare const ServerClientOptionsSchema: z.ZodObject<{
28
28
  type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
29
29
 
30
30
  /**
31
- * Helper type to extract the inferred type from a Zod schema.
32
- *
33
- * @template T - The Zod schema type
34
- */
35
- type Static<T extends z.ZodType> = z.infer<T>;
36
- /**
37
- * Schema for file metadata stored in MinIO.
38
- * Defines the structure and validation rules for file information.
31
+ * Type representing file metadata after validation.
39
32
  */
40
- declare const FileMetadataSchema: z.ZodObject<{
41
- id: z.ZodString;
42
- name: z.ZodString;
43
- contentType: z.ZodString;
44
- size: z.ZodNumber;
45
- uploadedAt: z.ZodString;
46
- etag: z.ZodString;
47
- url: z.ZodOptional<z.ZodString>;
48
- }, "strip", z.ZodTypeAny, {
49
- id: string;
50
- name: string;
51
- contentType: string;
52
- size: number;
53
- uploadedAt: string;
54
- etag: string;
55
- url?: string | undefined;
56
- }, {
33
+ interface FileMetadata {
34
+ /**
35
+ * The unique identifier for the file.
36
+ */
57
37
  id: string;
38
+ /**
39
+ * The name of the file.
40
+ */
58
41
  name: string;
42
+ /**
43
+ * The content type of the file.
44
+ */
59
45
  contentType: string;
46
+ /**
47
+ * The size of the file in bytes.
48
+ */
60
49
  size: number;
50
+ /**
51
+ * The date and time the file was uploaded.
52
+ */
61
53
  uploadedAt: string;
54
+ /**
55
+ * The ETag of the file.
56
+ */
62
57
  etag: string;
63
- url?: string | undefined;
64
- }>;
65
- /**
66
- * Type representing file metadata after validation.
67
- */
68
- type FileMetadata = Static<typeof FileMetadataSchema>;
58
+ /**
59
+ * The URL of the file.
60
+ */
61
+ url?: string;
62
+ }
69
63
  /**
70
64
  * Default bucket name to use for file storage when none is specified.
71
65
  */
@@ -216,4 +210,4 @@ declare function createServerMinioClient(options: ServerClientOptions): {
216
210
  client: Client;
217
211
  };
218
212
 
219
- export { DEFAULT_BUCKET, type FileMetadata, FileMetadataSchema, type Static, createPresignedUploadUrl, createServerMinioClient, deleteFile, getFileById, getFilesList, uploadFile };
213
+ export { DEFAULT_BUCKET, type FileMetadata, createPresignedUploadUrl, createServerMinioClient, deleteFile, getFileById, getFilesList, uploadFile };
package/dist/minio.mjs CHANGED
@@ -15,6 +15,19 @@ 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
+
18
31
  // src/helpers/functions.ts
19
32
  import { ensureServer as ensureServer2 } from "@settlemint/sdk-utils/runtime";
20
33
  import { validate } from "@settlemint/sdk-utils/validation";
@@ -88,19 +101,6 @@ function createSimpleUploadOperation(client) {
88
101
  };
89
102
  }
90
103
 
91
- // src/helpers/schema.ts
92
- import { z as z2 } from "zod";
93
- var FileMetadataSchema = z2.object({
94
- id: z2.string(),
95
- name: z2.string(),
96
- contentType: z2.string(),
97
- size: z2.number(),
98
- uploadedAt: z2.string().datetime(),
99
- etag: z2.string(),
100
- url: z2.string().url().optional()
101
- });
102
- var DEFAULT_BUCKET = "uploads";
103
-
104
104
  // src/helpers/functions.ts
105
105
  function normalizePath(path, fileName) {
106
106
  if (path.length > 1e3) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/minio.ts","../src/helpers/client-options.schema.ts","../src/helpers/functions.ts","../src/helpers/executor.ts","../src/helpers/operations.ts","../src/helpers/schema.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { Client } from \"minio\";\nimport { type ServerClientOptions, ServerClientOptionsSchema } from \"./helpers/client-options.schema.js\";\n\n/**\n * Creates a MinIO client for server-side use with authentication.\n *\n * @param options - The server client options for configuring the MinIO client\n * @returns An object containing the initialized MinIO client\n * @throws Will throw an error if not called on the server or if the options fail validation\n *\n * @example\n * import { createServerMinioClient } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n * client.listBuckets();\n */\nexport function createServerMinioClient(options: ServerClientOptions): { client: Client } {\n ensureServer();\n const validatedOptions = validate(ServerClientOptionsSchema, options);\n\n const url = new URL(validatedOptions.instance);\n return {\n client: new Client({\n endPoint: url.hostname,\n accessKey: validatedOptions.accessKey,\n secretKey: validatedOptions.secretKey,\n useSSL: url.protocol !== \"http:\",\n port: url.port ? Number(url.port) : undefined,\n region: \"eu-central-1\",\n }),\n };\n}\n\n// Export high-level functions\nexport {\n getFilesList,\n getFileById,\n uploadFile,\n deleteFile,\n createPresignedUploadUrl,\n} from \"./helpers/functions.js\";\n\n// Export validation utilities and schemas\nexport {\n type FileMetadata,\n type FileMetadataSchema,\n type Static,\n DEFAULT_BUCKET,\n} from \"./helpers/schema.js\";\n\n// Re-export required types from minio\nexport type { Client, ItemBucketMetadata } from \"minio\";\n","import { UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { z } from \"zod\";\n\n/**\n * Schema for validating server client options for the MinIO client.\n */\nexport const ServerClientOptionsSchema = z.object({\n /** The URL of the MinIO instance to connect to */\n instance: UrlSchema,\n /** The MinIO access key used to authenticate with the MinIO server */\n accessKey: z.string(),\n /** The MinIO secret key used to authenticate with the MinIO server */\n secretKey: z.string(),\n});\n\n/**\n * Type definition for server client options derived from the ServerClientOptionsSchema.\n */\nexport type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;\n","import type { Buffer } from \"node:buffer\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport type { Client } from \"minio\";\nimport { executeMinioOperation } from \"./executor.js\";\nimport {\n createDeleteOperation,\n createListObjectsOperation,\n createPresignedPutOperation,\n createPresignedUrlOperation,\n createSimpleUploadOperation,\n createStatObjectOperation,\n} from \"./operations.js\";\nimport { DEFAULT_BUCKET, type FileMetadata, FileMetadataSchema } from \"./schema.js\";\n\n/**\n * Helper function to normalize paths and prevent double slashes\n *\n * @param path - The path to normalize\n * @param fileName - The filename to append\n * @returns The normalized path with filename\n * @throws Will throw an error if the path is too long (max 1000 characters)\n */\nfunction normalizePath(path: string, fileName: string): string {\n if (path.length > 1_000) {\n throw new Error(\"Path is too long\");\n }\n\n // Remove trailing slashes from path\n const cleanPath = path.replace(/\\/+$/, \"\");\n\n // If path is empty, return just the filename\n if (!cleanPath) {\n return fileName;\n }\n\n // Join with a single slash\n return `${cleanPath}/${fileName}`;\n}\n\n/**\n * Gets a list of files with optional prefix filter\n *\n * @param client - The MinIO client to use\n * @param prefix - Optional prefix to filter files (like a folder path)\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns Array of file metadata objects\n * @throws Will throw an error if the operation fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, getFilesList } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const files = await getFilesList(client, \"documents/\");\n */\nexport async function getFilesList(\n client: Client,\n prefix = \"\",\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata[]> {\n ensureServer();\n console.log(`Listing files with prefix: \"${prefix}\" in bucket: \"${bucket}\"`);\n\n try {\n const listOperation = createListObjectsOperation(bucket, prefix);\n const objects = await executeMinioOperation(client, listOperation);\n console.log(`Found ${objects.length} files in MinIO`);\n\n const fileObjects = await Promise.all(\n objects.map(async (obj): Promise<FileMetadata> => {\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n obj.name,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n return {\n id: obj.name,\n name: obj.name.split(\"/\").pop() || obj.name,\n contentType: \"application/octet-stream\", // Default type\n size: obj.size,\n uploadedAt: obj.lastModified.toISOString(),\n etag: obj.etag,\n url,\n };\n }),\n );\n\n return validate(FileMetadataSchema.array(), fileObjects);\n } catch (error) {\n console.error(\"Failed to list files:\", error);\n throw new Error(`Failed to list files: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Gets a single file by its object name\n *\n * @param client - The MinIO client to use\n * @param fileId - The file identifier/path\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns File metadata with presigned URL\n * @throws Will throw an error if the file doesn't exist or client initialization fails\n *\n * @example\n * import { createServerMinioClient, getFileByObjectName } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const file = await getFileByObjectName(client, \"documents/report.pdf\");\n */\nexport async function getFileById(\n client: Client,\n fileId: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n console.log(`Getting file details for: ${fileId} in bucket: ${bucket}`);\n\n try {\n // Get the file metadata\n const statOperation = createStatObjectOperation(bucket, fileId);\n const statResult = await executeMinioOperation(client, statOperation);\n\n // Generate a presigned URL for access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n fileId,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n // Try to get size from metadata first, then from stat result\n let size = 0;\n\n // Check for content-length in metadata\n if (statResult.metaData[\"content-length\"]) {\n const parsedSize = Number.parseInt(statResult.metaData[\"content-length\"], 10);\n if (!Number.isNaN(parsedSize)) {\n size = parsedSize;\n }\n }\n // Fallback to statResult.size if available and valid\n else if (typeof statResult.size === \"number\" && !Number.isNaN(statResult.size)) {\n size = statResult.size;\n }\n\n const fileMetadata: FileMetadata = {\n id: fileId,\n name: fileId.split(\"/\").pop() || fileId,\n contentType: statResult.metaData[\"content-type\"] || \"application/octet-stream\",\n size,\n uploadedAt: statResult.lastModified.toISOString(),\n etag: statResult.etag,\n url,\n };\n\n return validate(FileMetadataSchema, fileMetadata);\n } catch (error) {\n console.error(`Failed to get file ${fileId}:`, error);\n throw new Error(`Failed to get file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Deletes a file from storage\n *\n * @param client - The MinIO client to use\n * @param fileId - The file identifier/path\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns Success status\n * @throws Will throw an error if deletion fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, deleteFile } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * await deleteFile(client, \"documents/report.pdf\");\n */\nexport async function deleteFile(client: Client, fileId: string, bucket: string = DEFAULT_BUCKET): Promise<boolean> {\n ensureServer();\n try {\n const deleteOperation = createDeleteOperation(bucket, fileId);\n await executeMinioOperation(client, deleteOperation);\n return true;\n } catch (error) {\n console.error(`Failed to delete file ${fileId}:`, error);\n throw new Error(`Failed to delete file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Creates a presigned upload URL for direct browser uploads\n *\n * @param client - The MinIO client to use\n * @param fileName - The file name to use\n * @param path - Optional path/folder\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @param expirySeconds - How long the URL should be valid for\n * @returns Presigned URL for PUT operation\n * @throws Will throw an error if URL creation fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, createPresignedUploadUrl } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * // Generate the presigned URL on the server\n * const url = await createPresignedUploadUrl(client, \"report.pdf\", \"documents/\");\n *\n * // Send the URL to the client/browser via HTTP response\n * return Response.json({ uploadUrl: url });\n *\n * // Then in the browser:\n * const response = await fetch('/api/get-upload-url');\n * const { uploadUrl } = await response.json();\n * await fetch(uploadUrl, {\n * method: 'PUT',\n * headers: { 'Content-Type': 'application/pdf' },\n * body: pdfFile\n * });\n */\nexport async function createPresignedUploadUrl(\n client: Client,\n fileName: string,\n path = \"\",\n bucket: string = DEFAULT_BUCKET,\n expirySeconds = 3600,\n): Promise<string> {\n ensureServer();\n try {\n const safeFileName = fileName.replace(/[^a-zA-Z0-9._-]/g, \"_\");\n const objectName = normalizePath(path, safeFileName);\n\n // Create operation for presigned PUT URL\n const presignedPutOperation = createPresignedPutOperation(bucket, objectName, expirySeconds);\n\n const url = await executeMinioOperation(client, presignedPutOperation);\n if (!url) {\n throw new Error(\"Failed to generate presigned upload URL\");\n }\n\n return url;\n } catch (error) {\n console.error(\"Failed to create presigned upload URL:\", error);\n throw new Error(`Failed to create presigned upload URL: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Uploads a buffer directly to storage\n *\n * @param client - The MinIO client to use\n * @param buffer - The buffer to upload\n * @param objectName - The full object name/path\n * @param contentType - The content type of the file\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns The uploaded file metadata\n * @throws Will throw an error if upload fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, uploadBuffer } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const buffer = Buffer.from(\"Hello, world!\");\n * const uploadedFile = await uploadFile(client, buffer, \"documents/hello.txt\", \"text/plain\");\n */\nexport async function uploadFile(\n client: Client,\n buffer: Buffer,\n objectName: string,\n contentType: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n try {\n // Add file metadata\n const metadata = {\n \"content-type\": contentType,\n \"upload-time\": new Date().toISOString(),\n };\n\n // Use the createSimpleUploadOperation\n const simpleUploadFn = createSimpleUploadOperation(client);\n const result = await simpleUploadFn(buffer, bucket, objectName, metadata);\n\n // Generate a presigned URL for immediate access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n objectName,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n const fileName = objectName.split(\"/\").pop() || objectName;\n\n const fileMetadata: FileMetadata = {\n id: objectName,\n name: fileName,\n contentType,\n size: buffer.length,\n uploadedAt: new Date().toISOString(),\n etag: result.etag,\n url,\n };\n\n return validate(FileMetadataSchema, fileMetadata);\n } catch (error) {\n console.error(\"Failed to upload file:\", error);\n throw new Error(`Failed to upload file: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n","import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport type { Client } from \"minio\";\nimport type { MinioOperation } from \"./operations.js\";\n\n/**\n * Executes a MinIO operation using the provided client\n *\n * @param client - MinIO client to use\n * @param operation - The operation to execute\n * @returns The result of the operation execution\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createServerMinioClient, createListObjectsOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n * const listOperation = createListObjectsOperation(\"my-bucket\", \"prefix/\");\n * const result = await executeMinioOperation(client, listOperation);\n */\nexport async function executeMinioOperation<T>(client: Client, operation: MinioOperation<T>): Promise<T> {\n ensureServer();\n\n return operation.execute(client);\n}\n","import type { Buffer } from \"node:buffer\";\nimport type { Client, ItemBucketMetadata } from \"minio\";\n\n/**\n * Base interface for all MinIO operations\n *\n * @template T The return type of the operation\n */\nexport interface MinioOperation<T> {\n execute: (client: Client) => Promise<T>;\n}\n\n/**\n * Creates an operation to list objects in a bucket\n *\n * @param bucket - The bucket name to list objects from\n * @param prefix - Optional prefix to filter objects (like a folder path)\n * @returns A MinioOperation that lists objects when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createListObjectsOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const listOperation = createListObjectsOperation(\"my-bucket\", \"folder/\");\n * const objects = await executeMinioOperation(client, listOperation);\n */\nexport function createListObjectsOperation(\n bucket: string,\n prefix = \"\",\n): MinioOperation<\n Array<{\n name: string;\n prefix?: string;\n size: number;\n etag: string;\n lastModified: Date;\n }>\n> {\n return {\n execute: async (client: Client) => {\n const objectsStream = client.listObjects(bucket, prefix, true);\n const objects: Array<{\n name: string;\n prefix?: string;\n size: number;\n etag: string;\n lastModified: Date;\n }> = [];\n\n return new Promise((resolve, reject) => {\n objectsStream.on(\"data\", (obj) => {\n // Ensure required properties are not undefined before adding to the array\n if (obj.name && typeof obj.size === \"number\" && obj.etag && obj.lastModified) {\n objects.push({\n name: obj.name,\n prefix: obj.prefix,\n size: obj.size,\n etag: obj.etag,\n lastModified: obj.lastModified,\n });\n }\n });\n\n objectsStream.on(\"error\", (err) => {\n reject(err);\n });\n\n objectsStream.on(\"end\", () => {\n resolve(objects);\n });\n });\n },\n };\n}\n\n/**\n * Creates an operation to get an object's metadata\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path\n * @returns A MinioOperation that gets object stats when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createStatObjectOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const statOperation = createStatObjectOperation(\"my-bucket\", \"folder/file.txt\");\n * const stats = await executeMinioOperation(client, statOperation);\n */\nexport function createStatObjectOperation(\n bucket: string,\n objectName: string,\n): MinioOperation<{\n size: number;\n etag: string;\n metaData: Record<string, string>;\n lastModified: Date;\n}> {\n return {\n execute: async (client: Client) => {\n return client.statObject(bucket, objectName);\n },\n };\n}\n\n/**\n * Creates an operation to upload a buffer to MinIO\n *\n * @param bucket - The bucket name to upload to\n * @param objectName - The object name/path to create\n * @param buffer - The buffer containing the file data\n * @param metadata - Optional metadata to attach to the object\n * @returns A MinioOperation that uploads the buffer when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createUploadOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const buffer = Buffer.from(\"file content\");\n * const uploadOperation = createUploadOperation(\"my-bucket\", \"folder/file.txt\", buffer, { \"content-type\": \"text/plain\" });\n * const result = await executeMinioOperation(client, uploadOperation);\n */\nexport function createUploadOperation(\n bucket: string,\n objectName: string,\n buffer: Buffer,\n metadata?: ItemBucketMetadata,\n): MinioOperation<{ etag: string }> {\n return {\n execute: async (client: Client) => {\n return client.putObject(bucket, objectName, buffer, undefined, metadata);\n },\n };\n}\n\n/**\n * Creates an operation to delete an object from MinIO\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path to delete\n * @returns A MinioOperation that deletes the object when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createDeleteOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const deleteOperation = createDeleteOperation(\"my-bucket\", \"folder/file.txt\");\n * await executeMinioOperation(client, deleteOperation);\n */\nexport function createDeleteOperation(bucket: string, objectName: string): MinioOperation<void> {\n return {\n execute: async (client: Client) => {\n return client.removeObject(bucket, objectName);\n },\n };\n}\n\n/**\n * Creates an operation to generate a presigned URL for an object\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path\n * @param expirySeconds - How long the URL should be valid for in seconds\n * @returns A MinioOperation that creates a presigned URL when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createPresignedUrlOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const urlOperation = createPresignedUrlOperation(\"my-bucket\", \"folder/file.txt\", 3600);\n * const url = await executeMinioOperation(client, urlOperation);\n */\nexport function createPresignedUrlOperation(\n bucket: string,\n objectName: string,\n expirySeconds: number,\n): MinioOperation<string> {\n return {\n execute: async (client: Client) => {\n return client.presignedGetObject(bucket, objectName, expirySeconds);\n },\n };\n}\n\n/**\n * Creates an operation to generate a presigned PUT URL for direct uploads\n *\n * @param bucket - The bucket name to upload to\n * @param objectName - The object name/path to create\n * @param expirySeconds - How long the URL should be valid for in seconds\n * @returns A MinioOperation that creates a presigned PUT URL when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createPresignedPutOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const putUrlOperation = createPresignedPutOperation(\"my-bucket\", \"folder/file.txt\", 3600);\n * const url = await executeMinioOperation(client, putUrlOperation);\n */\nexport function createPresignedPutOperation(\n bucket: string,\n objectName: string,\n expirySeconds: number,\n): MinioOperation<string> {\n return {\n execute: async (client: Client) => {\n // The MinIO client only accepts the first three parameters for presignedPutObject\n // Metadata needs to be applied when actually uploading via the presigned URL\n return client.presignedPutObject(bucket, objectName, expirySeconds);\n },\n };\n}\n\n/**\n * Creates a simplified upload function bound to a specific client\n *\n * @param client - The MinIO client to use for uploads\n * @returns A function that uploads buffers to MinIO\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createSimpleUploadOperation, getMinioClient } from \"@settlemint/sdk-minio\";\n *\n * const client = await getMinioClient();\n * const uploadFn = createSimpleUploadOperation(client);\n * const result = await uploadFn(buffer, \"my-bucket\", \"folder/file.txt\", { \"content-type\": \"text/plain\" });\n */\nexport function createSimpleUploadOperation(client: Client) {\n return async (\n buffer: Buffer,\n bucket: string,\n objectName: string,\n metadata?: ItemBucketMetadata,\n ): Promise<{ etag: string }> => {\n return client.putObject(bucket, objectName, buffer, undefined, metadata);\n };\n}\n","import { z } from \"zod\";\n\n/**\n * Helper type to extract the inferred type from a Zod schema.\n *\n * @template T - The Zod schema type\n */\nexport type Static<T extends z.ZodType> = z.infer<T>;\n\n// ----- Schema Definitions -----\n\n/**\n * Schema for file metadata stored in MinIO.\n * Defines the structure and validation rules for file information.\n */\nexport const FileMetadataSchema = z.object({\n id: z.string(),\n name: z.string(),\n contentType: z.string(),\n size: z.number(),\n uploadedAt: z.string().datetime(),\n etag: z.string(),\n url: z.string().url().optional(),\n});\n\n/**\n * Type representing file metadata after validation.\n */\nexport type FileMetadata = Static<typeof FileMetadataSchema>;\n\n/**\n * Default bucket name to use for file storage when none is specified.\n */\nexport const DEFAULT_BUCKET = \"uploads\";\n"],"mappings":";AAAA,SAAS,gBAAAA,qBAAoB;AAC7B,SAAS,YAAAC,iBAAgB;AACzB,SAAS,cAAc;;;ACFvB,SAAS,iBAAiB;AAC1B,SAAS,SAAS;AAKX,IAAM,4BAA4B,EAAE,OAAO;AAAA;AAAA,EAEhD,UAAU;AAAA;AAAA,EAEV,WAAW,EAAE,OAAO;AAAA;AAAA,EAEpB,WAAW,EAAE,OAAO;AACtB,CAAC;;;ACZD,SAAS,gBAAAC,qBAAoB;AAC7B,SAAS,gBAAgB;;;ACFzB,SAAS,oBAAoB;AAsB7B,eAAsB,sBAAyB,QAAgB,WAA0C;AACvG,eAAa;AAEb,SAAO,UAAU,QAAQ,MAAM;AACjC;;;ACAO,SAAS,2BACd,QACA,SAAS,IAST;AACA,SAAO;AAAA,IACL,SAAS,OAAO,WAAmB;AACjC,YAAM,gBAAgB,OAAO,YAAY,QAAQ,QAAQ,IAAI;AAC7D,YAAM,UAMD,CAAC;AAEN,a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,UAAM,SAAS,MAAM,eAAe,QAAQ,QAAQ,YAAY,QAAQ;AAGxE,UAAM,wBAAwB;AAAA,MAC5B;AAAA,MACA;AAAA,MACA;AAAA;AAAA,IACF;AACA,UAAM,MAAM,MAAM,sBAAsB,QAAQ,qBAAqB;AAErE,UAAM,WAAW,WAAW,MAAM,GAAG,EAAE,IAAI,KAAK;AAEhD,UAAM,eAA6B;AAAA,MACjC,IAAI;AAAA,MACJ,MAAM;AAAA,MACN;AAAA,MACA,MAAM,OAAO;AAAA,MACb,aAAY,oBAAI,KAAK,GAAE,YAAY;AAAA,MACnC,MAAM,OAAO;AAAA,MACb;AAAA,IACF;AAEA,WAAO,SAAS,oBAAoB,YAAY;AAAA,EAClD,SAAS,OAAO;AACd,YAAQ,MAAM,0BAA0B,KAAK;AAC7C,UAAM,IAAI,MAAM,0BAA0B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,EACpG;AACF;;;AFzTO,SAAS,wBAAwB,SAAkD;AACxF,EAAAC,cAAa;AACb,QAAM,mBAAmBC,UAAS,2BAA2B,OAAO;AAEpE,QAAM,MAAM,IAAI,IAAI,iBAAiB,QAAQ;AAC7C,SAAO;AAAA,IACL,QAAQ,IAAI,OAAO;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,WAAW,iBAAiB;AAAA,MAC5B,WAAW,iBAAiB;AAAA,MAC5B,QAAQ,IAAI,aAAa;AAAA,MACzB,MAAM,IAAI,OAAO,OAAO,IAAI,IAAI,IAAI;AAAA,MACpC,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;","names":["ensureServer","validate","ensureServer","z","ensureServer","ensureServer","validate"]}
1
+ {"version":3,"sources":["../src/minio.ts","../src/helpers/client-options.schema.ts","../src/helpers/schema.ts","../src/helpers/functions.ts","../src/helpers/executor.ts","../src/helpers/operations.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { Client } from \"minio\";\nimport { type ServerClientOptions, ServerClientOptionsSchema } from \"./helpers/client-options.schema.js\";\n\n/**\n * Creates a MinIO client for server-side use with authentication.\n *\n * @param options - The server client options for configuring the MinIO client\n * @returns An object containing the initialized MinIO client\n * @throws Will throw an error if not called on the server or if the options fail validation\n *\n * @example\n * import { createServerMinioClient } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n * client.listBuckets();\n */\nexport function createServerMinioClient(options: ServerClientOptions): { client: Client } {\n ensureServer();\n const validatedOptions = validate(ServerClientOptionsSchema, options);\n\n const url = new URL(validatedOptions.instance);\n return {\n client: new Client({\n endPoint: url.hostname,\n accessKey: validatedOptions.accessKey,\n secretKey: validatedOptions.secretKey,\n useSSL: url.protocol !== \"http:\",\n port: url.port ? Number(url.port) : undefined,\n region: \"eu-central-1\",\n }),\n };\n}\n// Export validation utilities and schemas\nexport {\n type FileMetadata,\n DEFAULT_BUCKET,\n} from \"./helpers/schema.js\";\n\n// Export high-level functions\nexport {\n getFilesList,\n getFileById,\n uploadFile,\n deleteFile,\n createPresignedUploadUrl,\n} from \"./helpers/functions.js\";\n\n// Re-export required types from minio\nexport type { Client, ItemBucketMetadata } from \"minio\";\n","import { UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { z } from \"zod\";\n\n/**\n * Schema for validating server client options for the MinIO client.\n */\nexport const ServerClientOptionsSchema = z.object({\n /** The URL of the MinIO instance to connect to */\n instance: UrlSchema,\n /** The MinIO access key used to authenticate with the MinIO server */\n accessKey: z.string(),\n /** The MinIO secret key used to authenticate with the MinIO server */\n secretKey: z.string(),\n});\n\n/**\n * Type definition for server client options derived from the ServerClientOptionsSchema.\n */\nexport type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;\n","import { z } from \"zod\";\n\n/**\n * Helper type to extract the inferred type from a Zod schema.\n *\n * @template T - The Zod schema type\n */\nexport type Static<T extends z.ZodType> = z.infer<T>;\n\n// ----- Schema Definitions -----\n\n/**\n * Schema for file metadata stored in MinIO.\n * Defines the structure and validation rules for file information.\n */\nexport const FileMetadataSchema = z.object({\n id: z.string(),\n name: z.string(),\n contentType: z.string(),\n size: z.number(),\n uploadedAt: z.string().datetime(),\n etag: z.string(),\n url: z.string().url().optional(),\n});\n\n/**\n * Type representing file metadata after validation.\n */\nexport interface FileMetadata {\n /**\n * The unique identifier for the file.\n */\n id: string;\n /**\n * The name of the file.\n */\n name: string;\n /**\n * The content type of the file.\n */\n contentType: string;\n\n /**\n * The size of the file in bytes.\n */\n size: number;\n\n /**\n * The date and time the file was uploaded.\n */\n uploadedAt: string;\n\n /**\n * The ETag of the file.\n */\n etag: string;\n\n /**\n * The URL of the file.\n */\n url?: string;\n}\n\n/**\n * Default bucket name to use for file storage when none is specified.\n */\nexport const DEFAULT_BUCKET = \"uploads\";\n","import type { Buffer } from \"node:buffer\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport type { Client } from \"minio\";\nimport { executeMinioOperation } from \"./executor.js\";\nimport {\n createDeleteOperation,\n createListObjectsOperation,\n createPresignedPutOperation,\n createPresignedUrlOperation,\n createSimpleUploadOperation,\n createStatObjectOperation,\n} from \"./operations.js\";\nimport { DEFAULT_BUCKET, FileMetadataSchema } from \"./schema.js\";\nimport type { FileMetadata } from \"./schema.js\";\n\n/**\n * Helper function to normalize paths and prevent double slashes\n *\n * @param path - The path to normalize\n * @param fileName - The filename to append\n * @returns The normalized path with filename\n * @throws Will throw an error if the path is too long (max 1000 characters)\n */\nfunction normalizePath(path: string, fileName: string): string {\n if (path.length > 1_000) {\n throw new Error(\"Path is too long\");\n }\n\n // Remove trailing slashes from path\n const cleanPath = path.replace(/\\/+$/, \"\");\n\n // If path is empty, return just the filename\n if (!cleanPath) {\n return fileName;\n }\n\n // Join with a single slash\n return `${cleanPath}/${fileName}`;\n}\n\n/**\n * Gets a list of files with optional prefix filter\n *\n * @param client - The MinIO client to use\n * @param prefix - Optional prefix to filter files (like a folder path)\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns Array of file metadata objects\n * @throws Will throw an error if the operation fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, getFilesList } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const files = await getFilesList(client, \"documents/\");\n */\nexport async function getFilesList(\n client: Client,\n prefix = \"\",\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata[]> {\n ensureServer();\n console.log(`Listing files with prefix: \"${prefix}\" in bucket: \"${bucket}\"`);\n\n try {\n const listOperation = createListObjectsOperation(bucket, prefix);\n const objects = await executeMinioOperation(client, listOperation);\n console.log(`Found ${objects.length} files in MinIO`);\n\n const fileObjects = await Promise.all(\n objects.map(async (obj): Promise<FileMetadata> => {\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n obj.name,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n return {\n id: obj.name,\n name: obj.name.split(\"/\").pop() || obj.name,\n contentType: \"application/octet-stream\", // Default type\n size: obj.size,\n uploadedAt: obj.lastModified.toISOString(),\n etag: obj.etag,\n url,\n };\n }),\n );\n\n return validate(FileMetadataSchema.array(), fileObjects);\n } catch (error) {\n console.error(\"Failed to list files:\", error);\n throw new Error(`Failed to list files: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Gets a single file by its object name\n *\n * @param client - The MinIO client to use\n * @param fileId - The file identifier/path\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns File metadata with presigned URL\n * @throws Will throw an error if the file doesn't exist or client initialization fails\n *\n * @example\n * import { createServerMinioClient, getFileByObjectName } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const file = await getFileByObjectName(client, \"documents/report.pdf\");\n */\nexport async function getFileById(\n client: Client,\n fileId: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n console.log(`Getting file details for: ${fileId} in bucket: ${bucket}`);\n\n try {\n // Get the file metadata\n const statOperation = createStatObjectOperation(bucket, fileId);\n const statResult = await executeMinioOperation(client, statOperation);\n\n // Generate a presigned URL for access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n fileId,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n // Try to get size from metadata first, then from stat result\n let size = 0;\n\n // Check for content-length in metadata\n if (statResult.metaData[\"content-length\"]) {\n const parsedSize = Number.parseInt(statResult.metaData[\"content-length\"], 10);\n if (!Number.isNaN(parsedSize)) {\n size = parsedSize;\n }\n }\n // Fallback to statResult.size if available and valid\n else if (typeof statResult.size === \"number\" && !Number.isNaN(statResult.size)) {\n size = statResult.size;\n }\n\n const fileMetadata: FileMetadata = {\n id: fileId,\n name: fileId.split(\"/\").pop() || fileId,\n contentType: statResult.metaData[\"content-type\"] || \"application/octet-stream\",\n size,\n uploadedAt: statResult.lastModified.toISOString(),\n etag: statResult.etag,\n url,\n };\n\n return validate(FileMetadataSchema, fileMetadata);\n } catch (error) {\n console.error(`Failed to get file ${fileId}:`, error);\n throw new Error(`Failed to get file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Deletes a file from storage\n *\n * @param client - The MinIO client to use\n * @param fileId - The file identifier/path\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns Success status\n * @throws Will throw an error if deletion fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, deleteFile } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * await deleteFile(client, \"documents/report.pdf\");\n */\nexport async function deleteFile(client: Client, fileId: string, bucket: string = DEFAULT_BUCKET): Promise<boolean> {\n ensureServer();\n try {\n const deleteOperation = createDeleteOperation(bucket, fileId);\n await executeMinioOperation(client, deleteOperation);\n return true;\n } catch (error) {\n console.error(`Failed to delete file ${fileId}:`, error);\n throw new Error(`Failed to delete file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Creates a presigned upload URL for direct browser uploads\n *\n * @param client - The MinIO client to use\n * @param fileName - The file name to use\n * @param path - Optional path/folder\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @param expirySeconds - How long the URL should be valid for\n * @returns Presigned URL for PUT operation\n * @throws Will throw an error if URL creation fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, createPresignedUploadUrl } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * // Generate the presigned URL on the server\n * const url = await createPresignedUploadUrl(client, \"report.pdf\", \"documents/\");\n *\n * // Send the URL to the client/browser via HTTP response\n * return Response.json({ uploadUrl: url });\n *\n * // Then in the browser:\n * const response = await fetch('/api/get-upload-url');\n * const { uploadUrl } = await response.json();\n * await fetch(uploadUrl, {\n * method: 'PUT',\n * headers: { 'Content-Type': 'application/pdf' },\n * body: pdfFile\n * });\n */\nexport async function createPresignedUploadUrl(\n client: Client,\n fileName: string,\n path = \"\",\n bucket: string = DEFAULT_BUCKET,\n expirySeconds = 3600,\n): Promise<string> {\n ensureServer();\n try {\n const safeFileName = fileName.replace(/[^a-zA-Z0-9._-]/g, \"_\");\n const objectName = normalizePath(path, safeFileName);\n\n // Create operation for presigned PUT URL\n const presignedPutOperation = createPresignedPutOperation(bucket, objectName, expirySeconds);\n\n const url = await executeMinioOperation(client, presignedPutOperation);\n if (!url) {\n throw new Error(\"Failed to generate presigned upload URL\");\n }\n\n return url;\n } catch (error) {\n console.error(\"Failed to create presigned upload URL:\", error);\n throw new Error(`Failed to create presigned upload URL: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\n/**\n * Uploads a buffer directly to storage\n *\n * @param client - The MinIO client to use\n * @param buffer - The buffer to upload\n * @param objectName - The full object name/path\n * @param contentType - The content type of the file\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns The uploaded file metadata\n * @throws Will throw an error if upload fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, uploadBuffer } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const buffer = Buffer.from(\"Hello, world!\");\n * const uploadedFile = await uploadFile(client, buffer, \"documents/hello.txt\", \"text/plain\");\n */\nexport async function uploadFile(\n client: Client,\n buffer: Buffer,\n objectName: string,\n contentType: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n try {\n // Add file metadata\n const metadata = {\n \"content-type\": contentType,\n \"upload-time\": new Date().toISOString(),\n };\n\n // Use the createSimpleUploadOperation\n const simpleUploadFn = createSimpleUploadOperation(client);\n const result = await simpleUploadFn(buffer, bucket, objectName, metadata);\n\n // Generate a presigned URL for immediate access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n objectName,\n 3600, // 1 hour expiry\n );\n const url = await executeMinioOperation(client, presignedUrlOperation);\n\n const fileName = objectName.split(\"/\").pop() || objectName;\n\n const fileMetadata: FileMetadata = {\n id: objectName,\n name: fileName,\n contentType,\n size: buffer.length,\n uploadedAt: new Date().toISOString(),\n etag: result.etag,\n url,\n };\n\n return validate(FileMetadataSchema, fileMetadata);\n } catch (error) {\n console.error(\"Failed to upload file:\", error);\n throw new Error(`Failed to upload file: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n","import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport type { Client } from \"minio\";\nimport type { MinioOperation } from \"./operations.js\";\n\n/**\n * Executes a MinIO operation using the provided client\n *\n * @param client - MinIO client to use\n * @param operation - The operation to execute\n * @returns The result of the operation execution\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createServerMinioClient, createListObjectsOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n * const listOperation = createListObjectsOperation(\"my-bucket\", \"prefix/\");\n * const result = await executeMinioOperation(client, listOperation);\n */\nexport async function executeMinioOperation<T>(client: Client, operation: MinioOperation<T>): Promise<T> {\n ensureServer();\n\n return operation.execute(client);\n}\n","import type { Buffer } from \"node:buffer\";\nimport type { Client, ItemBucketMetadata } from \"minio\";\n\n/**\n * Base interface for all MinIO operations\n *\n * @template T The return type of the operation\n */\nexport interface MinioOperation<T> {\n execute: (client: Client) => Promise<T>;\n}\n\n/**\n * Creates an operation to list objects in a bucket\n *\n * @param bucket - The bucket name to list objects from\n * @param prefix - Optional prefix to filter objects (like a folder path)\n * @returns A MinioOperation that lists objects when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createListObjectsOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const listOperation = createListObjectsOperation(\"my-bucket\", \"folder/\");\n * const objects = await executeMinioOperation(client, listOperation);\n */\nexport function createListObjectsOperation(\n bucket: string,\n prefix = \"\",\n): MinioOperation<\n Array<{\n name: string;\n prefix?: string;\n size: number;\n etag: string;\n lastModified: Date;\n }>\n> {\n return {\n execute: async (client: Client) => {\n const objectsStream = client.listObjects(bucket, prefix, true);\n const objects: Array<{\n name: string;\n prefix?: string;\n size: number;\n etag: string;\n lastModified: Date;\n }> = [];\n\n return new Promise((resolve, reject) => {\n objectsStream.on(\"data\", (obj) => {\n // Ensure required properties are not undefined before adding to the array\n if (obj.name && typeof obj.size === \"number\" && obj.etag && obj.lastModified) {\n objects.push({\n name: obj.name,\n prefix: obj.prefix,\n size: obj.size,\n etag: obj.etag,\n lastModified: obj.lastModified,\n });\n }\n });\n\n objectsStream.on(\"error\", (err) => {\n reject(err);\n });\n\n objectsStream.on(\"end\", () => {\n resolve(objects);\n });\n });\n },\n };\n}\n\n/**\n * Creates an operation to get an object's metadata\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path\n * @returns A MinioOperation that gets object stats when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createStatObjectOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const statOperation = createStatObjectOperation(\"my-bucket\", \"folder/file.txt\");\n * const stats = await executeMinioOperation(client, statOperation);\n */\nexport function createStatObjectOperation(\n bucket: string,\n objectName: string,\n): MinioOperation<{\n size: number;\n etag: string;\n metaData: Record<string, string>;\n lastModified: Date;\n}> {\n return {\n execute: async (client: Client) => {\n return client.statObject(bucket, objectName);\n },\n };\n}\n\n/**\n * Creates an operation to upload a buffer to MinIO\n *\n * @param bucket - The bucket name to upload to\n * @param objectName - The object name/path to create\n * @param buffer - The buffer containing the file data\n * @param metadata - Optional metadata to attach to the object\n * @returns A MinioOperation that uploads the buffer when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createUploadOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const buffer = Buffer.from(\"file content\");\n * const uploadOperation = createUploadOperation(\"my-bucket\", \"folder/file.txt\", buffer, { \"content-type\": \"text/plain\" });\n * const result = await executeMinioOperation(client, uploadOperation);\n */\nexport function createUploadOperation(\n bucket: string,\n objectName: string,\n buffer: Buffer,\n metadata?: ItemBucketMetadata,\n): MinioOperation<{ etag: string }> {\n return {\n execute: async (client: Client) => {\n return client.putObject(bucket, objectName, buffer, undefined, metadata);\n },\n };\n}\n\n/**\n * Creates an operation to delete an object from MinIO\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path to delete\n * @returns A MinioOperation that deletes the object when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createDeleteOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const deleteOperation = createDeleteOperation(\"my-bucket\", \"folder/file.txt\");\n * await executeMinioOperation(client, deleteOperation);\n */\nexport function createDeleteOperation(bucket: string, objectName: string): MinioOperation<void> {\n return {\n execute: async (client: Client) => {\n return client.removeObject(bucket, objectName);\n },\n };\n}\n\n/**\n * Creates an operation to generate a presigned URL for an object\n *\n * @param bucket - The bucket name containing the object\n * @param objectName - The object name/path\n * @param expirySeconds - How long the URL should be valid for in seconds\n * @returns A MinioOperation that creates a presigned URL when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createPresignedUrlOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const urlOperation = createPresignedUrlOperation(\"my-bucket\", \"folder/file.txt\", 3600);\n * const url = await executeMinioOperation(client, urlOperation);\n */\nexport function createPresignedUrlOperation(\n bucket: string,\n objectName: string,\n expirySeconds: number,\n): MinioOperation<string> {\n return {\n execute: async (client: Client) => {\n return client.presignedGetObject(bucket, objectName, expirySeconds);\n },\n };\n}\n\n/**\n * Creates an operation to generate a presigned PUT URL for direct uploads\n *\n * @param bucket - The bucket name to upload to\n * @param objectName - The object name/path to create\n * @param expirySeconds - How long the URL should be valid for in seconds\n * @returns A MinioOperation that creates a presigned PUT URL when executed\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createPresignedPutOperation, executeMinioOperation } from \"@settlemint/sdk-minio\";\n *\n * const putUrlOperation = createPresignedPutOperation(\"my-bucket\", \"folder/file.txt\", 3600);\n * const url = await executeMinioOperation(client, putUrlOperation);\n */\nexport function createPresignedPutOperation(\n bucket: string,\n objectName: string,\n expirySeconds: number,\n): MinioOperation<string> {\n return {\n execute: async (client: Client) => {\n // The MinIO client only accepts the first three parameters for presignedPutObject\n // Metadata needs to be applied when actually uploading via the presigned URL\n return client.presignedPutObject(bucket, objectName, expirySeconds);\n },\n };\n}\n\n/**\n * Creates a simplified upload function bound to a specific client\n *\n * @param client - The MinIO client to use for uploads\n * @returns A function that uploads buffers to MinIO\n * @throws Will throw an error if the operation fails\n *\n * @example\n * import { createSimpleUploadOperation, getMinioClient } from \"@settlemint/sdk-minio\";\n *\n * const client = await getMinioClient();\n * const uploadFn = createSimpleUploadOperation(client);\n * const result = await uploadFn(buffer, \"my-bucket\", \"folder/file.txt\", { \"content-type\": \"text/plain\" });\n */\nexport function createSimpleUploadOperation(client: Client) {\n return async (\n buffer: Buffer,\n bucket: string,\n objectName: string,\n metadata?: ItemBucketMetadata,\n ): Promise<{ etag: string }> => {\n return client.putObject(bucket, objectName, buffer, undefined, metadata);\n };\n}\n"],"mappings":";AAAA,SAAS,gBAAAA,qBAAoB;AAC7B,SAAS,YAAAC,iBAAgB;AACzB,SAAS,cAAc;;;ACFvB,SAAS,iBAAiB;AAC1B,SAAS,SAAS;AAKX,IAAM,4BAA4B,EAAE,OAAO;AAAA;AAAA,EAEhD,UAAU;AAAA;AAAA,EAEV,WAAW,EAAE,OAAO;AAAA;AAAA,EAEpB,WAAW,EAAE,OAAO;AACtB,CAAC;;;ACbD,SAAS,KAAAC,UAAS;AAeX,IAAM,qBAAqB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ACpC,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;","names":["ensureServer","validate","z","ensureServer","ensureServer","ensureServer","validate"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@settlemint/sdk-minio",
3
3
  "description": "MinIO integration module for SettleMint SDK, providing S3-compatible object storage capabilities",
4
- "version": "2.1.5-pr594fad44",
4
+ "version": "2.1.5-pr7397fec3",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "license": "FSL-1.1-MIT",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "devDependencies": {},
53
53
  "dependencies": {
54
- "@settlemint/sdk-utils": "2.1.5-pr594fad44",
54
+ "@settlemint/sdk-utils": "2.1.5-pr7397fec3",
55
55
  "minio": "^8",
56
56
  "zod": "^3"
57
57
  },