@headless-lms/adapter-storage-minio 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,14 +17,14 @@ const container = await createContainer(config, {
17
17
 
18
18
  ## Environment variables (reference installation)
19
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. |
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. Stray member uploads older than this are swept. |
30
+ | `STORAGE_DOWNLOAD_EXPIRY` | no | `downloadExpirySeconds` | Download lifetime when the caller names none. Default 300. The API names `DELIVERY_URL_EXPIRY` on every URL it serves. |
package/dist/index.d.ts CHANGED
@@ -16,7 +16,7 @@ declare class MinioStorageAdapter implements ObjectStorage {
16
16
  private readonly client;
17
17
  private readonly bucket;
18
18
  private readonly region;
19
- private readonly uploadExpiry;
19
+ readonly uploadExpirySeconds: number;
20
20
  private readonly downloadExpiry;
21
21
  private ensured;
22
22
  constructor(config: MinioStorageConfig, logger?: Logger | undefined);
@@ -29,6 +29,11 @@ declare class MinioStorageAdapter implements ObjectStorage {
29
29
  }): Promise<PresignedUpload>;
30
30
  presignDownload(input: PresignDownloadInput): Promise<string>;
31
31
  stat(key: string): Promise<StoredObjectInfo | null>;
32
+ list(prefix: string): Promise<StoredObjectInfo[]>;
33
+ copy(input: {
34
+ from: string;
35
+ to: string;
36
+ }): Promise<void>;
32
37
  remove(key: string): Promise<void>;
33
38
  }
34
39
  //#endregion
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { Client } from "minio";
1
+ import { Client, CopyDestinationOptions, CopySourceOptions } from "minio";
2
2
  //#region src/index.ts
3
3
  var MinioStorageAdapter = class {
4
4
  logger;
5
5
  client;
6
6
  bucket;
7
7
  region;
8
- uploadExpiry;
8
+ uploadExpirySeconds;
9
9
  downloadExpiry;
10
10
  ensured = false;
11
11
  constructor(config, logger) {
@@ -20,7 +20,7 @@ var MinioStorageAdapter = class {
20
20
  });
21
21
  this.bucket = config.bucket;
22
22
  this.region = config.region;
23
- this.uploadExpiry = config.uploadExpirySeconds;
23
+ this.uploadExpirySeconds = config.uploadExpirySeconds;
24
24
  this.downloadExpiry = config.downloadExpirySeconds;
25
25
  }
26
26
  /** Create the (private) bucket if it does not exist. Call once at startup. */
@@ -31,7 +31,7 @@ var MinioStorageAdapter = class {
31
31
  }
32
32
  async presignUpload(input) {
33
33
  await this.ensureBucket();
34
- const expiresInSeconds = input.expiresInSeconds ?? this.uploadExpiry;
34
+ const expiresInSeconds = input.expiresInSeconds ?? this.uploadExpirySeconds;
35
35
  return {
36
36
  url: await this.client.presignedPutObject(this.bucket, input.key, expiresInSeconds),
37
37
  method: "PUT",
@@ -61,6 +61,29 @@ var MinioStorageAdapter = class {
61
61
  return null;
62
62
  }
63
63
  }
64
+ async list(prefix) {
65
+ await this.ensureBucket();
66
+ const objects = [];
67
+ for await (const item of this.client.listObjectsV2(this.bucket, prefix, true)) {
68
+ if (!item.name) continue;
69
+ objects.push({
70
+ key: item.name,
71
+ size: item.size,
72
+ ...item.lastModified ? { lastModified: item.lastModified.toISOString() } : {}
73
+ });
74
+ }
75
+ return objects;
76
+ }
77
+ async copy(input) {
78
+ await this.ensureBucket();
79
+ await this.client.copyObject(new CopySourceOptions({
80
+ Bucket: this.bucket,
81
+ Object: input.from
82
+ }), new CopyDestinationOptions({
83
+ Bucket: this.bucket,
84
+ Object: input.to
85
+ }));
86
+ }
64
87
  async remove(key) {
65
88
  await this.client.removeObject(this.bucket, key);
66
89
  }
package/dist/index.js.map CHANGED
@@ -1 +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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ACN,OAAO;EACT;CACF;CAEA,MAAM,OAAO,KAA4B;EACvC,MAAM,KAAK,OAAO,aAAa,KAAK,QAAQ,GAAG;CACjD;AACF"}
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, CopyDestinationOptions, CopySourceOptions } 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 readonly uploadExpirySeconds: 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.uploadExpirySeconds = 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.uploadExpirySeconds;\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 list(prefix: string): Promise<StoredObjectInfo[]> {\n await this.ensureBucket();\n const objects: StoredObjectInfo[] = [];\n for await (const item of this.client.listObjectsV2(this.bucket, prefix, true)) {\n if (!item.name) {\n continue;\n }\n objects.push({\n key: item.name,\n size: item.size,\n ...(item.lastModified ? { lastModified: item.lastModified.toISOString() } : {}),\n });\n }\n return objects;\n }\n\n async copy(input: { from: string; to: string }): Promise<void> {\n await this.ensureBucket();\n await this.client.copyObject(\n new CopySourceOptions({ Bucket: this.bucket, Object: input.from }),\n new CopyDestinationOptions({ Bucket: this.bucket, Object: input.to }),\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;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,aAAa;EACxB,MAAM,UAA8B,CAAC;EACrC,WAAW,MAAM,QAAQ,KAAK,OAAO,cAAc,KAAK,QAAQ,QAAQ,IAAI,GAAG;GAC7E,IAAI,CAAC,KAAK,MACR;GAEF,QAAQ,KAAK;IACX,KAAK,KAAK;IACV,MAAM,KAAK;IACX,GAAI,KAAK,eAAe,EAAE,cAAc,KAAK,aAAa,YAAY,EAAE,IAAI,CAAC;GAC/E,CAAC;EACH;EACA,OAAO;CACT;CAEA,MAAM,KAAK,OAAoD;EAC7D,MAAM,KAAK,aAAa;EACxB,MAAM,KAAK,OAAO,WAChB,IAAI,kBAAkB;GAAE,QAAQ,KAAK;GAAQ,QAAQ,MAAM;EAAK,CAAC,GACjE,IAAI,uBAAuB;GAAE,QAAQ,KAAK;GAAQ,QAAQ,MAAM;EAAG,CAAC,CACtE;CACF;CAEA,MAAM,OAAO,KAA4B;EACvC,MAAM,KAAK,OAAO,aAAa,KAAK,QAAQ,GAAG;CACjD;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-lms/adapter-storage-minio",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "minio": "^8.0.7",
15
- "@headless-lms/core": "0.2.0"
15
+ "@headless-lms/core": "0.4.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/node": "^22.10.2",