@headless-lms/adapter-storage-minio 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mdwt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @headless-lms/adapter-storage-minio
2
+
3
+ MinIO (S3-compatible) implementation of the `ObjectStorage` port from
4
+ `@headless-lms/core/types`. Works against MinIO or any S3-compatible store; buckets
5
+ are private, access is via short-lived presigned URLs only.
6
+
7
+ The adapter reads no environment itself — the installation's `config.ts` parses
8
+ env into a `MinioStorageConfig` and injects the constructed adapter:
9
+
10
+ ```ts
11
+ import { MinioStorageAdapter } from "@headless-lms/adapter-storage-minio";
12
+
13
+ const container = await createContainer(config, {
14
+ adapters: { storage: new MinioStorageAdapter(storageConfig) },
15
+ });
16
+ ```
17
+
18
+ ## Environment variables (reference installation)
19
+
20
+ | Variable | Required | Maps to | Notes |
21
+ | ------------------------- | -------- | ----------------------- | ------------------------------ |
22
+ | `STORAGE_ENDPOINT` | yes | `endPoint` | Host only, no scheme. |
23
+ | `STORAGE_PORT` | yes | `port` | |
24
+ | `STORAGE_USE_SSL` | yes | `useSSL` | `"true"` / `"false"`. |
25
+ | `STORAGE_ACCESS_KEY` | yes | `accessKey` | |
26
+ | `STORAGE_SECRET_KEY` | yes | `secretKey` | |
27
+ | `STORAGE_REGION` | yes | `region` | |
28
+ | `STORAGE_BUCKET` | yes | `bucket` | Created private if missing. |
29
+ | `STORAGE_UPLOAD_EXPIRY` | no | `uploadExpirySeconds` | Default 300. |
30
+ | `STORAGE_DOWNLOAD_EXPIRY` | no | `downloadExpirySeconds` | Default 300. |
@@ -0,0 +1,36 @@
1
+ import { Logger, ObjectStorage, PresignDownloadInput, PresignedUpload, StoredObjectInfo } from "@headless-lms/core/types";
2
+ //#region src/index.d.ts
3
+ interface MinioStorageConfig {
4
+ endPoint: string;
5
+ port: number;
6
+ useSSL: boolean;
7
+ accessKey: string;
8
+ secretKey: string;
9
+ region: string;
10
+ bucket: string;
11
+ uploadExpirySeconds: number;
12
+ downloadExpirySeconds: number;
13
+ }
14
+ declare class MinioStorageAdapter implements ObjectStorage {
15
+ private readonly logger?;
16
+ private readonly client;
17
+ private readonly bucket;
18
+ private readonly region;
19
+ private readonly uploadExpiry;
20
+ private readonly downloadExpiry;
21
+ private ensured;
22
+ constructor(config: MinioStorageConfig, logger?: Logger | undefined);
23
+ /** Create the (private) bucket if it does not exist. Call once at startup. */
24
+ ensureBucket(): Promise<void>;
25
+ presignUpload(input: {
26
+ key: string;
27
+ contentType?: string;
28
+ expiresInSeconds?: number;
29
+ }): Promise<PresignedUpload>;
30
+ presignDownload(input: PresignDownloadInput): Promise<string>;
31
+ stat(key: string): Promise<StoredObjectInfo | null>;
32
+ remove(key: string): Promise<void>;
33
+ }
34
+ //#endregion
35
+ export { MinioStorageAdapter, MinioStorageConfig };
36
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,71 @@
1
+ import { Client } from "minio";
2
+ //#region src/index.ts
3
+ var MinioStorageAdapter = class {
4
+ logger;
5
+ client;
6
+ bucket;
7
+ region;
8
+ uploadExpiry;
9
+ downloadExpiry;
10
+ ensured = false;
11
+ constructor(config, logger) {
12
+ this.logger = logger;
13
+ this.client = new Client({
14
+ endPoint: config.endPoint,
15
+ port: config.port,
16
+ useSSL: config.useSSL,
17
+ accessKey: config.accessKey,
18
+ secretKey: config.secretKey,
19
+ region: config.region
20
+ });
21
+ this.bucket = config.bucket;
22
+ this.region = config.region;
23
+ this.uploadExpiry = config.uploadExpirySeconds;
24
+ this.downloadExpiry = config.downloadExpirySeconds;
25
+ }
26
+ /** Create the (private) bucket if it does not exist. Call once at startup. */
27
+ async ensureBucket() {
28
+ if (this.ensured) return;
29
+ if (!await this.client.bucketExists(this.bucket).catch(() => false)) await this.client.makeBucket(this.bucket, this.region);
30
+ this.ensured = true;
31
+ }
32
+ async presignUpload(input) {
33
+ await this.ensureBucket();
34
+ const expiresInSeconds = input.expiresInSeconds ?? this.uploadExpiry;
35
+ return {
36
+ url: await this.client.presignedPutObject(this.bucket, input.key, expiresInSeconds),
37
+ method: "PUT",
38
+ key: input.key,
39
+ expiresInSeconds,
40
+ headers: input.contentType ? { "Content-Type": input.contentType } : {}
41
+ };
42
+ }
43
+ async presignDownload(input) {
44
+ await this.ensureBucket();
45
+ const expiresInSeconds = input.expiresInSeconds ?? this.downloadExpiry;
46
+ const respHeaders = {};
47
+ if (input.downloadFilename) respHeaders["response-content-disposition"] = `attachment; filename="${input.downloadFilename.replace(/"/g, "")}"`;
48
+ return this.client.presignedGetObject(this.bucket, input.key, expiresInSeconds, respHeaders);
49
+ }
50
+ async stat(key) {
51
+ try {
52
+ const s = await this.client.statObject(this.bucket, key);
53
+ const contentType = s.metaData?.["content-type"];
54
+ return {
55
+ key,
56
+ size: s.size,
57
+ ...contentType ? { contentType } : {},
58
+ ...s.lastModified ? { lastModified: s.lastModified.toISOString() } : {}
59
+ };
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+ async remove(key) {
65
+ await this.client.removeObject(this.bucket, key);
66
+ }
67
+ };
68
+ //#endregion
69
+ export { MinioStorageAdapter };
70
+
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// MinIO (S3-compatible) implementation of the ObjectStorage port. Private\n// buckets; access via short-lived presigned URLs only.\nimport { Client } from \"minio\";\nimport type {\n Logger,\n ObjectStorage,\n PresignDownloadInput,\n PresignedUpload,\n StoredObjectInfo,\n} from \"@headless-lms/core/types\";\n\nexport interface MinioStorageConfig {\n endPoint: string;\n port: number;\n useSSL: boolean;\n accessKey: string;\n secretKey: string;\n region: string;\n bucket: string;\n uploadExpirySeconds: number;\n downloadExpirySeconds: number;\n}\n\nexport class MinioStorageAdapter implements ObjectStorage {\n private readonly client: Client;\n private readonly bucket: string;\n private readonly region: string;\n private readonly uploadExpiry: number;\n private readonly downloadExpiry: number;\n private ensured = false;\n\n constructor(\n config: MinioStorageConfig,\n private readonly logger?: Logger,\n ) {\n this.client = new Client({\n endPoint: config.endPoint,\n port: config.port,\n useSSL: config.useSSL,\n accessKey: config.accessKey,\n secretKey: config.secretKey,\n region: config.region,\n });\n this.bucket = config.bucket;\n this.region = config.region;\n this.uploadExpiry = config.uploadExpirySeconds;\n this.downloadExpiry = config.downloadExpirySeconds;\n }\n\n /** Create the (private) bucket if it does not exist. Call once at startup. */\n async ensureBucket(): Promise<void> {\n if (this.ensured) {\n return;\n }\n const exists = await this.client.bucketExists(this.bucket).catch(() => false);\n if (!exists) {\n await this.client.makeBucket(this.bucket, this.region);\n }\n this.ensured = true;\n }\n\n async presignUpload(input: {\n key: string;\n contentType?: string;\n expiresInSeconds?: number;\n }): Promise<PresignedUpload> {\n await this.ensureBucket();\n const expiresInSeconds = input.expiresInSeconds ?? this.uploadExpiry;\n const url = await this.client.presignedPutObject(this.bucket, input.key, expiresInSeconds);\n return {\n url,\n method: \"PUT\",\n key: input.key,\n expiresInSeconds,\n headers: input.contentType ? { \"Content-Type\": input.contentType } : {},\n };\n }\n\n async presignDownload(input: PresignDownloadInput): Promise<string> {\n await this.ensureBucket();\n const expiresInSeconds = input.expiresInSeconds ?? this.downloadExpiry;\n const respHeaders: Record<string, string> = {};\n if (input.downloadFilename) {\n respHeaders[\"response-content-disposition\"] =\n `attachment; filename=\"${input.downloadFilename.replace(/\"/g, \"\")}\"`;\n }\n return this.client.presignedGetObject(this.bucket, input.key, expiresInSeconds, respHeaders);\n }\n\n async stat(key: string): Promise<StoredObjectInfo | null> {\n try {\n const s = await this.client.statObject(this.bucket, key);\n const contentType = s.metaData?.[\"content-type\"];\n return {\n key,\n size: s.size,\n ...(contentType ? { contentType } : {}),\n ...(s.lastModified ? { lastModified: s.lastModified.toISOString() } : {}),\n };\n } catch {\n return null;\n }\n }\n\n async remove(key: string): Promise<void> {\n await this.client.removeObject(this.bucket, key);\n }\n}\n"],"mappings":";;AAuBA,IAAa,sBAAb,MAA0D;CAUrC;CATnB;CACA;CACA;CACA;CACA;CACA,UAAkB;CAElB,YACE,QACA,QACA;EADiB,KAAA,SAAA;EAEjB,KAAK,SAAS,IAAI,OAAO;GACvB,UAAU,OAAO;GACjB,MAAM,OAAO;GACb,QAAQ,OAAO;GACf,WAAW,OAAO;GAClB,WAAW,OAAO;GAClB,QAAQ,OAAO;EACjB,CAAC;EACD,KAAK,SAAS,OAAO;EACrB,KAAK,SAAS,OAAO;EACrB,KAAK,eAAe,OAAO;EAC3B,KAAK,iBAAiB,OAAO;CAC/B;;CAGA,MAAM,eAA8B;EAClC,IAAI,KAAK,SACP;EAGF,IAAI,CAAC,MADgB,KAAK,OAAO,aAAa,KAAK,MAAM,CAAC,CAAC,YAAY,KAAK,GAE1E,MAAM,KAAK,OAAO,WAAW,KAAK,QAAQ,KAAK,MAAM;EAEvD,KAAK,UAAU;CACjB;CAEA,MAAM,cAAc,OAIS;EAC3B,MAAM,KAAK,aAAa;EACxB,MAAM,mBAAmB,MAAM,oBAAoB,KAAK;EAExD,OAAO;GACL,KAAA,MAFgB,KAAK,OAAO,mBAAmB,KAAK,QAAQ,MAAM,KAAK,gBAAgB;GAGvF,QAAQ;GACR,KAAK,MAAM;GACX;GACA,SAAS,MAAM,cAAc,EAAE,gBAAgB,MAAM,YAAY,IAAI,CAAC;EACxE;CACF;CAEA,MAAM,gBAAgB,OAA8C;EAClE,MAAM,KAAK,aAAa;EACxB,MAAM,mBAAmB,MAAM,oBAAoB,KAAK;EACxD,MAAM,cAAsC,CAAC;EAC7C,IAAI,MAAM,kBACR,YAAY,kCACV,yBAAyB,MAAM,iBAAiB,QAAQ,MAAM,EAAE,EAAE;EAEtE,OAAO,KAAK,OAAO,mBAAmB,KAAK,QAAQ,MAAM,KAAK,kBAAkB,WAAW;CAC7F;CAEA,MAAM,KAAK,KAA+C;EACxD,IAAI;GACF,MAAM,IAAI,MAAM,KAAK,OAAO,WAAW,KAAK,QAAQ,GAAG;GACvD,MAAM,cAAc,EAAE,WAAW;GACjC,OAAO;IACL;IACA,MAAM,EAAE;IACR,GAAI,cAAc,EAAE,YAAY,IAAI,CAAC;IACrC,GAAI,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,YAAY,EAAE,IAAI,CAAC;GACzE;EACF,QAAQ;GACN,OAAO;EACT;CACF;CAEA,MAAM,OAAO,KAA4B;EACvC,MAAM,KAAK,OAAO,aAAa,KAAK,QAAQ,GAAG;CACjD;AACF"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@headless-lms/adapter-storage-minio",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "minio": "^8.0.7",
15
+ "@headless-lms/core": "0.1.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^22.10.2",
19
+ "tsdown": "^0.22.9",
20
+ "typescript": "^5.7.2"
21
+ },
22
+ "description": "MinIO/S3 storage adapter for the headless LMS",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/mdwt/headless-lms.git",
27
+ "directory": "adapters/storage-minio"
28
+ },
29
+ "homepage": "https://github.com/mdwt/headless-lms#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/mdwt/headless-lms/issues"
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "tsdown",
41
+ "typecheck": "tsc --noEmit"
42
+ }
43
+ }