@appitude/lcms-storage
v0.1.1
Published
Official TypeScript/JavaScript SDK for LCMS Storage - Asset management and CDN platform
Maintainers
Readme
LCMS Storage - TypeScript/Node.js SDK
Official TypeScript/JavaScript SDK for LCMS Storage - Asset management and CDN platform.
Features
- Upload files to LCMS Storage from file paths or Buffers
- Delete assets from storage
- List directory contents
- Generate asset URLs with automatic CDN delivery
- Full TypeScript support with type definitions
- Zero dependencies (uses native fetch API)
- Works in Node.js 18+ and modern browsers
Requirements
- Node.js 18.0 or higher
- npm or yarn
Installation
npm install @appitudeio/lcms-storageQuick Start
import { Storage } from '@appitudeio/lcms-storage';
// Initialize client
const storage = new Storage('your-domain.com', 'your_api_key');
// Upload a file
const response = await storage.upload('/path/to/local/image.jpg', '/uploads/image.jpg');
console.log('Uploaded to:', response.url.asset);
// List directory contents
const listing = await storage.list('/uploads');
for (const item of listing.items) {
console.log(`${item.key} - ${item.url}`);
}
// Delete file
await storage.delete('/uploads/old-image.jpg');API Reference
Constructor
const storage = new Storage(domain: string, apiKey: string);Initialize the LCMS Storage client with your domain and API key.
upload()
async upload(
filePathOrBuffer: string | Buffer,
remotePath: string,
contentType?: string
): Promise<UploadResponse>Upload a file to LCMS Storage.
Examples:
// Upload from file path (MIME type auto-detected)
const response = await storage.upload('/tmp/photo.jpg', '/gallery/photo.jpg');
// Upload from Buffer (contentType required)
import { readFileSync } from 'fs';
const buffer = readFileSync('/tmp/photo.jpg');
const response = await storage.upload(buffer, '/gallery/photo.jpg', 'image/jpeg');
// Check response
if (response.success) {
console.log('Uploaded:', response.url.asset);
}delete()
async delete(path: string): Promise<void>Delete a file from LCMS Storage.
Example:
await storage.delete('/gallery/old-photo.jpg');list()
async list(path: string = ''): Promise<ListResponse>List contents of a directory.
Example:
const listing = await storage.list('/gallery');
console.log('Directory:', listing.path);
console.log('Total files:', listing.count());
// List files
for (const item of listing.items) {
console.log(`${item.key} - ${item.size} bytes`);
console.log(`URL: ${item.url}`);
}
// List subdirectories
for (const prefix of listing.prefixes) {
console.log(`Subdirectory: ${prefix}`);
}
// Check if empty
if (listing.isEmpty()) {
console.log('Directory is empty');
}Response Objects
UploadResponse
Properties:
boolean success- Whether upload was successfulstring message- Success or error messageobject url- Contains 'asset' and 'upload' URLs
Methods:
toObject(): Record<string, any>toJson(): string
ListResponse
Properties:
boolean success- Whether the operation was successfulstring message- Success or error messagestring path- Directory path that was listedstring assetBaseUrl- Base URL for accessing assetsListItem[] items- Array of file items with 'key', 'size', 'lastModified', 'url'string[] prefixes- Array of subdirectory prefixes
Methods:
count(): number- Number of itemsisEmpty(): boolean- Whether directory is emptytoObject(): Record<string, any>toJson(): string
Error Handling
try {
const response = await storage.upload('/path/to/file.jpg', '/uploads/file.jpg');
if (response.success) {
console.log('Success:', response.url.asset);
} else {
console.log('Upload failed:', response.message);
}
} catch (error) {
console.error('Upload error:', error.message);
}License
MIT License - see LICENSE file for details.
Support
For issues and questions:
- GitHub Issues: lcms-storage-node/issues
- Email: [email protected]
