@fluxmedia/s3 0.1.0-alpha.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 +21 -0
- package/README.md +76 -0
- package/dist/features.d.cts +6 -0
- package/dist/features.d.ts +6 -0
- package/dist/index.cjs +195 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +171 -0
- package/dist/index.js.map +1 -0
- package/dist/s3-provider.d.cts +30 -0
- package/dist/s3-provider.d.ts +30 -0
- package/dist/types.d.cts +29 -0
- package/dist/types.d.ts +29 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FluxMedia Contributors
|
|
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,76 @@
|
|
|
1
|
+
# @fluxmedia/s3
|
|
2
|
+
|
|
3
|
+
AWS S3 provider for FluxMedia.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @fluxmedia/core @fluxmedia/s3 @aws-sdk/client-s3
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { MediaUploader } from '@fluxmedia/core';
|
|
15
|
+
import { S3Provider } from '@fluxmedia/s3';
|
|
16
|
+
|
|
17
|
+
const uploader = new MediaUploader(
|
|
18
|
+
new S3Provider({
|
|
19
|
+
region: 'us-east-1',
|
|
20
|
+
bucket: 'my-bucket',
|
|
21
|
+
accessKeyId: 'your-access-key',
|
|
22
|
+
secretAccessKey: 'your-secret-key'
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const result = await uploader.upload(file, {
|
|
27
|
+
folder: 'uploads',
|
|
28
|
+
filename: 'my-file.jpg'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log(result.url);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
S3 is a storage-only provider:
|
|
37
|
+
|
|
38
|
+
- File upload/download
|
|
39
|
+
- Multipart upload for large files
|
|
40
|
+
- Signed upload URLs
|
|
41
|
+
- No image transformations (use CloudFront + Lambda@Edge)
|
|
42
|
+
- No video processing
|
|
43
|
+
|
|
44
|
+
## Configuration
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
interface S3Config {
|
|
48
|
+
region: string; // AWS region
|
|
49
|
+
bucket: string; // S3 bucket name
|
|
50
|
+
accessKeyId: string; // AWS Access Key
|
|
51
|
+
secretAccessKey: string; // AWS Secret Key
|
|
52
|
+
endpoint?: string; // Custom endpoint (for S3-compatible)
|
|
53
|
+
forcePathStyle?: boolean; // Force path style URLs
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## S3-Compatible Services
|
|
58
|
+
|
|
59
|
+
Works with S3-compatible services like MinIO, DigitalOcean Spaces:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const uploader = new MediaUploader(
|
|
63
|
+
new S3Provider({
|
|
64
|
+
region: 'nyc3',
|
|
65
|
+
bucket: 'my-space',
|
|
66
|
+
accessKeyId: 'your-key',
|
|
67
|
+
secretAccessKey: 'your-secret',
|
|
68
|
+
endpoint: 'https://nyc3.digitaloceanspaces.com',
|
|
69
|
+
forcePathStyle: false
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
const __fluxmedia_core = __toESM(require("@fluxmedia/core"));
|
|
25
|
+
|
|
26
|
+
//#region src/features.ts
|
|
27
|
+
/**
|
|
28
|
+
* Feature matrix for S3 provider.
|
|
29
|
+
* S3 is storage-only - no transformation support.
|
|
30
|
+
*/
|
|
31
|
+
const S3Features = {
|
|
32
|
+
transformations: {
|
|
33
|
+
resize: false,
|
|
34
|
+
crop: false,
|
|
35
|
+
format: false,
|
|
36
|
+
quality: false,
|
|
37
|
+
blur: false,
|
|
38
|
+
rotate: false,
|
|
39
|
+
effects: false
|
|
40
|
+
},
|
|
41
|
+
capabilities: {
|
|
42
|
+
signedUploads: true,
|
|
43
|
+
directUpload: true,
|
|
44
|
+
multipartUpload: true,
|
|
45
|
+
videoProcessing: false,
|
|
46
|
+
aiTagging: false,
|
|
47
|
+
facialDetection: false
|
|
48
|
+
},
|
|
49
|
+
storage: {
|
|
50
|
+
maxFileSize: 5 * 1024 * 1024 * 1024,
|
|
51
|
+
supportedFormats: ["*"]
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/s3-provider.ts
|
|
57
|
+
/**
|
|
58
|
+
* AWS S3 provider implementation.
|
|
59
|
+
* Storage-focused provider without transformation support.
|
|
60
|
+
*/
|
|
61
|
+
var S3Provider = class {
|
|
62
|
+
name = "s3";
|
|
63
|
+
features = S3Features;
|
|
64
|
+
client = null;
|
|
65
|
+
config;
|
|
66
|
+
constructor(config) {
|
|
67
|
+
this.config = config;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Lazy-loads the AWS S3 SDK to minimize bundle size.
|
|
71
|
+
*/
|
|
72
|
+
async ensureClient() {
|
|
73
|
+
if (!this.client) {
|
|
74
|
+
const { S3Client } = await import("@aws-sdk/client-s3");
|
|
75
|
+
this.client = new S3Client({
|
|
76
|
+
region: this.config.region,
|
|
77
|
+
credentials: {
|
|
78
|
+
accessKeyId: this.config.accessKeyId,
|
|
79
|
+
secretAccessKey: this.config.secretAccessKey
|
|
80
|
+
},
|
|
81
|
+
endpoint: this.config.endpoint,
|
|
82
|
+
forcePathStyle: this.config.forcePathStyle
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return this.client;
|
|
86
|
+
}
|
|
87
|
+
async upload(file, options) {
|
|
88
|
+
const client = await this.ensureClient();
|
|
89
|
+
try {
|
|
90
|
+
const { PutObjectCommand } = await import("@aws-sdk/client-s3");
|
|
91
|
+
const key = this.generateKey(options);
|
|
92
|
+
const body = file instanceof Buffer ? file : await this.fileToBuffer(file);
|
|
93
|
+
if (options?.onProgress) options.onProgress(0);
|
|
94
|
+
const command = new PutObjectCommand({
|
|
95
|
+
Bucket: this.config.bucket,
|
|
96
|
+
Key: key,
|
|
97
|
+
Body: body,
|
|
98
|
+
ContentType: this.getContentType(file)
|
|
99
|
+
});
|
|
100
|
+
await client.send(command);
|
|
101
|
+
if (options?.onProgress) options.onProgress(100);
|
|
102
|
+
return this.createResult(key, body.length);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw (0, __fluxmedia_core.createMediaError)(__fluxmedia_core.MediaErrorCode.UPLOAD_FAILED, this.name, error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async delete(id) {
|
|
108
|
+
const client = await this.ensureClient();
|
|
109
|
+
try {
|
|
110
|
+
const { DeleteObjectCommand } = await import("@aws-sdk/client-s3");
|
|
111
|
+
const command = new DeleteObjectCommand({
|
|
112
|
+
Bucket: this.config.bucket,
|
|
113
|
+
Key: id
|
|
114
|
+
});
|
|
115
|
+
await client.send(command);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
throw (0, __fluxmedia_core.createMediaError)(__fluxmedia_core.MediaErrorCode.DELETE_FAILED, this.name, error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async get(id) {
|
|
121
|
+
const client = await this.ensureClient();
|
|
122
|
+
try {
|
|
123
|
+
const { HeadObjectCommand } = await import("@aws-sdk/client-s3");
|
|
124
|
+
const command = new HeadObjectCommand({
|
|
125
|
+
Bucket: this.config.bucket,
|
|
126
|
+
Key: id
|
|
127
|
+
});
|
|
128
|
+
const response = await client.send(command);
|
|
129
|
+
return {
|
|
130
|
+
id,
|
|
131
|
+
url: this.getUrl(id),
|
|
132
|
+
publicUrl: this.getUrl(id),
|
|
133
|
+
size: response.ContentLength ?? 0,
|
|
134
|
+
format: this.extractFormat(id),
|
|
135
|
+
provider: this.name,
|
|
136
|
+
metadata: { contentType: response.ContentType },
|
|
137
|
+
createdAt: response.LastModified ?? /* @__PURE__ */ new Date()
|
|
138
|
+
};
|
|
139
|
+
} catch (error) {
|
|
140
|
+
throw (0, __fluxmedia_core.createMediaError)(__fluxmedia_core.MediaErrorCode.FILE_NOT_FOUND, this.name, error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
getUrl(id, _transform) {
|
|
144
|
+
if (this.config.endpoint) return `${this.config.endpoint}/${this.config.bucket}/${id}`;
|
|
145
|
+
return `https://${this.config.bucket}.s3.${this.config.region}.amazonaws.com/${id}`;
|
|
146
|
+
}
|
|
147
|
+
async uploadMultiple(files, options) {
|
|
148
|
+
const uploadPromises = files.map((file) => this.upload(file, options));
|
|
149
|
+
return Promise.all(uploadPromises);
|
|
150
|
+
}
|
|
151
|
+
async deleteMultiple(ids) {
|
|
152
|
+
const deletePromises = ids.map((id) => this.delete(id));
|
|
153
|
+
await Promise.all(deletePromises);
|
|
154
|
+
}
|
|
155
|
+
get native() {
|
|
156
|
+
return this.client;
|
|
157
|
+
}
|
|
158
|
+
generateKey(options) {
|
|
159
|
+
const filename = options?.filename ?? this.generateRandomId();
|
|
160
|
+
const folder = options?.folder ? `${options.folder}/` : "";
|
|
161
|
+
return `${folder}${filename}`;
|
|
162
|
+
}
|
|
163
|
+
generateRandomId() {
|
|
164
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
|
|
165
|
+
}
|
|
166
|
+
getContentType(file) {
|
|
167
|
+
if (file instanceof Buffer) return "application/octet-stream";
|
|
168
|
+
return file.type || "application/octet-stream";
|
|
169
|
+
}
|
|
170
|
+
extractFormat(key) {
|
|
171
|
+
const parts = key.split(".");
|
|
172
|
+
return parts.length > 1 ? parts[parts.length - 1] ?? "" : "";
|
|
173
|
+
}
|
|
174
|
+
async fileToBuffer(file) {
|
|
175
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
176
|
+
return Buffer.from(arrayBuffer);
|
|
177
|
+
}
|
|
178
|
+
createResult(key, size) {
|
|
179
|
+
return {
|
|
180
|
+
id: key,
|
|
181
|
+
url: this.getUrl(key),
|
|
182
|
+
publicUrl: this.getUrl(key),
|
|
183
|
+
size,
|
|
184
|
+
format: this.extractFormat(key),
|
|
185
|
+
provider: this.name,
|
|
186
|
+
metadata: {},
|
|
187
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
exports.S3Features = S3Features;
|
|
194
|
+
exports.S3Provider = S3Provider;
|
|
195
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["S3Features: ProviderFeatures","config: S3Config","file: File | Buffer","options?: UploadOptions","MediaErrorCode","id: string","_transform?: TransformationOptions","files: File[] | Buffer[]","ids: string[]","key: string","file: File","size: number"],"sources":["../src/features.ts","../src/s3-provider.ts"],"sourcesContent":["import type { ProviderFeatures } from '@fluxmedia/core';\n\n/**\n * Feature matrix for S3 provider.\n * S3 is storage-only - no transformation support.\n */\nexport const S3Features: ProviderFeatures = {\n transformations: {\n resize: false,\n crop: false,\n format: false,\n quality: false,\n blur: false,\n rotate: false,\n effects: false,\n },\n capabilities: {\n signedUploads: true,\n directUpload: true,\n multipartUpload: true,\n videoProcessing: false,\n aiTagging: false,\n facialDetection: false,\n },\n storage: {\n maxFileSize: 5 * 1024 * 1024 * 1024, // 5GB\n supportedFormats: ['*'], // All formats\n },\n};\n","import type {\n MediaProvider,\n UploadOptions,\n UploadResult,\n TransformationOptions,\n ProviderFeatures,\n} from '@fluxmedia/core';\nimport { MediaErrorCode, createMediaError } from '@fluxmedia/core';\nimport { S3Features } from './features';\nimport type { S3Config } from './types';\n\n// Type for S3 client\ninterface S3ClientType {\n send: (command: unknown) => Promise<unknown>;\n}\n\n/**\n * AWS S3 provider implementation.\n * Storage-focused provider without transformation support.\n */\nexport class S3Provider implements MediaProvider {\n readonly name: string = 's3';\n readonly features: ProviderFeatures = S3Features;\n\n private client: S3ClientType | null = null;\n private config: S3Config;\n\n constructor(config: S3Config) {\n this.config = config;\n }\n\n /**\n * Lazy-loads the AWS S3 SDK to minimize bundle size.\n */\n private async ensureClient(): Promise<S3ClientType> {\n if (!this.client) {\n const { S3Client } = await import('@aws-sdk/client-s3');\n this.client = new S3Client({\n region: this.config.region,\n credentials: {\n accessKeyId: this.config.accessKeyId,\n secretAccessKey: this.config.secretAccessKey,\n },\n endpoint: this.config.endpoint,\n forcePathStyle: this.config.forcePathStyle,\n });\n }\n return this.client;\n }\n\n async upload(file: File | Buffer, options?: UploadOptions): Promise<UploadResult> {\n const client = await this.ensureClient();\n\n try {\n const { PutObjectCommand } = await import('@aws-sdk/client-s3');\n\n const key = this.generateKey(options);\n const body = file instanceof Buffer ? file : await this.fileToBuffer(file);\n\n if (options?.onProgress) {\n options.onProgress(0);\n }\n\n const command = new PutObjectCommand({\n Bucket: this.config.bucket,\n Key: key,\n Body: body,\n ContentType: this.getContentType(file),\n });\n\n await client.send(command);\n\n if (options?.onProgress) {\n options.onProgress(100);\n }\n\n return this.createResult(key, body.length);\n } catch (error) {\n throw createMediaError(MediaErrorCode.UPLOAD_FAILED, this.name, error);\n }\n }\n\n async delete(id: string): Promise<void> {\n const client = await this.ensureClient();\n\n try {\n const { DeleteObjectCommand } = await import('@aws-sdk/client-s3');\n\n const command = new DeleteObjectCommand({\n Bucket: this.config.bucket,\n Key: id,\n });\n\n await client.send(command);\n } catch (error) {\n throw createMediaError(MediaErrorCode.DELETE_FAILED, this.name, error);\n }\n }\n\n async get(id: string): Promise<UploadResult> {\n const client = await this.ensureClient();\n\n try {\n const { HeadObjectCommand } = await import('@aws-sdk/client-s3');\n\n const command = new HeadObjectCommand({\n Bucket: this.config.bucket,\n Key: id,\n });\n\n const response = (await client.send(command)) as {\n ContentLength?: number;\n ContentType?: string;\n LastModified?: Date;\n };\n\n return {\n id,\n url: this.getUrl(id),\n publicUrl: this.getUrl(id),\n size: response.ContentLength ?? 0,\n format: this.extractFormat(id),\n provider: this.name,\n metadata: {\n contentType: response.ContentType,\n },\n createdAt: response.LastModified ?? new Date(),\n };\n } catch (error) {\n throw createMediaError(MediaErrorCode.FILE_NOT_FOUND, this.name, error);\n }\n }\n\n getUrl(id: string, _transform?: TransformationOptions): string {\n // S3 doesn't support transformations, ignore transform parameter\n if (this.config.endpoint) {\n return `${this.config.endpoint}/${this.config.bucket}/${id}`;\n }\n return `https://${this.config.bucket}.s3.${this.config.region}.amazonaws.com/${id}`;\n }\n\n async uploadMultiple(files: File[] | Buffer[], options?: UploadOptions): Promise<UploadResult[]> {\n const uploadPromises = files.map((file) => this.upload(file, options));\n return Promise.all(uploadPromises);\n }\n\n async deleteMultiple(ids: string[]): Promise<void> {\n const deletePromises = ids.map((id) => this.delete(id));\n await Promise.all(deletePromises);\n }\n\n get native(): unknown {\n return this.client;\n }\n\n private generateKey(options?: UploadOptions): string {\n const filename = options?.filename ?? this.generateRandomId();\n const folder = options?.folder ? `${options.folder}/` : '';\n return `${folder}${filename}`;\n }\n\n private generateRandomId(): string {\n return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;\n }\n\n private getContentType(file: File | Buffer): string {\n if (file instanceof Buffer) {\n return 'application/octet-stream';\n }\n return file.type || 'application/octet-stream';\n }\n\n private extractFormat(key: string): string {\n const parts = key.split('.');\n return parts.length > 1 ? parts[parts.length - 1] ?? '' : '';\n }\n\n private async fileToBuffer(file: File): Promise<Buffer> {\n const arrayBuffer = await file.arrayBuffer();\n return Buffer.from(arrayBuffer);\n }\n\n private createResult(key: string, size: number): UploadResult {\n return {\n id: key,\n url: this.getUrl(key),\n publicUrl: this.getUrl(key),\n size,\n format: this.extractFormat(key),\n provider: this.name,\n metadata: {},\n createdAt: new Date(),\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAaA,aAA+B;CACxC,iBAAiB;EACb,QAAQ;EACR,MAAM;EACN,QAAQ;EACR,SAAS;EACT,MAAM;EACN,QAAQ;EACR,SAAS;CACZ;CACD,cAAc;EACV,eAAe;EACf,cAAc;EACd,iBAAiB;EACjB,iBAAiB;EACjB,WAAW;EACX,iBAAiB;CACpB;CACD,SAAS;EACL,aAAa,IAAI,OAAO,OAAO;EAC/B,kBAAkB,CAAC,GAAI;CAC1B;AACJ;;;;;;;;ACRD,IAAa,aAAb,MAAiD;CAC7C,AAAS,OAAe;CACxB,AAAS,WAA6B;CAEtC,AAAQ,SAA8B;CACtC,AAAQ;CAER,YAAYC,QAAkB;AAC1B,OAAK,SAAS;CACjB;;;;CAKD,MAAc,eAAsC;AAChD,OAAK,KAAK,QAAQ;GACd,MAAM,EAAE,UAAU,GAAG,MAAM,OAAO;AAClC,QAAK,SAAS,IAAI,SAAS;IACvB,QAAQ,KAAK,OAAO;IACpB,aAAa;KACT,aAAa,KAAK,OAAO;KACzB,iBAAiB,KAAK,OAAO;IAChC;IACD,UAAU,KAAK,OAAO;IACtB,gBAAgB,KAAK,OAAO;GAC/B;EACJ;AACD,SAAO,KAAK;CACf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AAI,MAAM,MAAM,SAAS,MAAM,KAAK;CAC7D;CAED,MAAc,aAAaC,MAA6B;EACpD,MAAM,cAAc,MAAM,KAAK,aAAa;AAC5C,SAAO,OAAO,KAAK,YAAY;CAClC;CAED,AAAQ,aAAaD,KAAaE,MAA4B;AAC1D,SAAO;GACH,IAAI;GACJ,KAAK,KAAK,OAAO,IAAI;GACrB,WAAW,KAAK,OAAO,IAAI;GAC3B;GACA,QAAQ,KAAK,cAAc,IAAI;GAC/B,UAAU,KAAK;GACf,UAAU,CAAE;GACZ,2BAAW,IAAI;EAClB;CACJ;AACJ"}
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { MediaErrorCode, createMediaError } from "@fluxmedia/core";
|
|
2
|
+
|
|
3
|
+
//#region src/features.ts
|
|
4
|
+
/**
|
|
5
|
+
* Feature matrix for S3 provider.
|
|
6
|
+
* S3 is storage-only - no transformation support.
|
|
7
|
+
*/
|
|
8
|
+
const S3Features = {
|
|
9
|
+
transformations: {
|
|
10
|
+
resize: false,
|
|
11
|
+
crop: false,
|
|
12
|
+
format: false,
|
|
13
|
+
quality: false,
|
|
14
|
+
blur: false,
|
|
15
|
+
rotate: false,
|
|
16
|
+
effects: false
|
|
17
|
+
},
|
|
18
|
+
capabilities: {
|
|
19
|
+
signedUploads: true,
|
|
20
|
+
directUpload: true,
|
|
21
|
+
multipartUpload: true,
|
|
22
|
+
videoProcessing: false,
|
|
23
|
+
aiTagging: false,
|
|
24
|
+
facialDetection: false
|
|
25
|
+
},
|
|
26
|
+
storage: {
|
|
27
|
+
maxFileSize: 5 * 1024 * 1024 * 1024,
|
|
28
|
+
supportedFormats: ["*"]
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/s3-provider.ts
|
|
34
|
+
/**
|
|
35
|
+
* AWS S3 provider implementation.
|
|
36
|
+
* Storage-focused provider without transformation support.
|
|
37
|
+
*/
|
|
38
|
+
var S3Provider = class {
|
|
39
|
+
name = "s3";
|
|
40
|
+
features = S3Features;
|
|
41
|
+
client = null;
|
|
42
|
+
config;
|
|
43
|
+
constructor(config) {
|
|
44
|
+
this.config = config;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Lazy-loads the AWS S3 SDK to minimize bundle size.
|
|
48
|
+
*/
|
|
49
|
+
async ensureClient() {
|
|
50
|
+
if (!this.client) {
|
|
51
|
+
const { S3Client } = await import("@aws-sdk/client-s3");
|
|
52
|
+
this.client = new S3Client({
|
|
53
|
+
region: this.config.region,
|
|
54
|
+
credentials: {
|
|
55
|
+
accessKeyId: this.config.accessKeyId,
|
|
56
|
+
secretAccessKey: this.config.secretAccessKey
|
|
57
|
+
},
|
|
58
|
+
endpoint: this.config.endpoint,
|
|
59
|
+
forcePathStyle: this.config.forcePathStyle
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return this.client;
|
|
63
|
+
}
|
|
64
|
+
async upload(file, options) {
|
|
65
|
+
const client = await this.ensureClient();
|
|
66
|
+
try {
|
|
67
|
+
const { PutObjectCommand } = await import("@aws-sdk/client-s3");
|
|
68
|
+
const key = this.generateKey(options);
|
|
69
|
+
const body = file instanceof Buffer ? file : await this.fileToBuffer(file);
|
|
70
|
+
if (options?.onProgress) options.onProgress(0);
|
|
71
|
+
const command = new PutObjectCommand({
|
|
72
|
+
Bucket: this.config.bucket,
|
|
73
|
+
Key: key,
|
|
74
|
+
Body: body,
|
|
75
|
+
ContentType: this.getContentType(file)
|
|
76
|
+
});
|
|
77
|
+
await client.send(command);
|
|
78
|
+
if (options?.onProgress) options.onProgress(100);
|
|
79
|
+
return this.createResult(key, body.length);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw createMediaError(MediaErrorCode.UPLOAD_FAILED, this.name, error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async delete(id) {
|
|
85
|
+
const client = await this.ensureClient();
|
|
86
|
+
try {
|
|
87
|
+
const { DeleteObjectCommand } = await import("@aws-sdk/client-s3");
|
|
88
|
+
const command = new DeleteObjectCommand({
|
|
89
|
+
Bucket: this.config.bucket,
|
|
90
|
+
Key: id
|
|
91
|
+
});
|
|
92
|
+
await client.send(command);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
throw createMediaError(MediaErrorCode.DELETE_FAILED, this.name, error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async get(id) {
|
|
98
|
+
const client = await this.ensureClient();
|
|
99
|
+
try {
|
|
100
|
+
const { HeadObjectCommand } = await import("@aws-sdk/client-s3");
|
|
101
|
+
const command = new HeadObjectCommand({
|
|
102
|
+
Bucket: this.config.bucket,
|
|
103
|
+
Key: id
|
|
104
|
+
});
|
|
105
|
+
const response = await client.send(command);
|
|
106
|
+
return {
|
|
107
|
+
id,
|
|
108
|
+
url: this.getUrl(id),
|
|
109
|
+
publicUrl: this.getUrl(id),
|
|
110
|
+
size: response.ContentLength ?? 0,
|
|
111
|
+
format: this.extractFormat(id),
|
|
112
|
+
provider: this.name,
|
|
113
|
+
metadata: { contentType: response.ContentType },
|
|
114
|
+
createdAt: response.LastModified ?? /* @__PURE__ */ new Date()
|
|
115
|
+
};
|
|
116
|
+
} catch (error) {
|
|
117
|
+
throw createMediaError(MediaErrorCode.FILE_NOT_FOUND, this.name, error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
getUrl(id, _transform) {
|
|
121
|
+
if (this.config.endpoint) return `${this.config.endpoint}/${this.config.bucket}/${id}`;
|
|
122
|
+
return `https://${this.config.bucket}.s3.${this.config.region}.amazonaws.com/${id}`;
|
|
123
|
+
}
|
|
124
|
+
async uploadMultiple(files, options) {
|
|
125
|
+
const uploadPromises = files.map((file) => this.upload(file, options));
|
|
126
|
+
return Promise.all(uploadPromises);
|
|
127
|
+
}
|
|
128
|
+
async deleteMultiple(ids) {
|
|
129
|
+
const deletePromises = ids.map((id) => this.delete(id));
|
|
130
|
+
await Promise.all(deletePromises);
|
|
131
|
+
}
|
|
132
|
+
get native() {
|
|
133
|
+
return this.client;
|
|
134
|
+
}
|
|
135
|
+
generateKey(options) {
|
|
136
|
+
const filename = options?.filename ?? this.generateRandomId();
|
|
137
|
+
const folder = options?.folder ? `${options.folder}/` : "";
|
|
138
|
+
return `${folder}${filename}`;
|
|
139
|
+
}
|
|
140
|
+
generateRandomId() {
|
|
141
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
|
|
142
|
+
}
|
|
143
|
+
getContentType(file) {
|
|
144
|
+
if (file instanceof Buffer) return "application/octet-stream";
|
|
145
|
+
return file.type || "application/octet-stream";
|
|
146
|
+
}
|
|
147
|
+
extractFormat(key) {
|
|
148
|
+
const parts = key.split(".");
|
|
149
|
+
return parts.length > 1 ? parts[parts.length - 1] ?? "" : "";
|
|
150
|
+
}
|
|
151
|
+
async fileToBuffer(file) {
|
|
152
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
153
|
+
return Buffer.from(arrayBuffer);
|
|
154
|
+
}
|
|
155
|
+
createResult(key, size) {
|
|
156
|
+
return {
|
|
157
|
+
id: key,
|
|
158
|
+
url: this.getUrl(key),
|
|
159
|
+
publicUrl: this.getUrl(key),
|
|
160
|
+
size,
|
|
161
|
+
format: this.extractFormat(key),
|
|
162
|
+
provider: this.name,
|
|
163
|
+
metadata: {},
|
|
164
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
//#endregion
|
|
170
|
+
export { S3Features, S3Provider };
|
|
171
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["S3Features: ProviderFeatures","config: S3Config","file: File | Buffer","options?: UploadOptions","id: string","_transform?: TransformationOptions","files: File[] | Buffer[]","ids: string[]","key: string","file: File","size: number"],"sources":["../src/features.ts","../src/s3-provider.ts"],"sourcesContent":["import type { ProviderFeatures } from '@fluxmedia/core';\n\n/**\n * Feature matrix for S3 provider.\n * S3 is storage-only - no transformation support.\n */\nexport const S3Features: ProviderFeatures = {\n transformations: {\n resize: false,\n crop: false,\n format: false,\n quality: false,\n blur: false,\n rotate: false,\n effects: false,\n },\n capabilities: {\n signedUploads: true,\n directUpload: true,\n multipartUpload: true,\n videoProcessing: false,\n aiTagging: false,\n facialDetection: false,\n },\n storage: {\n maxFileSize: 5 * 1024 * 1024 * 1024, // 5GB\n supportedFormats: ['*'], // All formats\n },\n};\n","import type {\n MediaProvider,\n UploadOptions,\n UploadResult,\n TransformationOptions,\n ProviderFeatures,\n} from '@fluxmedia/core';\nimport { MediaErrorCode, createMediaError } from '@fluxmedia/core';\nimport { S3Features } from './features';\nimport type { S3Config } from './types';\n\n// Type for S3 client\ninterface S3ClientType {\n send: (command: unknown) => Promise<unknown>;\n}\n\n/**\n * AWS S3 provider implementation.\n * Storage-focused provider without transformation support.\n */\nexport class S3Provider implements MediaProvider {\n readonly name: string = 's3';\n readonly features: ProviderFeatures = S3Features;\n\n private client: S3ClientType | null = null;\n private config: S3Config;\n\n constructor(config: S3Config) {\n this.config = config;\n }\n\n /**\n * Lazy-loads the AWS S3 SDK to minimize bundle size.\n */\n private async ensureClient(): Promise<S3ClientType> {\n if (!this.client) {\n const { S3Client } = await import('@aws-sdk/client-s3');\n this.client = new S3Client({\n region: this.config.region,\n credentials: {\n accessKeyId: this.config.accessKeyId,\n secretAccessKey: this.config.secretAccessKey,\n },\n endpoint: this.config.endpoint,\n forcePathStyle: this.config.forcePathStyle,\n });\n }\n return this.client;\n }\n\n async upload(file: File | Buffer, options?: UploadOptions): Promise<UploadResult> {\n const client = await this.ensureClient();\n\n try {\n const { PutObjectCommand } = await import('@aws-sdk/client-s3');\n\n const key = this.generateKey(options);\n const body = file instanceof Buffer ? file : await this.fileToBuffer(file);\n\n if (options?.onProgress) {\n options.onProgress(0);\n }\n\n const command = new PutObjectCommand({\n Bucket: this.config.bucket,\n Key: key,\n Body: body,\n ContentType: this.getContentType(file),\n });\n\n await client.send(command);\n\n if (options?.onProgress) {\n options.onProgress(100);\n }\n\n return this.createResult(key, body.length);\n } catch (error) {\n throw createMediaError(MediaErrorCode.UPLOAD_FAILED, this.name, error);\n }\n }\n\n async delete(id: string): Promise<void> {\n const client = await this.ensureClient();\n\n try {\n const { DeleteObjectCommand } = await import('@aws-sdk/client-s3');\n\n const command = new DeleteObjectCommand({\n Bucket: this.config.bucket,\n Key: id,\n });\n\n await client.send(command);\n } catch (error) {\n throw createMediaError(MediaErrorCode.DELETE_FAILED, this.name, error);\n }\n }\n\n async get(id: string): Promise<UploadResult> {\n const client = await this.ensureClient();\n\n try {\n const { HeadObjectCommand } = await import('@aws-sdk/client-s3');\n\n const command = new HeadObjectCommand({\n Bucket: this.config.bucket,\n Key: id,\n });\n\n const response = (await client.send(command)) as {\n ContentLength?: number;\n ContentType?: string;\n LastModified?: Date;\n };\n\n return {\n id,\n url: this.getUrl(id),\n publicUrl: this.getUrl(id),\n size: response.ContentLength ?? 0,\n format: this.extractFormat(id),\n provider: this.name,\n metadata: {\n contentType: response.ContentType,\n },\n createdAt: response.LastModified ?? new Date(),\n };\n } catch (error) {\n throw createMediaError(MediaErrorCode.FILE_NOT_FOUND, this.name, error);\n }\n }\n\n getUrl(id: string, _transform?: TransformationOptions): string {\n // S3 doesn't support transformations, ignore transform parameter\n if (this.config.endpoint) {\n return `${this.config.endpoint}/${this.config.bucket}/${id}`;\n }\n return `https://${this.config.bucket}.s3.${this.config.region}.amazonaws.com/${id}`;\n }\n\n async uploadMultiple(files: File[] | Buffer[], options?: UploadOptions): Promise<UploadResult[]> {\n const uploadPromises = files.map((file) => this.upload(file, options));\n return Promise.all(uploadPromises);\n }\n\n async deleteMultiple(ids: string[]): Promise<void> {\n const deletePromises = ids.map((id) => this.delete(id));\n await Promise.all(deletePromises);\n }\n\n get native(): unknown {\n return this.client;\n }\n\n private generateKey(options?: UploadOptions): string {\n const filename = options?.filename ?? this.generateRandomId();\n const folder = options?.folder ? `${options.folder}/` : '';\n return `${folder}${filename}`;\n }\n\n private generateRandomId(): string {\n return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;\n }\n\n private getContentType(file: File | Buffer): string {\n if (file instanceof Buffer) {\n return 'application/octet-stream';\n }\n return file.type || 'application/octet-stream';\n }\n\n private extractFormat(key: string): string {\n const parts = key.split('.');\n return parts.length > 1 ? parts[parts.length - 1] ?? '' : '';\n }\n\n private async fileToBuffer(file: File): Promise<Buffer> {\n const arrayBuffer = await file.arrayBuffer();\n return Buffer.from(arrayBuffer);\n }\n\n private createResult(key: string, size: number): UploadResult {\n return {\n id: key,\n url: this.getUrl(key),\n publicUrl: this.getUrl(key),\n size,\n format: this.extractFormat(key),\n provider: this.name,\n metadata: {},\n createdAt: new Date(),\n };\n }\n}\n"],"mappings":";;;;;;;AAMA,MAAaA,aAA+B;CACxC,iBAAiB;EACb,QAAQ;EACR,MAAM;EACN,QAAQ;EACR,SAAS;EACT,MAAM;EACN,QAAQ;EACR,SAAS;CACZ;CACD,cAAc;EACV,eAAe;EACf,cAAc;EACd,iBAAiB;EACjB,iBAAiB;EACjB,WAAW;EACX,iBAAiB;CACpB;CACD,SAAS;EACL,aAAa,IAAI,OAAO,OAAO;EAC/B,kBAAkB,CAAC,GAAI;CAC1B;AACJ;;;;;;;;ACRD,IAAa,aAAb,MAAiD;CAC7C,AAAS,OAAe;CACxB,AAAS,WAA6B;CAEtC,AAAQ,SAA8B;CACtC,AAAQ;CAER,YAAYC,QAAkB;AAC1B,OAAK,SAAS;CACjB;;;;CAKD,MAAc,eAAsC;AAChD,OAAK,KAAK,QAAQ;GACd,MAAM,EAAE,UAAU,GAAG,MAAM,OAAO;AAClC,QAAK,SAAS,IAAI,SAAS;IACvB,QAAQ,KAAK,OAAO;IACpB,aAAa;KACT,aAAa,KAAK,OAAO;KACzB,iBAAiB,KAAK,OAAO;IAChC;IACD,UAAU,KA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ACvC,MAAM,QAAQ,IAAI,MAAM,IAAI;AAC5B,SAAO,MAAM,SAAS,IAAI,MAAM,MAAM,SAAS,MAAM,KAAK;CAC7D;CAED,MAAc,aAAaC,MAA6B;EACpD,MAAM,cAAc,MAAM,KAAK,aAAa;AAC5C,SAAO,OAAO,KAAK,YAAY;CAClC;CAED,AAAQ,aAAaD,KAAaE,MAA4B;AAC1D,SAAO;GACH,IAAI;GACJ,KAAK,KAAK,OAAO,IAAI;GACrB,WAAW,KAAK,OAAO,IAAI;GAC3B;GACA,QAAQ,KAAK,cAAc,IAAI;GAC/B,UAAU,KAAK;GACf,UAAU,CAAE;GACZ,2BAAW,IAAI;EAClB;CACJ;AACJ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MediaProvider, UploadOptions, UploadResult, TransformationOptions, ProviderFeatures } from '@fluxmedia/core';
|
|
2
|
+
import type { S3Config } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* AWS S3 provider implementation.
|
|
5
|
+
* Storage-focused provider without transformation support.
|
|
6
|
+
*/
|
|
7
|
+
export declare class S3Provider implements MediaProvider {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly features: ProviderFeatures;
|
|
10
|
+
private client;
|
|
11
|
+
private config;
|
|
12
|
+
constructor(config: S3Config);
|
|
13
|
+
/**
|
|
14
|
+
* Lazy-loads the AWS S3 SDK to minimize bundle size.
|
|
15
|
+
*/
|
|
16
|
+
private ensureClient;
|
|
17
|
+
upload(file: File | Buffer, options?: UploadOptions): Promise<UploadResult>;
|
|
18
|
+
delete(id: string): Promise<void>;
|
|
19
|
+
get(id: string): Promise<UploadResult>;
|
|
20
|
+
getUrl(id: string, _transform?: TransformationOptions): string;
|
|
21
|
+
uploadMultiple(files: File[] | Buffer[], options?: UploadOptions): Promise<UploadResult[]>;
|
|
22
|
+
deleteMultiple(ids: string[]): Promise<void>;
|
|
23
|
+
get native(): unknown;
|
|
24
|
+
private generateKey;
|
|
25
|
+
private generateRandomId;
|
|
26
|
+
private getContentType;
|
|
27
|
+
private extractFormat;
|
|
28
|
+
private fileToBuffer;
|
|
29
|
+
private createResult;
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MediaProvider, UploadOptions, UploadResult, TransformationOptions, ProviderFeatures } from '@fluxmedia/core';
|
|
2
|
+
import type { S3Config } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* AWS S3 provider implementation.
|
|
5
|
+
* Storage-focused provider without transformation support.
|
|
6
|
+
*/
|
|
7
|
+
export declare class S3Provider implements MediaProvider {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly features: ProviderFeatures;
|
|
10
|
+
private client;
|
|
11
|
+
private config;
|
|
12
|
+
constructor(config: S3Config);
|
|
13
|
+
/**
|
|
14
|
+
* Lazy-loads the AWS S3 SDK to minimize bundle size.
|
|
15
|
+
*/
|
|
16
|
+
private ensureClient;
|
|
17
|
+
upload(file: File | Buffer, options?: UploadOptions): Promise<UploadResult>;
|
|
18
|
+
delete(id: string): Promise<void>;
|
|
19
|
+
get(id: string): Promise<UploadResult>;
|
|
20
|
+
getUrl(id: string, _transform?: TransformationOptions): string;
|
|
21
|
+
uploadMultiple(files: File[] | Buffer[], options?: UploadOptions): Promise<UploadResult[]>;
|
|
22
|
+
deleteMultiple(ids: string[]): Promise<void>;
|
|
23
|
+
get native(): unknown;
|
|
24
|
+
private generateKey;
|
|
25
|
+
private generateRandomId;
|
|
26
|
+
private getContentType;
|
|
27
|
+
private extractFormat;
|
|
28
|
+
private fileToBuffer;
|
|
29
|
+
private createResult;
|
|
30
|
+
}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for S3 provider
|
|
3
|
+
*/
|
|
4
|
+
export interface S3Config {
|
|
5
|
+
/**
|
|
6
|
+
* AWS region
|
|
7
|
+
*/
|
|
8
|
+
region: string;
|
|
9
|
+
/**
|
|
10
|
+
* S3 bucket name
|
|
11
|
+
*/
|
|
12
|
+
bucket: string;
|
|
13
|
+
/**
|
|
14
|
+
* AWS Access Key ID
|
|
15
|
+
*/
|
|
16
|
+
accessKeyId: string;
|
|
17
|
+
/**
|
|
18
|
+
* AWS Secret Access Key
|
|
19
|
+
*/
|
|
20
|
+
secretAccessKey: string;
|
|
21
|
+
/**
|
|
22
|
+
* Custom endpoint URL (for S3-compatible services)
|
|
23
|
+
*/
|
|
24
|
+
endpoint?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to force path style (required for some S3-compatible services)
|
|
27
|
+
*/
|
|
28
|
+
forcePathStyle?: boolean;
|
|
29
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for S3 provider
|
|
3
|
+
*/
|
|
4
|
+
export interface S3Config {
|
|
5
|
+
/**
|
|
6
|
+
* AWS region
|
|
7
|
+
*/
|
|
8
|
+
region: string;
|
|
9
|
+
/**
|
|
10
|
+
* S3 bucket name
|
|
11
|
+
*/
|
|
12
|
+
bucket: string;
|
|
13
|
+
/**
|
|
14
|
+
* AWS Access Key ID
|
|
15
|
+
*/
|
|
16
|
+
accessKeyId: string;
|
|
17
|
+
/**
|
|
18
|
+
* AWS Secret Access Key
|
|
19
|
+
*/
|
|
20
|
+
secretAccessKey: string;
|
|
21
|
+
/**
|
|
22
|
+
* Custom endpoint URL (for S3-compatible services)
|
|
23
|
+
*/
|
|
24
|
+
endpoint?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Whether to force path style (required for some S3-compatible services)
|
|
27
|
+
*/
|
|
28
|
+
forcePathStyle?: boolean;
|
|
29
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluxmedia/s3",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "AWS S3 provider for FluxMedia",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"fluxmedia",
|
|
7
|
+
"s3",
|
|
8
|
+
"aws",
|
|
9
|
+
"media",
|
|
10
|
+
"upload",
|
|
11
|
+
"cloud"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://fluxmedia.dev",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/fluxmediajs/fluxmedia.git",
|
|
17
|
+
"directory": "packages/s3"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "FluxMedia Contributors",
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.cjs",
|
|
36
|
+
"module": "./dist/index.mjs",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@fluxmedia/core": "0.1.0-alpha.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^20.11.5",
|
|
47
|
+
"tsdown": "^0.2.1",
|
|
48
|
+
"typescript": "^5.3.3"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@aws-sdk/client-s3": "^3.0.0"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=18.0.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsdown",
|
|
61
|
+
"clean": "rm -rf dist",
|
|
62
|
+
"dev": "tsdown --watch"
|
|
63
|
+
}
|
|
64
|
+
}
|