@settlemint/sdk-minio 2.1.5-pr3ad019ac → 2.1.5-pr9382b4f5

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/dist/minio.cjs CHANGED
@@ -21,18 +21,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var minio_exports = {};
22
22
  __export(minio_exports, {
23
23
  DEFAULT_BUCKET: () => DEFAULT_BUCKET,
24
- createDeleteOperation: () => createDeleteOperation,
25
- createListObjectsOperation: () => createListObjectsOperation,
26
- createPresignedPutOperation: () => createPresignedPutOperation,
27
24
  createPresignedUploadUrl: () => createPresignedUploadUrl,
28
- createPresignedUrlOperation: () => createPresignedUrlOperation,
29
25
  createServerMinioClient: () => createServerMinioClient,
30
- createSimpleUploadOperation: () => createSimpleUploadOperation,
31
- createStatObjectOperation: () => createStatObjectOperation,
32
- createUploadOperation: () => createUploadOperation,
33
26
  deleteFile: () => deleteFile,
34
- executeMinioOperation: () => executeMinioOperation,
35
- getFileByObjectName: () => getFileByObjectName,
27
+ getFileById: () => getFileById,
36
28
  getFilesList: () => getFilesList,
37
29
  uploadFile: () => uploadFile
38
30
  });
@@ -53,6 +45,17 @@ var ServerClientOptionsSchema = import_zod.z.object({
53
45
  secretKey: import_zod.z.string()
54
46
  });
55
47
 
48
+ // src/helpers/functions.ts
49
+ var import_runtime2 = require("@settlemint/sdk-utils/runtime");
50
+ var import_validation2 = require("@settlemint/sdk-utils/validation");
51
+
52
+ // src/helpers/executor.ts
53
+ var import_runtime = require("@settlemint/sdk-utils/runtime");
54
+ async function executeMinioOperation(client, operation) {
55
+ (0, import_runtime.ensureServer)();
56
+ return operation.execute(client);
57
+ }
58
+
56
59
  // src/helpers/operations.ts
57
60
  function createListObjectsOperation(bucket, prefix = "") {
58
61
  return {
@@ -88,13 +91,6 @@ function createStatObjectOperation(bucket, objectName) {
88
91
  }
89
92
  };
90
93
  }
91
- function createUploadOperation(bucket, objectName, buffer, metadata) {
92
- return {
93
- execute: async (client) => {
94
- return client.putObject(bucket, objectName, buffer, void 0, metadata);
95
- }
96
- };
97
- }
98
94
  function createDeleteOperation(bucket, objectName) {
99
95
  return {
100
96
  execute: async (client) => {
@@ -122,17 +118,6 @@ function createSimpleUploadOperation(client) {
122
118
  };
123
119
  }
124
120
 
125
- // src/helpers/functions.ts
126
- var import_runtime2 = require("@settlemint/sdk-utils/runtime");
127
- var import_validation2 = require("@settlemint/sdk-utils/validation");
128
-
129
- // src/helpers/executor.ts
130
- var import_runtime = require("@settlemint/sdk-utils/runtime");
131
- async function executeMinioOperation(client, operation) {
132
- (0, import_runtime.ensureServer)();
133
- return operation.execute(client);
134
- }
135
-
136
121
  // src/helpers/schema.ts
137
122
  var import_zod2 = require("zod");
138
123
  var FileMetadataSchema = import_zod2.z.object({
@@ -191,15 +176,15 @@ async function getFilesList(client, prefix = "", bucket = DEFAULT_BUCKET) {
191
176
  throw new Error(`Failed to list files: ${error instanceof Error ? error.message : String(error)}`);
192
177
  }
193
178
  }
194
- async function getFileByObjectName(client, objectName, bucket = DEFAULT_BUCKET) {
179
+ async function getFileById(client, fileId, bucket = DEFAULT_BUCKET) {
195
180
  (0, import_runtime2.ensureServer)();
196
- console.log(`Getting file details for: ${objectName} in bucket: ${bucket}`);
181
+ console.log(`Getting file details for: ${fileId} in bucket: ${bucket}`);
197
182
  try {
198
- const statOperation = createStatObjectOperation(bucket, objectName);
183
+ const statOperation = createStatObjectOperation(bucket, fileId);
199
184
  const statResult = await executeMinioOperation(client, statOperation);
200
185
  const presignedUrlOperation = createPresignedUrlOperation(
201
186
  bucket,
202
- objectName,
187
+ fileId,
203
188
  3600
204
189
  // 1 hour expiry
205
190
  );
@@ -214,8 +199,8 @@ async function getFileByObjectName(client, objectName, bucket = DEFAULT_BUCKET)
214
199
  size = statResult.size;
215
200
  }
216
201
  const fileMetadata = {
217
- id: objectName,
218
- name: objectName.split("/").pop() || objectName,
202
+ id: fileId,
203
+ name: fileId.split("/").pop() || fileId,
219
204
  contentType: statResult.metaData["content-type"] || "application/octet-stream",
220
205
  size,
221
206
  uploadedAt: statResult.lastModified.toISOString(),
@@ -224,8 +209,8 @@ async function getFileByObjectName(client, objectName, bucket = DEFAULT_BUCKET)
224
209
  };
225
210
  return (0, import_validation2.validate)(FileMetadataSchema, fileMetadata);
226
211
  } catch (error) {
227
- console.error(`Failed to get file ${objectName}:`, error);
228
- throw new Error(`Failed to get file ${objectName}: ${error instanceof Error ? error.message : String(error)}`);
212
+ console.error(`Failed to get file ${fileId}:`, error);
213
+ throw new Error(`Failed to get file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);
229
214
  }
230
215
  }
231
216
  async function deleteFile(client, fileId, bucket = DEFAULT_BUCKET) {
@@ -307,18 +292,10 @@ function createServerMinioClient(options) {
307
292
  // Annotate the CommonJS export names for ESM import in node:
308
293
  0 && (module.exports = {
309
294
  DEFAULT_BUCKET,
310
- createDeleteOperation,
311
- createListObjectsOperation,
312
- createPresignedPutOperation,
313
295
  createPresignedUploadUrl,
314
- createPresignedUrlOperation,
315
296
  createServerMinioClient,
316
- createSimpleUploadOperation,
317
- createStatObjectOperation,
318
- createUploadOperation,
319
297
  deleteFile,
320
- executeMinioOperation,
321
- getFileByObjectName,
298
+ getFileById,
322
299
  getFilesList,
323
300
  uploadFile
324
301
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/minio.ts","../src/helpers/client-options.schema.ts","../src/helpers/operations.ts","../src/helpers/functions.ts","../src/helpers/executor.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 operations and executor\nexport {\n createDeleteOperation,\n createListObjectsOperation,\n createPresignedPutOperation,\n createPresignedUrlOperation,\n createSimpleUploadOperation,\n createStatObjectOperation,\n createUploadOperation,\n type MinioOperation,\n} from \"./helpers/operations.js\";\n\n// Export high-level functions\nexport {\n getFilesList,\n getFileByObjectName,\n uploadFile,\n deleteFile,\n createPresignedUploadUrl,\n} from \"./helpers/functions.js\";\nexport { executeMinioOperation } from \"./helpers/executor.js\";\n\n// Export validation utilities and schemas\nexport {\n type FileMetadata,\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 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 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 objectName - The object name/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 getFileByObjectName(\n client: Client,\n objectName: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n console.log(`Getting file details for: ${objectName} in bucket: ${bucket}`);\n\n try {\n // Get the file metadata\n const statOperation = createStatObjectOperation(bucket, objectName);\n const statResult = await executeMinioOperation(client, statOperation);\n\n // Generate a presigned URL for access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n objectName,\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: objectName,\n name: objectName.split(\"/\").pop() || objectName,\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 ${objectName}:`, error);\n throw new Error(`Failed to get file ${objectName}: ${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 to delete\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 { 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;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;;;ACaM,SAAS,2BACd,QACA,SAAS,IAST;AACA,SAAO;AAAA,IACL,SAAS,OAAO,WAAmB;AACjC,YAAM,gBAAgB,OAAO,YAAY,QAAQ,QAAQ,IAAI;AAC7D,YAAM,UAMD,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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/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 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,E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AAA,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"]}
package/dist/minio.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Client, ItemBucketMetadata } from 'minio';
1
+ import { Client } from 'minio';
2
2
  export { Client, ItemBucketMetadata } from 'minio';
3
3
  import { z } from 'zod';
4
4
  import { Buffer } from 'node:buffer';
@@ -27,140 +27,6 @@ declare const ServerClientOptionsSchema: z.ZodObject<{
27
27
  */
28
28
  type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
29
29
 
30
- /**
31
- * Base interface for all MinIO operations
32
- *
33
- * @template T The return type of the operation
34
- */
35
- interface MinioOperation<T> {
36
- execute: (client: Client) => Promise<T>;
37
- }
38
- /**
39
- * Creates an operation to list objects in a bucket
40
- *
41
- * @param bucket - The bucket name to list objects from
42
- * @param prefix - Optional prefix to filter objects (like a folder path)
43
- * @returns A MinioOperation that lists objects when executed
44
- * @throws Will throw an error if the operation fails
45
- *
46
- * @example
47
- * import { createListObjectsOperation, executeMinioOperation } from "@settlemint/sdk-minio";
48
- *
49
- * const listOperation = createListObjectsOperation("my-bucket", "folder/");
50
- * const objects = await executeMinioOperation(client, listOperation);
51
- */
52
- declare function createListObjectsOperation(bucket: string, prefix?: string): MinioOperation<Array<{
53
- name: string;
54
- prefix?: string;
55
- size: number;
56
- etag: string;
57
- lastModified: Date;
58
- }>>;
59
- /**
60
- * Creates an operation to get an object's metadata
61
- *
62
- * @param bucket - The bucket name containing the object
63
- * @param objectName - The object name/path
64
- * @returns A MinioOperation that gets object stats when executed
65
- * @throws Will throw an error if the operation fails
66
- *
67
- * @example
68
- * import { createStatObjectOperation, executeMinioOperation } from "@settlemint/sdk-minio";
69
- *
70
- * const statOperation = createStatObjectOperation("my-bucket", "folder/file.txt");
71
- * const stats = await executeMinioOperation(client, statOperation);
72
- */
73
- declare function createStatObjectOperation(bucket: string, objectName: string): MinioOperation<{
74
- size: number;
75
- etag: string;
76
- metaData: Record<string, string>;
77
- lastModified: Date;
78
- }>;
79
- /**
80
- * Creates an operation to upload a buffer to MinIO
81
- *
82
- * @param bucket - The bucket name to upload to
83
- * @param objectName - The object name/path to create
84
- * @param buffer - The buffer containing the file data
85
- * @param metadata - Optional metadata to attach to the object
86
- * @returns A MinioOperation that uploads the buffer when executed
87
- * @throws Will throw an error if the operation fails
88
- *
89
- * @example
90
- * import { createUploadOperation, executeMinioOperation } from "@settlemint/sdk-minio";
91
- *
92
- * const buffer = Buffer.from("file content");
93
- * const uploadOperation = createUploadOperation("my-bucket", "folder/file.txt", buffer, { "content-type": "text/plain" });
94
- * const result = await executeMinioOperation(client, uploadOperation);
95
- */
96
- declare function createUploadOperation(bucket: string, objectName: string, buffer: Buffer, metadata?: ItemBucketMetadata): MinioOperation<{
97
- etag: string;
98
- }>;
99
- /**
100
- * Creates an operation to delete an object from MinIO
101
- *
102
- * @param bucket - The bucket name containing the object
103
- * @param objectName - The object name/path to delete
104
- * @returns A MinioOperation that deletes the object when executed
105
- * @throws Will throw an error if the operation fails
106
- *
107
- * @example
108
- * import { createDeleteOperation, executeMinioOperation } from "@settlemint/sdk-minio";
109
- *
110
- * const deleteOperation = createDeleteOperation("my-bucket", "folder/file.txt");
111
- * await executeMinioOperation(client, deleteOperation);
112
- */
113
- declare function createDeleteOperation(bucket: string, objectName: string): MinioOperation<void>;
114
- /**
115
- * Creates an operation to generate a presigned URL for an object
116
- *
117
- * @param bucket - The bucket name containing the object
118
- * @param objectName - The object name/path
119
- * @param expirySeconds - How long the URL should be valid for in seconds
120
- * @returns A MinioOperation that creates a presigned URL when executed
121
- * @throws Will throw an error if the operation fails
122
- *
123
- * @example
124
- * import { createPresignedUrlOperation, executeMinioOperation } from "@settlemint/sdk-minio";
125
- *
126
- * const urlOperation = createPresignedUrlOperation("my-bucket", "folder/file.txt", 3600);
127
- * const url = await executeMinioOperation(client, urlOperation);
128
- */
129
- declare function createPresignedUrlOperation(bucket: string, objectName: string, expirySeconds: number): MinioOperation<string>;
130
- /**
131
- * Creates an operation to generate a presigned PUT URL for direct uploads
132
- *
133
- * @param bucket - The bucket name to upload to
134
- * @param objectName - The object name/path to create
135
- * @param expirySeconds - How long the URL should be valid for in seconds
136
- * @returns A MinioOperation that creates a presigned PUT URL when executed
137
- * @throws Will throw an error if the operation fails
138
- *
139
- * @example
140
- * import { createPresignedPutOperation, executeMinioOperation } from "@settlemint/sdk-minio";
141
- *
142
- * const putUrlOperation = createPresignedPutOperation("my-bucket", "folder/file.txt", 3600);
143
- * const url = await executeMinioOperation(client, putUrlOperation);
144
- */
145
- declare function createPresignedPutOperation(bucket: string, objectName: string, expirySeconds: number): MinioOperation<string>;
146
- /**
147
- * Creates a simplified upload function bound to a specific client
148
- *
149
- * @param client - The MinIO client to use for uploads
150
- * @returns A function that uploads buffers to MinIO
151
- * @throws Will throw an error if the operation fails
152
- *
153
- * @example
154
- * import { createSimpleUploadOperation, getMinioClient } from "@settlemint/sdk-minio";
155
- *
156
- * const client = await getMinioClient();
157
- * const uploadFn = createSimpleUploadOperation(client);
158
- * const result = await uploadFn(buffer, "my-bucket", "folder/file.txt", { "content-type": "text/plain" });
159
- */
160
- declare function createSimpleUploadOperation(client: Client): (buffer: Buffer, bucket: string, objectName: string, metadata?: ItemBucketMetadata) => Promise<{
161
- etag: string;
162
- }>;
163
-
164
30
  /**
165
31
  * Helper type to extract the inferred type from a Zod schema.
166
32
  *
@@ -230,7 +96,7 @@ declare function getFilesList(client: Client, prefix?: string, bucket?: string):
230
96
  * Gets a single file by its object name
231
97
  *
232
98
  * @param client - The MinIO client to use
233
- * @param objectName - The object name/path
99
+ * @param fileId - The file identifier/path
234
100
  * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)
235
101
  * @returns File metadata with presigned URL
236
102
  * @throws Will throw an error if the file doesn't exist or client initialization fails
@@ -246,12 +112,12 @@ declare function getFilesList(client: Client, prefix?: string, bucket?: string):
246
112
  *
247
113
  * const file = await getFileByObjectName(client, "documents/report.pdf");
248
114
  */
249
- declare function getFileByObjectName(client: Client, objectName: string, bucket?: string): Promise<FileMetadata>;
115
+ declare function getFileById(client: Client, fileId: string, bucket?: string): Promise<FileMetadata>;
250
116
  /**
251
117
  * Deletes a file from storage
252
118
  *
253
119
  * @param client - The MinIO client to use
254
- * @param fileId - The file identifier/path to delete
120
+ * @param fileId - The file identifier/path
255
121
  * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)
256
122
  * @returns Success status
257
123
  * @throws Will throw an error if deletion fails or client initialization fails
@@ -329,26 +195,6 @@ declare function createPresignedUploadUrl(client: Client, fileName: string, path
329
195
  */
330
196
  declare function uploadFile(client: Client, buffer: Buffer, objectName: string, contentType: string, bucket?: string): Promise<FileMetadata>;
331
197
 
332
- /**
333
- * Executes a MinIO operation using the provided client
334
- *
335
- * @param client - MinIO client to use
336
- * @param operation - The operation to execute
337
- * @returns The result of the operation execution
338
- * @throws Will throw an error if the operation fails
339
- *
340
- * @example
341
- * import { createServerMinioClient, createListObjectsOperation, executeMinioOperation } from "@settlemint/sdk-minio";
342
- * const { client } = createServerMinioClient({
343
- * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
344
- * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
345
- * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
346
- * });
347
- * const listOperation = createListObjectsOperation("my-bucket", "prefix/");
348
- * const result = await executeMinioOperation(client, listOperation);
349
- */
350
- declare function executeMinioOperation<T>(client: Client, operation: MinioOperation<T>): Promise<T>;
351
-
352
198
  /**
353
199
  * Creates a MinIO client for server-side use with authentication.
354
200
  *
@@ -370,4 +216,4 @@ declare function createServerMinioClient(options: ServerClientOptions): {
370
216
  client: Client;
371
217
  };
372
218
 
373
- export { DEFAULT_BUCKET, type FileMetadata, type MinioOperation, createDeleteOperation, createListObjectsOperation, createPresignedPutOperation, createPresignedUploadUrl, createPresignedUrlOperation, createServerMinioClient, createSimpleUploadOperation, createStatObjectOperation, createUploadOperation, deleteFile, executeMinioOperation, getFileByObjectName, getFilesList, uploadFile };
219
+ export { DEFAULT_BUCKET, type FileMetadata, createPresignedUploadUrl, createServerMinioClient, deleteFile, getFileById, getFilesList, uploadFile };
package/dist/minio.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Client, ItemBucketMetadata } from 'minio';
1
+ import { Client } from 'minio';
2
2
  export { Client, ItemBucketMetadata } from 'minio';
3
3
  import { z } from 'zod';
4
4
  import { Buffer } from 'node:buffer';
@@ -27,140 +27,6 @@ declare const ServerClientOptionsSchema: z.ZodObject<{
27
27
  */
28
28
  type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
29
29
 
30
- /**
31
- * Base interface for all MinIO operations
32
- *
33
- * @template T The return type of the operation
34
- */
35
- interface MinioOperation<T> {
36
- execute: (client: Client) => Promise<T>;
37
- }
38
- /**
39
- * Creates an operation to list objects in a bucket
40
- *
41
- * @param bucket - The bucket name to list objects from
42
- * @param prefix - Optional prefix to filter objects (like a folder path)
43
- * @returns A MinioOperation that lists objects when executed
44
- * @throws Will throw an error if the operation fails
45
- *
46
- * @example
47
- * import { createListObjectsOperation, executeMinioOperation } from "@settlemint/sdk-minio";
48
- *
49
- * const listOperation = createListObjectsOperation("my-bucket", "folder/");
50
- * const objects = await executeMinioOperation(client, listOperation);
51
- */
52
- declare function createListObjectsOperation(bucket: string, prefix?: string): MinioOperation<Array<{
53
- name: string;
54
- prefix?: string;
55
- size: number;
56
- etag: string;
57
- lastModified: Date;
58
- }>>;
59
- /**
60
- * Creates an operation to get an object's metadata
61
- *
62
- * @param bucket - The bucket name containing the object
63
- * @param objectName - The object name/path
64
- * @returns A MinioOperation that gets object stats when executed
65
- * @throws Will throw an error if the operation fails
66
- *
67
- * @example
68
- * import { createStatObjectOperation, executeMinioOperation } from "@settlemint/sdk-minio";
69
- *
70
- * const statOperation = createStatObjectOperation("my-bucket", "folder/file.txt");
71
- * const stats = await executeMinioOperation(client, statOperation);
72
- */
73
- declare function createStatObjectOperation(bucket: string, objectName: string): MinioOperation<{
74
- size: number;
75
- etag: string;
76
- metaData: Record<string, string>;
77
- lastModified: Date;
78
- }>;
79
- /**
80
- * Creates an operation to upload a buffer to MinIO
81
- *
82
- * @param bucket - The bucket name to upload to
83
- * @param objectName - The object name/path to create
84
- * @param buffer - The buffer containing the file data
85
- * @param metadata - Optional metadata to attach to the object
86
- * @returns A MinioOperation that uploads the buffer when executed
87
- * @throws Will throw an error if the operation fails
88
- *
89
- * @example
90
- * import { createUploadOperation, executeMinioOperation } from "@settlemint/sdk-minio";
91
- *
92
- * const buffer = Buffer.from("file content");
93
- * const uploadOperation = createUploadOperation("my-bucket", "folder/file.txt", buffer, { "content-type": "text/plain" });
94
- * const result = await executeMinioOperation(client, uploadOperation);
95
- */
96
- declare function createUploadOperation(bucket: string, objectName: string, buffer: Buffer, metadata?: ItemBucketMetadata): MinioOperation<{
97
- etag: string;
98
- }>;
99
- /**
100
- * Creates an operation to delete an object from MinIO
101
- *
102
- * @param bucket - The bucket name containing the object
103
- * @param objectName - The object name/path to delete
104
- * @returns A MinioOperation that deletes the object when executed
105
- * @throws Will throw an error if the operation fails
106
- *
107
- * @example
108
- * import { createDeleteOperation, executeMinioOperation } from "@settlemint/sdk-minio";
109
- *
110
- * const deleteOperation = createDeleteOperation("my-bucket", "folder/file.txt");
111
- * await executeMinioOperation(client, deleteOperation);
112
- */
113
- declare function createDeleteOperation(bucket: string, objectName: string): MinioOperation<void>;
114
- /**
115
- * Creates an operation to generate a presigned URL for an object
116
- *
117
- * @param bucket - The bucket name containing the object
118
- * @param objectName - The object name/path
119
- * @param expirySeconds - How long the URL should be valid for in seconds
120
- * @returns A MinioOperation that creates a presigned URL when executed
121
- * @throws Will throw an error if the operation fails
122
- *
123
- * @example
124
- * import { createPresignedUrlOperation, executeMinioOperation } from "@settlemint/sdk-minio";
125
- *
126
- * const urlOperation = createPresignedUrlOperation("my-bucket", "folder/file.txt", 3600);
127
- * const url = await executeMinioOperation(client, urlOperation);
128
- */
129
- declare function createPresignedUrlOperation(bucket: string, objectName: string, expirySeconds: number): MinioOperation<string>;
130
- /**
131
- * Creates an operation to generate a presigned PUT URL for direct uploads
132
- *
133
- * @param bucket - The bucket name to upload to
134
- * @param objectName - The object name/path to create
135
- * @param expirySeconds - How long the URL should be valid for in seconds
136
- * @returns A MinioOperation that creates a presigned PUT URL when executed
137
- * @throws Will throw an error if the operation fails
138
- *
139
- * @example
140
- * import { createPresignedPutOperation, executeMinioOperation } from "@settlemint/sdk-minio";
141
- *
142
- * const putUrlOperation = createPresignedPutOperation("my-bucket", "folder/file.txt", 3600);
143
- * const url = await executeMinioOperation(client, putUrlOperation);
144
- */
145
- declare function createPresignedPutOperation(bucket: string, objectName: string, expirySeconds: number): MinioOperation<string>;
146
- /**
147
- * Creates a simplified upload function bound to a specific client
148
- *
149
- * @param client - The MinIO client to use for uploads
150
- * @returns A function that uploads buffers to MinIO
151
- * @throws Will throw an error if the operation fails
152
- *
153
- * @example
154
- * import { createSimpleUploadOperation, getMinioClient } from "@settlemint/sdk-minio";
155
- *
156
- * const client = await getMinioClient();
157
- * const uploadFn = createSimpleUploadOperation(client);
158
- * const result = await uploadFn(buffer, "my-bucket", "folder/file.txt", { "content-type": "text/plain" });
159
- */
160
- declare function createSimpleUploadOperation(client: Client): (buffer: Buffer, bucket: string, objectName: string, metadata?: ItemBucketMetadata) => Promise<{
161
- etag: string;
162
- }>;
163
-
164
30
  /**
165
31
  * Helper type to extract the inferred type from a Zod schema.
166
32
  *
@@ -230,7 +96,7 @@ declare function getFilesList(client: Client, prefix?: string, bucket?: string):
230
96
  * Gets a single file by its object name
231
97
  *
232
98
  * @param client - The MinIO client to use
233
- * @param objectName - The object name/path
99
+ * @param fileId - The file identifier/path
234
100
  * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)
235
101
  * @returns File metadata with presigned URL
236
102
  * @throws Will throw an error if the file doesn't exist or client initialization fails
@@ -246,12 +112,12 @@ declare function getFilesList(client: Client, prefix?: string, bucket?: string):
246
112
  *
247
113
  * const file = await getFileByObjectName(client, "documents/report.pdf");
248
114
  */
249
- declare function getFileByObjectName(client: Client, objectName: string, bucket?: string): Promise<FileMetadata>;
115
+ declare function getFileById(client: Client, fileId: string, bucket?: string): Promise<FileMetadata>;
250
116
  /**
251
117
  * Deletes a file from storage
252
118
  *
253
119
  * @param client - The MinIO client to use
254
- * @param fileId - The file identifier/path to delete
120
+ * @param fileId - The file identifier/path
255
121
  * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)
256
122
  * @returns Success status
257
123
  * @throws Will throw an error if deletion fails or client initialization fails
@@ -329,26 +195,6 @@ declare function createPresignedUploadUrl(client: Client, fileName: string, path
329
195
  */
330
196
  declare function uploadFile(client: Client, buffer: Buffer, objectName: string, contentType: string, bucket?: string): Promise<FileMetadata>;
331
197
 
332
- /**
333
- * Executes a MinIO operation using the provided client
334
- *
335
- * @param client - MinIO client to use
336
- * @param operation - The operation to execute
337
- * @returns The result of the operation execution
338
- * @throws Will throw an error if the operation fails
339
- *
340
- * @example
341
- * import { createServerMinioClient, createListObjectsOperation, executeMinioOperation } from "@settlemint/sdk-minio";
342
- * const { client } = createServerMinioClient({
343
- * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
344
- * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
345
- * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
346
- * });
347
- * const listOperation = createListObjectsOperation("my-bucket", "prefix/");
348
- * const result = await executeMinioOperation(client, listOperation);
349
- */
350
- declare function executeMinioOperation<T>(client: Client, operation: MinioOperation<T>): Promise<T>;
351
-
352
198
  /**
353
199
  * Creates a MinIO client for server-side use with authentication.
354
200
  *
@@ -370,4 +216,4 @@ declare function createServerMinioClient(options: ServerClientOptions): {
370
216
  client: Client;
371
217
  };
372
218
 
373
- export { DEFAULT_BUCKET, type FileMetadata, type MinioOperation, createDeleteOperation, createListObjectsOperation, createPresignedPutOperation, createPresignedUploadUrl, createPresignedUrlOperation, createServerMinioClient, createSimpleUploadOperation, createStatObjectOperation, createUploadOperation, deleteFile, executeMinioOperation, getFileByObjectName, getFilesList, uploadFile };
219
+ export { DEFAULT_BUCKET, type FileMetadata, createPresignedUploadUrl, createServerMinioClient, deleteFile, getFileById, getFilesList, uploadFile };
package/dist/minio.mjs CHANGED
@@ -15,6 +15,17 @@ var ServerClientOptionsSchema = z.object({
15
15
  secretKey: z.string()
16
16
  });
17
17
 
18
+ // src/helpers/functions.ts
19
+ import { ensureServer as ensureServer2 } from "@settlemint/sdk-utils/runtime";
20
+ import { validate } from "@settlemint/sdk-utils/validation";
21
+
22
+ // src/helpers/executor.ts
23
+ import { ensureServer } from "@settlemint/sdk-utils/runtime";
24
+ async function executeMinioOperation(client, operation) {
25
+ ensureServer();
26
+ return operation.execute(client);
27
+ }
28
+
18
29
  // src/helpers/operations.ts
19
30
  function createListObjectsOperation(bucket, prefix = "") {
20
31
  return {
@@ -50,13 +61,6 @@ function createStatObjectOperation(bucket, objectName) {
50
61
  }
51
62
  };
52
63
  }
53
- function createUploadOperation(bucket, objectName, buffer, metadata) {
54
- return {
55
- execute: async (client) => {
56
- return client.putObject(bucket, objectName, buffer, void 0, metadata);
57
- }
58
- };
59
- }
60
64
  function createDeleteOperation(bucket, objectName) {
61
65
  return {
62
66
  execute: async (client) => {
@@ -84,17 +88,6 @@ function createSimpleUploadOperation(client) {
84
88
  };
85
89
  }
86
90
 
87
- // src/helpers/functions.ts
88
- import { ensureServer as ensureServer2 } from "@settlemint/sdk-utils/runtime";
89
- import { validate } from "@settlemint/sdk-utils/validation";
90
-
91
- // src/helpers/executor.ts
92
- import { ensureServer } from "@settlemint/sdk-utils/runtime";
93
- async function executeMinioOperation(client, operation) {
94
- ensureServer();
95
- return operation.execute(client);
96
- }
97
-
98
91
  // src/helpers/schema.ts
99
92
  import { z as z2 } from "zod";
100
93
  var FileMetadataSchema = z2.object({
@@ -153,15 +146,15 @@ async function getFilesList(client, prefix = "", bucket = DEFAULT_BUCKET) {
153
146
  throw new Error(`Failed to list files: ${error instanceof Error ? error.message : String(error)}`);
154
147
  }
155
148
  }
156
- async function getFileByObjectName(client, objectName, bucket = DEFAULT_BUCKET) {
149
+ async function getFileById(client, fileId, bucket = DEFAULT_BUCKET) {
157
150
  ensureServer2();
158
- console.log(`Getting file details for: ${objectName} in bucket: ${bucket}`);
151
+ console.log(`Getting file details for: ${fileId} in bucket: ${bucket}`);
159
152
  try {
160
- const statOperation = createStatObjectOperation(bucket, objectName);
153
+ const statOperation = createStatObjectOperation(bucket, fileId);
161
154
  const statResult = await executeMinioOperation(client, statOperation);
162
155
  const presignedUrlOperation = createPresignedUrlOperation(
163
156
  bucket,
164
- objectName,
157
+ fileId,
165
158
  3600
166
159
  // 1 hour expiry
167
160
  );
@@ -176,8 +169,8 @@ async function getFileByObjectName(client, objectName, bucket = DEFAULT_BUCKET)
176
169
  size = statResult.size;
177
170
  }
178
171
  const fileMetadata = {
179
- id: objectName,
180
- name: objectName.split("/").pop() || objectName,
172
+ id: fileId,
173
+ name: fileId.split("/").pop() || fileId,
181
174
  contentType: statResult.metaData["content-type"] || "application/octet-stream",
182
175
  size,
183
176
  uploadedAt: statResult.lastModified.toISOString(),
@@ -186,8 +179,8 @@ async function getFileByObjectName(client, objectName, bucket = DEFAULT_BUCKET)
186
179
  };
187
180
  return validate(FileMetadataSchema, fileMetadata);
188
181
  } catch (error) {
189
- console.error(`Failed to get file ${objectName}:`, error);
190
- throw new Error(`Failed to get file ${objectName}: ${error instanceof Error ? error.message : String(error)}`);
182
+ console.error(`Failed to get file ${fileId}:`, error);
183
+ throw new Error(`Failed to get file ${fileId}: ${error instanceof Error ? error.message : String(error)}`);
191
184
  }
192
185
  }
193
186
  async function deleteFile(client, fileId, bucket = DEFAULT_BUCKET) {
@@ -268,18 +261,10 @@ function createServerMinioClient(options) {
268
261
  }
269
262
  export {
270
263
  DEFAULT_BUCKET,
271
- createDeleteOperation,
272
- createListObjectsOperation,
273
- createPresignedPutOperation,
274
264
  createPresignedUploadUrl,
275
- createPresignedUrlOperation,
276
265
  createServerMinioClient,
277
- createSimpleUploadOperation,
278
- createStatObjectOperation,
279
- createUploadOperation,
280
266
  deleteFile,
281
- executeMinioOperation,
282
- getFileByObjectName,
267
+ getFileById,
283
268
  getFilesList,
284
269
  uploadFile
285
270
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/minio.ts","../src/helpers/client-options.schema.ts","../src/helpers/operations.ts","../src/helpers/functions.ts","../src/helpers/executor.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 operations and executor\nexport {\n createDeleteOperation,\n createListObjectsOperation,\n createPresignedPutOperation,\n createPresignedUrlOperation,\n createSimpleUploadOperation,\n createStatObjectOperation,\n createUploadOperation,\n type MinioOperation,\n} from \"./helpers/operations.js\";\n\n// Export high-level functions\nexport {\n getFilesList,\n getFileByObjectName,\n uploadFile,\n deleteFile,\n createPresignedUploadUrl,\n} from \"./helpers/functions.js\";\nexport { executeMinioOperation } from \"./helpers/executor.js\";\n\n// Export validation utilities and schemas\nexport {\n type FileMetadata,\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 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 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 objectName - The object name/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 getFileByObjectName(\n client: Client,\n objectName: string,\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata> {\n ensureServer();\n console.log(`Getting file details for: ${objectName} in bucket: ${bucket}`);\n\n try {\n // Get the file metadata\n const statOperation = createStatObjectOperation(bucket, objectName);\n const statResult = await executeMinioOperation(client, statOperation);\n\n // Generate a presigned URL for access\n const presignedUrlOperation = createPresignedUrlOperation(\n bucket,\n objectName,\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: objectName,\n name: objectName.split(\"/\").pop() || objectName,\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 ${objectName}:`, error);\n throw new Error(`Failed to get file ${objectName}: ${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 to delete\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 { 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;;;ACaM,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,IAAI,QAAQ,IAAI,cAAc;AAC5E,oBAAQ,KAAK;AAAA,cACX,MAAM,IAAI;AAAA,cACV,QAAQ,IAAI;AAAA,cACZ,MAAM,IAAI;AAAA,cACV,MAAM,IAAI;AAAA,cACV,cAAc,IAAI;AAAA,YACpB,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAED,sBAAc,GAAG,SAAS,CAAC,QAAQ;AACjC,iBAAO,GAAG;AAAA,QACZ,CAAC;AAED,sBAAc,GAAG,OAAO,MAAM;AAC5B,kBAAQ,OAAO;AAAA,QACjB,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAgBO,SAAS,0BACd,QACA,YAMC;AACD,SAAO;AAAA,IACL,SAAS,OAAO,WAAmB;AACjC,aAAO,OAAO,WAAW,QAAQ,UAAU;AAAA,IAC7C;AAAA,EACF;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,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;;;AHzTO,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/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 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,aAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,sBAAc,GAAG,QAAQ,CAAC,QAAQ;AAEhC,cAAI,IAAI,QAAQ,OAAO,IAAI,SAAS,YAAY,IAAI,QAAQ,IAAI,cAAc;AAC5E,oBAAQ,KAAK;AAAA,cACX,MAAM,IAAI;AAAA,cACV,QAAQ,IAAI;AAAA,cACZ,MAAM,IAAI;AAAA,cACV,MAAM,IAAI;AA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A,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"]}
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-pr3ad019ac",
4
+ "version": "2.1.5-pr9382b4f5",
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-pr3ad019ac",
54
+ "@settlemint/sdk-utils": "2.1.5-pr9382b4f5",
55
55
  "minio": "^8",
56
56
  "zod": "^3"
57
57
  },