From 37ab6554943e4e650eb047d5d7f1cbbfbae36ecd Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Tue, 24 Nov 2026 08:16:01 -0400 Subject: [PATCH] Add usage tracking foundation: usageEvents + a visible pages-counter The first piece of a stated future billing model, scoped to exactly this: a visible "pages this month" counter and the raw data recording behind it - not plan enforcement, payment processing, or the described pause/resume billing-cycle logic itself. New append-only/immutable usageEvents collection (pb_migrations/13); one event recorded per successfully delivered extraction (result.page_reports.length), not a Preview click. "This period" is explicitly the calendar month - a placeholder until a real subscription/plan record exists to anchor a custom cycle against. Co-Authored-By: Claude Sonnet 5 --- frontend/src/components/AppHeader.vue | 33 ++++++--- frontend/src/services/usageService.js | 56 +++++++++++++++ frontend/src/stores/usageStore.js | 70 +++++++++++++++++++ .../pb_migrations/13_add_usage_events.js | 50 +++++++++++++ 4 files changed, 201 insertions(+), 8 deletions(-) create mode 100644 frontend/src/services/usageService.js create mode 100644 frontend/src/stores/usageStore.js create mode 100644 pocketbase/pb_migrations/13_add_usage_events.js diff --git a/frontend/src/components/AppHeader.vue b/frontend/src/components/AppHeader.vue index 09505ce..fec11a2 100644 --- a/frontend/src/components/AppHeader.vue +++ b/frontend/src/components/AppHeader.vue @@ -12,10 +12,12 @@ import { ref, onMounted, onUnmounted } from 'vue' import { useAuthStore } from '../stores/authStore' import { useProjectsStore } from '../stores/projectsStore' +import { useUsageStore } from '../stores/usageStore' import * as authService from '../services/authService' const authStore = useAuthStore() const projectsStore = useProjectsStore() +const usageStore = useUsageStore() const menuOpen = ref(false) const menuRef = ref(null) @@ -30,7 +32,14 @@ function handleOutsideClick(e) { } } -onMounted(() => window.addEventListener('click', handleOutsideClick)) +onMounted(() => { + window.addEventListener('click', handleOutsideClick) + // Billing/usage-tracking foundation - loaded once here (the one place + // in the app this counter is actually shown) rather than in App.vue's + // own onMounted alongside projects/documents, since nothing else in + // the app currently needs this value loaded ahead of time. + usageStore.loadUsage() +}) onUnmounted(() => window.removeEventListener('click', handleOutsideClick)) function handleSignOut() { @@ -59,13 +68,21 @@ function handleSignOut() {
- - - - Layouts - + +
+ + {{ usageStore.pagesThisPeriod }} page{{ usageStore.pagesThisPeriod === 1 ? '' : 's' }} this month +