UNPKG

@settlemint/sdk-minio

Version:

MinIO integration module for SettleMint SDK, providing S3-compatible object storage capabilities

1 lines • 32.3 kB
{"version":3,"file":"minio.cjs","names":["z","UrlSchema","z","client: Client","operation: MinioOperation<T>","bucket: string","client: Client","objects: Array<{\n name: string;\n prefix?: string;\n size: number;\n etag: string;\n lastModified: Date;\n }>","objectName: string","buffer: Buffer","metadata?: ItemBucketMetadata","expirySeconds: number","path: string","fileName: string","client: Client","bucket: string","fileId: string","fileMetadata: FileMetadata","buffer: Buffer","objectName: string","contentType: string","options: ServerClientOptions","Client"],"sources":["../src/helpers/client-options.schema.ts","../src/helpers/schema.ts","../src/helpers/executor.ts","../src/helpers/operations.ts","../src/helpers/functions.ts","../src/minio.ts"],"sourcesContent":["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().min(1, \"Access key cannot be empty\"),\n /** The MinIO secret key used to authenticate with the MinIO server */\n secretKey: z.string().min(1, \"Secret key cannot be empty\"),\n});\n\n/**\n * Type definition for server client options derived from the ServerClientOptionsSchema.\n */\nexport type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;\n","import { z } from \"zod\";\n\n/**\n * Helper type to extract the inferred type from a Zod schema.\n *\n * @template T - The Zod schema type\n */\nexport type Static<T extends z.ZodType> = z.infer<T>;\n\n// ----- Schema Definitions -----\n\n/**\n * Schema for file metadata stored in MinIO.\n * Defines the structure and validation rules for file information.\n */\nexport const FileMetadataSchema = z.object({\n id: z.string(),\n name: z.string(),\n contentType: z.string(),\n size: z.number(),\n uploadedAt: z.string().datetime(),\n etag: z.string(),\n url: z.string().url().optional(),\n});\n\n/**\n * Type representing file metadata after validation.\n */\nexport interface FileMetadata {\n /**\n * The unique identifier for the file.\n */\n id: string;\n /**\n * The name of the file.\n */\n name: string;\n /**\n * The content type of the file.\n */\n contentType: string;\n\n /**\n * The size of the file in bytes.\n */\n size: number;\n\n /**\n * The date and time the file was uploaded.\n */\n uploadedAt: string;\n\n /**\n * The ETag of the file.\n */\n etag: string;\n\n /**\n * The URL of the file.\n */\n url?: string;\n}\n\n/**\n * Default bucket name to use for file storage when none is specified.\n */\nexport const DEFAULT_BUCKET = \"uploads\";\n","import { 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 type { Buffer } from \"node:buffer\";\nimport { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport type { Client } from \"minio\";\nimport { executeMinioOperation } from \"./executor.js\";\nimport {\n createDeleteOperation,\n createListObjectsOperation,\n createPresignedPutOperation,\n createPresignedUrlOperation,\n createSimpleUploadOperation,\n createStatObjectOperation,\n} from \"./operations.js\";\nimport { DEFAULT_BUCKET, FileMetadataSchema } from \"./schema.js\";\nimport type { FileMetadata } from \"./schema.js\";\n\n/**\n * Helper function to normalize paths and prevent double slashes\n *\n * @param path - The path to normalize\n * @param fileName - The filename to append\n * @returns The normalized path with filename\n * @throws Will throw an error if the path is too long (max 1000 characters)\n */\nfunction normalizePath(path: string, fileName: string): string {\n if (path.length > 1_000) {\n throw new Error(\"Path is too long\");\n }\n\n // Remove trailing slashes from path\n const cleanPath = path.replace(/\\/+$/, \"\");\n\n // If path is empty, return just the filename\n if (!cleanPath) {\n return fileName;\n }\n\n // Join with a single slash\n return `${cleanPath}/${fileName}`;\n}\n\n/**\n * Gets a list of files with optional prefix filter\n *\n * @param client - The MinIO client to use\n * @param prefix - Optional prefix to filter files (like a folder path)\n * @param bucket - Optional bucket name (defaults to DEFAULT_BUCKET)\n * @returns Array of file metadata objects\n * @throws Will throw an error if the operation fails or client initialization fails\n *\n * @example\n * import { createServerMinioClient, getFilesList } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n *\n * const files = await getFilesList(client, \"documents/\");\n */\nexport async function getFilesList(\n client: Client,\n prefix = \"\",\n bucket: string = DEFAULT_BUCKET,\n): Promise<FileMetadata[]> {\n ensureServer();\n console.log(`Listing files with prefix: \"${prefix}\" in bucket: \"${bucket}\"`);\n\n try {\n const listOperation = createListObjectsOperation(bucket, prefix);\n const objects = await executeMinioOperation(client, listOperation);\n console.log(`Found ${objects.length} files in MinIO`);\n\n const fileObjects = await Promise.allSettled(\n objects.map(async (obj): Promise<FileMetadata> => {\n try {\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 } catch (error) {\n console.warn(`Failed to generate presigned URL for ${obj.name}:`, error);\n // Return metadata without URL for failed presigned URL operations\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 is omitted for failed operations (undefined)\n };\n }\n }),\n ).then((results) =>\n results\n .filter((result): result is PromiseFulfilledResult<FileMetadata> => result.status === \"fulfilled\")\n .map((result) => result.value),\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) && parsedSize >= 0 && Number.isFinite(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 { validate } from \"@settlemint/sdk-utils/validation\";\nimport { Client } from \"minio\";\nimport { type ServerClientOptions, ServerClientOptionsSchema } from \"./helpers/client-options.schema.js\";\n\n/**\n * Creates a MinIO client for server-side use with authentication.\n *\n * @param options - The server client options for configuring the MinIO client\n * @returns An object containing the initialized MinIO client\n * @throws Will throw an error if not called on the server or if the options fail validation\n *\n * @example\n * import { createServerMinioClient } from \"@settlemint/sdk-minio\";\n *\n * const { client } = createServerMinioClient({\n * instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,\n * accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,\n * secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!\n * });\n * client.listBuckets();\n */\nexport function createServerMinioClient(options: ServerClientOptions): { client: Client } {\n ensureServer();\n const validatedOptions = validate(ServerClientOptionsSchema, options);\n\n const url = new URL(validatedOptions.instance);\n return {\n client: new Client({\n endPoint: url.hostname,\n accessKey: validatedOptions.accessKey,\n secretKey: validatedOptions.secretKey,\n useSSL: url.protocol !== \"http:\",\n port: url.port ? Number(url.port) : undefined,\n region: \"eu-central-1\",\n }),\n };\n}\n// Export validation utilities and schemas\nexport {\n type FileMetadata,\n DEFAULT_BUCKET,\n} from \"./helpers/schema.js\";\n\n// Export high-level functions\nexport {\n getFilesList,\n getFileById,\n uploadFile,\n deleteFile,\n createPresignedUploadUrl,\n} from \"./helpers/functions.js\";\n\n// Re-export required types from minio\nexport type { Client, ItemBucketMetadata } from \"minio\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAa,4BAA4BA,MAAE,OAAO;CAEhD,UAAUC;CAEV,WAAWD,MAAE,QAAQ,CAAC,IAAI,GAAG,6BAA6B;CAE1D,WAAWA,MAAE,QAAQ,CAAC,IAAI,GAAG,6BAA6B;AAC3D,EAAC;;;;;;;;ACEF,MAAa,qBAAqBE,MAAE,OAAO;CACzC,IAAIA,MAAE,QAAQ;CACd,MAAMA,MAAE,QAAQ;CAChB,aAAaA,MAAE,QAAQ;CACvB,MAAMA,MAAE,QAAQ;CAChB,YAAYA,MAAE,QAAQ,CAAC,UAAU;CACjC,MAAMA,MAAE,QAAQ;CAChB,KAAKA,MAAE,QAAQ,CAAC,KAAK,CAAC,UAAU;AACjC,EAAC;;;;AA2CF,MAAa,iBAAiB;;;;;;;;;;;;;;;;;;;;;;AC5C9B,eAAsB,sBAAyBC,QAAgBC,WAA0C;mDACzF;AAEd,QAAO,UAAU,QAAQ,OAAO;AACjC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