@occupop/lib-s3-storage
Version:
Tiny S3 storage helper (AWS & LocalStack) with injectable bucket, signed URLs and public URLs.
64 lines (62 loc) • 1.74 kB
TypeScript
type PublicUrlMode = 'raw' | 'signed';
type S3StorageConfig = {
region: string;
credentials: {
accessKeyId: string;
secretAccessKey: string;
};
endpoint?: string;
accelerate?: boolean;
defaultBucket?: string;
defaultExpiresInSeconds?: number;
publicUrlMode?: PublicUrlMode;
publicAcl?: boolean;
cacheControl?: string;
httpConnectionTimeoutMs?: number;
forcePathStyle?: boolean;
};
type SignedUrlResult = {
url: string;
bucket: string;
key: string;
expiresIn: number;
};
type PutObjectResult = {
url: string;
bucket: string;
key: string;
};
type PublicUrlInput = {
path: string;
bucket?: string;
mode?: PublicUrlMode;
expiresInSeconds?: number;
};
type SignedPutInput = {
path: string;
bucket?: string;
contentType?: string;
fileName?: string;
expiresInSeconds?: number;
checksumCRC32Base64?: string;
};
type PutObjectInput = {
path: string;
bucket?: string;
contentType: string;
fileName?: string;
bodyBase64: string;
cacheControl?: string;
};
type S3Storage = {
getSignedPutUrl: (input: SignedPutInput) => Promise<SignedUrlResult>;
putObject: (input: PutObjectInput) => Promise<PutObjectResult>;
getPublicUrl: (input: PublicUrlInput) => Promise<string>;
getSignedGetUrl: (input: {
path: string;
bucket?: string;
expiresInSeconds?: number;
}) => Promise<SignedUrlResult>;
};
declare const createS3Storage: (cfg: S3StorageConfig) => S3Storage;
export { type PublicUrlInput, type PublicUrlMode, type PutObjectInput, type PutObjectResult, type S3Storage, type S3StorageConfig, type SignedPutInput, type SignedUrlResult, createS3Storage };