feat(firebase): add Firebase Cloud Functions backend for usage data storage#3
Conversation
…torage - Strict Valibot schema validation for daily, session, monthly, and blocks reports - HTTPS Cloud Function endpoint that validates and stores data in Firestore - Comprehensive in-source tests for schema validation - Follows monorepo conventions (tsdown, eslint, vitest configs) Agent-Logs-Url: https://github.com/xSolutions365/ccusage/sessions/722b1421-ad82-4226-9ba6-16499e81b4d4 Co-authored-by: danielllewellyn <56390385+danielllewellyn@users.noreply.github.com>
- @hono/node-server: ^1.19.7 → ^1.19.10 (authorization bypass fix) - @modelcontextprotocol/sdk: ^1.24.3 → ^1.26.0 (data leak + ReDoS fixes) - hono: ^4.9.2 → ^4.12.4 (file access, JWT confusion, auth bypass fixes) - valibot: ^1.1.0 → ^1.2.0 (ReDoS in EMOJI_REGEX fix) - wrangler: ^4.32.0 → ^4.59.1 (OS command injection fix) Agent-Logs-Url: https://github.com/xSolutions365/ccusage/sessions/722b1421-ad82-4226-9ba6-16499e81b4d4 Co-authored-by: danielllewellyn <56390385+danielllewellyn@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4b4341951
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| v.string(), | ||
| v.regex(/^\d{4}-\d{2}-\d{2}$/, 'Last activity must be in YYYY-MM-DD format'), | ||
| ), | ||
| versions: v.array(v.pipe(v.string(), v.regex(/^\d+\.\d+\.\d+/, 'Invalid version format'))), |
There was a problem hiding this comment.
Make
versions optional for session report entries
This schema requires report.sessions[*].versions, but the current session JSON producer does not emit that field (apps/ccusage/src/commands/session.ts builds each session with sessionId, token counts, lastActivity, modelsUsed, modelBreakdowns, and projectPath only). As a result, posting a normal session --json payload to this endpoint will be rejected with 400 even though it is valid ccusage output; this blocks the main ingestion path for session reports.
Useful? React with 👍 / 👎.
| blockStart: v.pipe( | ||
| v.string(), | ||
| v.regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/, 'Invalid ISO timestamp'), |
There was a problem hiding this comment.
Match blocks schema to the actual blocks JSON shape
The blocks validator expects fields like blockStart, blockEnd, and flattened token fields, but ccusage currently emits a different structure (startTime, endTime, tokenCounts, costUSD, models, etc. in apps/ccusage/src/commands/blocks.ts). With this mismatch, a standard blocks --json payload will fail validation and never be stored, so the new backend cannot ingest one of the advertised report types.
Useful? React with 👍 / 👎.
Root cause: pnpm-workspace.yaml catalog specifiers were bumped (security patch) without regenerating pnpm-lock.yaml, causing ERR_PNPM_LOCKFILE_CONFIG_MISMATCH on all CI jobs. Changes: - Revert catalog specifiers to match the existing lockfile - Add apps/firebase to pnpm-lock.yaml importers - Remove firebase-admin/firebase-functions deps (use as runtime externals) - Refactor firebase index.ts to framework-agnostic handler (no firebase imports) - Sync ci.yaml with main branch (adds build job) - Add publish-github-packages.yaml from main branch Agent-Logs-Url: https://github.com/xSolutions365/ccusage/sessions/ad7b2410-68c8-42a3-b345-53185df170aa Co-authored-by: danielllewellyn <56390385+danielllewellyn@users.noreply.github.com>
Agent-Logs-Url: https://github.com/xSolutions365/ccusage/sessions/ad7b2410-68c8-42a3-b345-53185df170aa Co-authored-by: danielllewellyn <56390385+danielllewellyn@users.noreply.github.com>
Bumps catalog specifiers and regenerates pnpm-lock.yaml to resolve: - @hono/node-server: ^1.19.7 → ^1.19.10 (resolves 1.19.14) - @modelcontextprotocol/sdk: ^1.24.3 → ^1.26.0 (resolves 1.29.0) - hono: ^4.9.2 → ^4.12.4 (resolves 4.12.16) - valibot: ^1.1.0 → ^1.2.0 (resolves 1.3.1) - wrangler: ^4.32.0 → ^4.59.1 (resolves 4.87.0) Agent-Logs-Url: https://github.com/xSolutions365/ccusage/sessions/ad7b2410-68c8-42a3-b345-53185df170aa Co-authored-by: danielllewellyn <56390385+danielllewellyn@users.noreply.github.com>
ERR_PNPM_LOCKFILE_CONFIG_MISMATCHpnpm install --frozen-lockfilereports "Lockfile is up to date"