@fluxmedia/s3 0.1.0-alpha.0 → 0.1.1

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/index.js.map DELETED
@@ -1 +0,0 @@
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,W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Q,OAAO,KAAK;AACxD,UAAQ,EAAE,OAAO,EAAE,SAAS;CAC/B;CAED,AAAQ,mBAA2B;AAC/B,UAAQ,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;CACvE;CAED,AAAQ,eAAeD,MAA6B;AAChD,MAAI,gBAAgB,OAChB,QAAO;AAEX,SAAO,KAAK,QAAQ;CACvB;CAED,AAAQ,cAAcM,KAAqB;EACvC,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"}
@@ -1,30 +0,0 @@
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
- }
@@ -1,30 +0,0 @@
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 DELETED
@@ -1,29 +0,0 @@
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 DELETED
@@ -1,29 +0,0 @@
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
- }