Store Wire
The Store wire (@fluxkitdev/store) provides file upload management, generic CRUD operations, and automated database backups.
Installation
npm install @fluxkitdev/core @fluxkitdev/store
Quick Start
import { FluxKit } from "@fluxkitdev/core";
import { store } from "@fluxkitdev/store";
const app = new FluxKit({
wires: [
store({
uploads: {
provider: "s3",
bucket: process.env.S3_BUCKET,
region: process.env.S3_REGION,
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_SECRET_KEY,
maxFileSize: "10mb",
allowedTypes: ["image/*", "application/pdf"],
},
backup: {
enabled: true,
schedule: "0 2 * * *", // Daily at 2 AM
retention: 30, // Keep 30 days
},
}),
],
database: { uri: process.env.MONGODB_URI },
});
await app.start({ port: 3000 });
Features
| Feature | Description |
|---|---|
| File Uploads | Upload files to S3, GCS, or local disk |
| CRUD | Generic create/read/update/delete for any collection |
| Backup | Automated MongoDB backups with scheduling |
Programmatic API
// Upload a file
const file = await app.store.upload({
buffer: fileBuffer,
filename: "photo.jpg",
contentType: "image/jpeg",
});
// CRUD operations
const item = await app.store.create("products", {
name: "Widget",
price: 9.99,
});
const items = await app.store.find("products", {
price: { $lte: 20 },
});
await app.store.update("products", item._id, {
price: 14.99,
});
await app.store.delete("products", item._id);
REST API Endpoints
POST /store/upload-- Upload a fileGET /store/files-- List uploaded filesGET /store/files/:id-- Get file metadataDELETE /store/files/:id-- Delete a filePOST /store/:collection-- Create a documentGET /store/:collection-- List documentsGET /store/:collection/:id-- Get a documentPUT /store/:collection/:id-- Update a documentDELETE /store/:collection/:id-- Delete a documentPOST /store/backup-- Trigger a manual backupGET /store/backups-- List backups
Environment Variables
| Variable | Default | Description |
|---|---|---|
S3_BUCKET | -- | S3 bucket name |
S3_REGION | us-east-1 | S3 region |
S3_ACCESS_KEY | -- | S3 access key |
S3_SECRET_KEY | -- | S3 secret key |
S3_ENDPOINT | -- | Custom S3 endpoint (for MinIO, etc.) |
UPLOAD_MAX_SIZE | 10mb | Maximum file upload size |
BACKUP_SCHEDULE | -- | Cron schedule for backups |
BACKUP_RETENTION | 30 | Backup retention in days |