Skip to main content

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

FeatureDescription
File UploadsUpload files to S3, GCS, or local disk
CRUDGeneric create/read/update/delete for any collection
BackupAutomated 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 file
  • GET /store/files -- List uploaded files
  • GET /store/files/:id -- Get file metadata
  • DELETE /store/files/:id -- Delete a file
  • POST /store/:collection -- Create a document
  • GET /store/:collection -- List documents
  • GET /store/:collection/:id -- Get a document
  • PUT /store/:collection/:id -- Update a document
  • DELETE /store/:collection/:id -- Delete a document
  • POST /store/backup -- Trigger a manual backup
  • GET /store/backups -- List backups

Environment Variables

VariableDefaultDescription
S3_BUCKET--S3 bucket name
S3_REGIONus-east-1S3 region
S3_ACCESS_KEY--S3 access key
S3_SECRET_KEY--S3 secret key
S3_ENDPOINT--Custom S3 endpoint (for MinIO, etc.)
UPLOAD_MAX_SIZE10mbMaximum file upload size
BACKUP_SCHEDULE--Cron schedule for backups
BACKUP_RETENTION30Backup retention in days