Files
shiftcraft/server/utils/pb-admin.ts
Clanker 36e0946ee4 feat: complete ShiftCraft — AI-powered shift scheduling SaaS
Complete implementation including:
- Landing page with hero, features, how-it-works, pricing
- Employee management (CRUD with soft delete)
- AI constraint parser (Anthropic Claude API)
- German labor law templates (ArbZG §3, §5, §9)
- HiGHS ILP solver for optimal fair schedules
- Schedule calendar result view (employee × date grid)
- Shift framework configuration (periods + shifts)
- Subscription tiers: Free / Pro / Business
- PocketBase setup script with collection creation + seed data
- .env.example with all required variables documented

Pages: employees, constraints (list/new/templates), schedules (list/new/[id]),
       settings (organization/shifts/billing), dashboard

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-18 07:47:31 +02:00

25 lines
716 B
TypeScript

import PocketBase from 'pocketbase'
let _adminClient: PocketBase | null = null
let _tokenExpiry: number = 0
export async function getPBAdminClient(): Promise<PocketBase> {
const config = useRuntimeConfig()
const pbUrl = config.public.pocketbaseUrl as string
if (!_adminClient) {
_adminClient = new PocketBase(pbUrl)
}
// Re-authenticate if token expired (PB tokens last 7 days but refresh at 1h)
if (!_adminClient.authStore.isValid || Date.now() > _tokenExpiry) {
await _adminClient.collection('_superusers').authWithPassword(
config.pbAdminEmail as string,
config.pbAdminPassword as string
)
_tokenExpiry = Date.now() + 3600 * 1000 // 1 hour
}
return _adminClient
}