1.0.0 • Published 5 months ago

@vitkuz/s3-client-wrapper v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

@vitkuz/s3-client-wrapper

A simplified AWS S3 client wrapper with TypeScript support.

Features

  • TypeScript support with type definitions
  • Simplified S3 operations
  • Support for both CommonJS and ESM modules
  • Comprehensive error handling
  • Node.js 14+ support

Installation

npm install @vitkuz/s3-client-wrapper

Usage

import { S3ClientWrapper } from '@vitkuz/s3-client-wrapper';

// Create a client instance
const s3Client = new S3ClientWrapper({
  region: 'us-east-1',
  bucket: 'my-bucket', // Optional default bucket
  credentials: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!
  }
});

// Upload a file
await s3Client.putFile({
  key: 'example.txt',
  body: 'Hello, World!',
  contentType: 'text/plain'
});

// Download a file
const file = await s3Client.getFile({
  key: 'example.txt'
});

// Get file metadata
const metadata = await s3Client.getFileMetadata({
  key: 'example.txt'
});

// Delete a file
await s3Client.deleteFile({
  key: 'example.txt'
});

// Generate a signed URL
const url = await s3Client.getFileSignedUrl({
  key: 'example.txt',
  expiresIn: 3600 // 1 hour
});

API Reference

Constructor

new S3ClientWrapper(config: S3ClientWrapperConfig)

Configuration

The constructor accepts all standard AWS S3 client configuration options plus:

  • bucket: (optional) Default bucket name to use for operations

Methods

putFile

Uploads a file to S3.

putFile({
  bucket?: string;
  key: string;
  body: Buffer | Readable | string;
  contentType?: string;
  metadata?: Record<string, string>;
}): Promise<void>

getFile

Downloads a file from S3.

getFile({
  bucket?: string;
  key: string;
}): Promise<GetObjectCommandOutput>

getFileMetadata

Gets metadata for a file in S3.

getFileMetadata({
  bucket?: string;
  key: string;
}): Promise<FileMetadata>

deleteFile

Deletes a file from S3.

deleteFile({
  bucket?: string;
  key: string;
}): Promise<void>

getFileSignedUrl

Generates a signed URL for a file in S3.

getFileSignedUrl({
  bucket?: string;
  key: string;
  expiresIn?: number;
}): Promise<string>

License

MIT