RJBULK-APP/lib/pb.ts
SJCoetz 1efa979443 feat: initial setup of rj bulk supplies backoffice app
Adds complete initial codebase for the RJ Bulk Supplies fuel delivery backoffice:
- Authentication pages and protected route layouts
- Customer, supplier, fuel purchase, and delivery note management
- Custom reporting and customer statement sending tools
- Full UI component library and Tailwind styling
- Server actions, API routes, and PocketBase integration
- Development scripts and project configuration updates
- Updated README and package metadata
2026-07-19 20:38:16 +02:00

30 lines
808 B
TypeScript

import PocketBase from "pocketbase";
import { PB_URL } from "./pocketbase";
/**
* PB record helpers — auth-aware clients for server actions and route handlers.
*/
export function pbAdmin(): PocketBase {
return new PocketBase(PB_URL);
}
export async function pbAsUser(token: string): Promise<PocketBase> {
const pb = new PocketBase(PB_URL);
pb.authStore.save(token, null);
return pb;
}
/**
* Generate a PB-compatible id (15 chars, lowercase a-z + 0-9).
* This PB version's autogenerate pattern doesn't fire on create, so we
* generate IDs explicitly in the app layer.
*/
export function pbId(): string {
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
let out = "";
for (let i = 0; i < 15; i++) {
out += chars[Math.floor(Math.random() * chars.length)];
}
return out;
}