Commit graph

535 commits

Author SHA1 Message Date
Jon Seager
bfe4f7d67d
ci: speed up nix container build with crane dependency caching
Replace rustPlatform.buildRustPackage with crane to split the Rust
compilation into a deps-only derivation (keyed on Cargo.lock) and a
source derivation. The deps derivation is cached in the Nix store
between CI runs, avoiding full recompilation on every deploy.
2026-02-15 12:29:06 +00:00
Jon Seager
1075986554
fix: use form element for registration page
The formatter converted the register container from a div with onclick
to a semantic form with onsubmit, improving accessibility and enabling
native form submission behavior.
2026-02-15 11:39:42 +00:00
Jon Seager
5a0321b226
feat: add WebAuthn Conditional UI for passkey autofill
Enables password managers (1Password, iCloud Keychain) to offer passkey
suggestions via autofill on the login page, matching behavior of other
passkey-enabled websites.
2026-02-15 11:38:53 +00:00
Jon Seager
02235426c4
ci: speed up pipeline with cargo caching and merged jobs
Merge separate lint and test jobs into a single check job so clippy's
compilation artifacts are reused by tests. Add actions/cache for the
Cargo target directory and registry to enable incremental builds across
runs. Drop unnecessary fetch-depth: 0 from CI jobs.
2026-02-15 11:29:45 +00:00
Jon Seager
0e3847ade9
feat: sync timeline events with entity edits
Add background timeline rebuild task (mirroring stats cache pattern)
that refreshes denormalized timeline event snapshots when entities are
updated. Includes cascade logic so editing a roaster refreshes timeline
events for its roasts, bags, brews, and cups.

- Add update_by_entity/delete_by_entity/delete_all to TimelineEventRepository
- Add TimelineInvalidator with debounced background rebuild task
- Add invalidate() calls to all 7 entity update handlers
- Add delete_by_entity cleanup to define_delete_handler! macro
- Add gear_id filter to BrewFilter for cascade traversal
- Add `brewlog timeline rebuild` CLI command for full rebuild
- Add 5 integration tests for timeline sync behavior
2026-02-15 11:11:07 +00:00
Jon Seager
ae016c6437
build: add LD_LIBRARY_PATH to devshell for libssl 2026-02-15 10:36:43 +00:00
Jon Seager
12dcc37cbe
fix: persist session cookie with max-age for Safari PWA support
Session cookie lacked a Max-Age attribute, making it ephemeral. Safari's
standalone PWA mode aggressively clears session cookies on app suspend,
causing frequent logouts. Set Max-Age to 30 days to match the server-side
session lifetime.
2026-02-15 10:36:05 +00:00
Jon Seager
5820c162f6
fix: address static assets code review findings
- Remove dead CSS color property in .tab-mobile
- Fix design token violations (text-red-500, fallback colors)
- Add disconnectedCallback to chip-scroll, image-upload, searchable-select
- Replace innerHTML with safe DOM APIs in world-map screen reader table
- Add credentials: same-origin to WebAuthn fetch calls
- Move page-specific scripts (donut-chart, location) out of base.html
- Add client-side image resizing (1920px max dimension)
- Resize app-icon-512.png from 2048x2048 to 512x512
- Document Datastar unsafe-eval CSP requirement
- Add static asset serving tests (16 routes)
- Add e2e tests for world-map, donut-chart, chip-scroll presence
- Add cache-busting query params to all static asset URLs
2026-02-13 17:13:02 +00:00
Jon Seager
920931ba17
refactor: fix template review findings (security, macros, tokens)
Address findings from the templates code review:

- Fix XSS in admin.html onclick handlers via data attributes
- Fix XSS in 5 edit page signal initializations via JSON serialization
- Fix register.html token exposure by moving to data attribute
- Add entity_icon, quick_notes_toggles, add_form_submit macros
- Replace hardcoded colors with design tokens (warning, error, success)
- Add warning design tokens to CSS theme
- Scope MutationObserver to main element
- Add defer to webauthn.js script tags
- Refactor login/register JS to arrow functions
- Guard lightbox script behind image_url check
- Fix else-if to elif in 5 templates
2026-02-13 16:20:30 +00:00
Jon Seager
ab4bcbaa0a
test: add unit tests for all reviewed presentation modules
Cover parse_created_at in CLI, StatsView::is_empty, format_datetime,
Paginated helpers, encode_uri_component, page_size_from_text,
build_map_data, build_coffee_info, used_percent edge cases,
brew_again_url construction, and parse_and_categorize splitting.
2026-02-13 16:20:29 +00:00
Jon Seager
472e851b80
refactor: standardize view model conversions on From trait
Convert single-argument from_domain() methods to impl From<T> for
consistency with the existing CafeView, RoasterView, and option view
patterns. Affected: BagView, BrewView, CupView, GearView,
GearDetailView, CafeDetailView, RoasterDetailView, TimelineEventView.

RoastView retains from_domain() since it takes extra parameters.
2026-02-13 16:20:27 +00:00
Jon Seager
36e2d90ee8
refactor: document content|safe safety invariant in templates
Add comments explaining why the |safe filter is used in data.html and
stats.html — content is always pre-rendered HTML from render_template().
2026-02-13 16:20:25 +00:00
Jon Seager
31cb7c6c71
refactor: simplify NearbyCafeView iterator chain and remove unused _addr parameter
- Replace .iter().copied().cloned() with .into_iter() on str slices in
  NearbyCafeView::from
- Remove unused _addr: SocketAddr parameter from run_callback_server
  and its call site in tokens.rs
2026-02-13 16:20:23 +00:00
Jon Seager
766ac1432d
refactor: extract duplicated helpers for tasting notes, used_percent, format_datetime, and map builder
- Add parse_and_categorize() in tasting_notes.rs, replacing identical
  split-trim-categorize pipelines in mod.rs, roasts.rs, and timeline.rs
- Add used_percent() in bags.rs, deduplicating the calculation in
  BagView::from_domain and BagDetailView::from_parts
- Add format_datetime() in views/mod.rs, replacing 16 paired occurrences
  of .format("%Y-%m-%d") / .format("%H:%M") across 7 view files
- Add build_origin_roaster_map() in views/mod.rs, replacing identical
  map-entry building blocks in bags.rs, brews.rs, and roasts.rs detail views
2026-02-13 16:20:21 +00:00
Jon Seager
3d49236c13
refactor: move NearbyCafe to domain layer to fix dependency violation
The presentation layer was importing NearbyCafe directly from
infrastructure::foursquare, violating the dependency flow
(presentation -> application -> domain <- infrastructure). Introduce
NearbyCafeResult in domain::nearby_cafes and update all
references.
2026-02-13 16:20:20 +00:00
Jon Seager
f7b210f234
test: add unit tests for all reviewed domain modules
Add 57 unit tests across auth (sessions, registration tokens, API
tokens, username validation), coffee (roasters, cafes, brews, gear),
listing (pagination, sort keys, page calculations), analytics
(country stats), images (debug redaction), and entity type (roundtrip
serialization).
2026-02-13 16:20:18 +00:00
Jon Seager
bd4cb023fb
refactor: replace hand-written SortKey impls with define_sort_key! macro
Add define_sort_key! macro to listing.rs and convert all 8 SortKey
enum + impl blocks to use it, eliminating ~270 lines of repetitive
boilerplate across roasters, roasts, bags, brews, cups, cafes, gear,
and timeline.
2026-02-13 16:20:16 +00:00
Jon Seager
de49f7c3b1
refactor: add EntityType enum and typed IDs in TimelineBrewData
Replace stringly-typed entity references with a compile-time-safe
EntityType enum throughout timeline events, images, and repository
operations. Also replace raw i64 fields in TimelineBrewData with
typed BagId/GearId wrappers.
2026-02-13 16:20:14 +00:00
Jon Seager
c58c60c783
fix: security hardening and code health improvements in domain layer
- Remove danger-allow-state-serialisation feature from webauthn-rs
- Add #[serde(skip_serializing)] to Session and RegistrationToken hash fields
- Add custom Debug impls to redact hashes in Session and NewToken
- Add MAX_SESSION_DURATION (30d) and MAX_TOKEN_DURATION (7d) with clamping
- Add domain-level username validation (length + character constraints)
- Extract shared normalize_optional_field to coffee/mod.rs (DRY)
- Implement FromStr for QuickNote, delegate from_str_value to it
- Refactor UpdateRoaster/UpdateCafe normalize() to use shared helper
2026-02-13 16:20:11 +00:00
Jon Seager
7330e5b59e
refactor: convert to_domain methods to From/TryFrom trait impls
Replace ad-hoc to_domain/into_domain conversion methods on SQL
repository structs with idiomatic From and TryFrom trait implementations
on the record types, following standard Rust conventions.
2026-02-13 13:35:08 +00:00
Jon Seager
590868e51f
test: add integration tests for webauthn, passkeys, and input validation
Add webauthn API tests (register, auth, passkey add flows), passkey
endpoint auth tests, bag validation (zero/negative amount, invalid date),
brew validation (zero weight, negative grind, zero water, temp > 100),
and fix flaky date assertion in bag close test.
2026-02-13 13:06:27 +00:00
Jon Seager
09bd7e61e4
test: add unit tests for support module helpers
Cover kebab_to_camel, render_signals_json, page_size_from_text,
parse_direction, and render_redirect_script with unit tests.
2026-02-13 13:06:19 +00:00
Jon Seager
19e191e922
perf: parallelize independent async calls in detail pages
Use tokio::try_join! to run independent repo queries and image URL
lookups concurrently in bag, brew, and checkin page handlers, and for
gear option loading in the brew form data loader.
2026-02-13 13:06:10 +00:00
Jon Seager
b8a26bbeca
feat: add entity counts to stats cache for home page
Add EntityCounts struct and StatsRepository::entity_counts() to query
per-entity row counts. Include them in CachedStats so the home page can
read counts from cache instead of issuing six list queries with LIMIT 1.
Derive Default on StatsView for the fallback case.
2026-02-13 13:06:04 +00:00
Jon Seager
9d25873243
refactor: reuse ListQuery for timeline page
Replace the hand-rolled TimelineQuery struct with the shared ListQuery
type and its into_request_and_search_with_default method.
2026-02-13 13:05:56 +00:00
Jon Seager
a1aefda860
refactor: use update_response helper in update handlers
Replace duplicated datastar/form/json response branching in brew, cup,
and roast update handlers with the shared update_response helper.
2026-02-13 13:05:50 +00:00
Jon Seager
167af65943
fix: prevent XSS in redirect script via JSON encoding
JSON-encode the URL in render_redirect_script instead of interpolating
it into a single-quoted string, preventing injection via crafted URLs.
2026-02-13 13:05:44 +00:00
Jon Seager
ff2c602139
fix: validate cafe URL scheme on create and update
Make is_valid_url_scheme pub(crate) and use it to filter cafe website
URLs on both create and update, matching roaster validation behavior.
Add UpdateCafe::normalize() method for consistent sanitization.
2026-02-13 13:05:29 +00:00
Jon Seager
b5d5949adf
refactor: simplify admin page auth with direct session lookup
Replace the private extract_user_from_session helper with inline
session/user lookup, reusing the shared SESSION_COOKIE_NAME constant.
Adds tracing instrumentation to the handler.
2026-02-13 13:05:23 +00:00
Jon Seager
0bf30d3475
fix: verify authenticated user in passkey add finish
Add AuthenticatedUser extractor to passkey_add_finish and verify the
session user matches the challenge owner, preventing one user from
completing another user's passkey registration.
2026-02-13 13:05:14 +00:00
Jon Seager
55f2de1e92
refactor: deduplicate SESSION_COOKIE_NAME constant
Make the constant pub(crate) in application::auth and remove the
duplicate definition from routes::app::auth.
2026-02-13 13:04:34 +00:00
Jon Seager
78cc66972d
refactor: extract static_asset! macro for static file handlers
Replace 16 near-identical async functions with a macro that generates
static-asset handlers with embedded content and one-week cache headers.
2026-02-13 13:03:14 +00:00
Ubuntu
7e0b910008
fix: validate CLI callback URLs to localhost-only
Reject non-localhost CLI callback URLs in the WebAuthn auth start
endpoint to prevent token exfiltration to external servers.
2026-02-13 13:01:12 +00:00
Jon Seager
24d9d75145
feat: add home screen icons for iOS and Android 2026-02-13 11:41:16 +00:00
Jon Seager
21696a02f0
chore: update gitignore 2026-02-13 11:27:02 +00:00
Jon Seager
2e41c28429
fix: apply EXIF orientation to uploaded photos
iPhone photos were displayed rotated because EXIF orientation metadata
was not being applied. Fix both the client-side canvas conversion
(use createImageBitmap which respects EXIF) and the server-side image
processing (read and apply EXIF orientation before resizing).
2026-02-12 18:07:52 +00:00
Jon Seager
98053a8679
docs: add note about Claude usage in README 2026-02-12 15:55:57 +00:00
Jon Seager
f1548d7e7a
build: fail-fast pre-commit hooks for faster iteration 2026-02-12 15:30:57 +00:00
Jon Seager
67f218495f
feat: add cancel buttons to all add forms
Match the edit form pattern by adding a Cancel button (history.back())
below each Save button in the sticky submit bar.
2026-02-11 10:24:28 +00:00
Jon Seager
720ebcbad3
feat: add sticky submit buttons to all edit forms on mobile
Add sticky-submit class to the shared edit_form_actions() macro and
pb-16 bottom padding to all seven edit form templates, matching the
add form pattern for a consistent mobile experience.
2026-02-11 10:20:30 +00:00
Jon Seager
1eb5647b76
feat: add sticky submit button to all mobile add forms
Apply the existing sticky-submit pattern (fixed bottom bar on mobile,
inline on desktop) to roaster, roast, bag, gear, cafe, and cup add
forms, matching the brew form behavior.
2026-02-11 10:15:40 +00:00
Jon Seager
1f21dc27af
fix: prevent iOS auto-zoom on input focus
Bump .input-field font-size to 1rem (16px) on mobile so iOS Safari
does not auto-zoom the viewport when focusing text inputs, number
inputs, or searchable selects.
2026-02-11 10:11:02 +00:00
Jon Seager
55addb200c
fix: prevent double-tap zoom on mobile stepper buttons
Add touch-action: manipulation to .btn-adjust so rapid taps on +/-
buttons no longer trigger the browser's double-tap-to-zoom gesture.
2026-02-11 10:07:58 +00:00
Jon Seager
049e9d68a8
fix: mobile fixed nav bar and detail page polish
- Make nav bar fixed on mobile with safe-area-inset-top support for
  notched devices (10% reduction) and 1rem minimum for non-notched
- Adjust timeline sticky month headings to sit flush below the fixed
  nav with matching top/bottom padding
- Update IntersectionObserver rootMargin to account for fixed nav height
  so stuck-state accent border triggers correctly
- Increase main content top padding on mobile for balanced spacing on
  detail pages
- Add remaining field to bag edit form with +/- stepper buttons
- Make admin page passkey/token forms responsive with icon-only mobile
  delete/revoke buttons
- Make detail page action buttons stack vertically on mobile with equal
  width
2026-02-11 09:53:43 +00:00
Jon Seager
705144bcf7
fix: make detail page action buttons responsive on mobile 2026-02-11 09:05:58 +00:00
Jon Seager
76445f49ae
fix: improve admin page forms for mobile
Stack passkey and token input forms vertically on mobile with full-width
fields and buttons. Collapse Delete/Revoke buttons to icon-only squares
on mobile, expanding to show text labels on larger screens.
2026-02-11 08:59:52 +00:00
Jon Seager
3a32d9725a
feat: add remaining amount field to bag edit form 2026-02-11 08:53:56 +00:00
Jon Seager
4190fc2620
feat: log payload fields in trace spans by redacting image data
Add ImageData newtype that wraps Option<String> with a custom Debug impl
showing Some(<image>)/None instead of raw base64. Replace image fields on
all 14 submission structs and remove payload from tracing skip lists so
textual/numeric fields appear in spans.
2026-02-11 08:37:03 +00:00
Jon Seager
56a1637d63
style: use accented color for links on timeline 2026-02-10 20:35:42 +00:00
Jon Seager
a38e9aae5b
fix: use shortened dates in expanded timeline cards 2026-02-10 20:33:24 +00:00