Commit Graph

45 Commits

Author SHA1 Message Date
Mohamed Bassem
5537fe85ed feat: Add open telemetry (#2318)
* feat: add OpenTelemetry tracing infrastructure

Introduce distributed tracing capabilities using OpenTelemetry:

- Add @opentelemetry packages to shared-server for tracing
- Create tracing utility module with span helpers (withSpan, addSpanEvent, etc.)
- Add tRPC middleware for automatic span creation on API calls
- Initialize tracing in API and workers entry points
- Add demo instrumentation to bookmark creation and crawler worker
- Add configuration options (OTEL_TRACING_ENABLED, OTEL_EXPORTER_OTLP_ENDPOINT, etc.)
- Document tracing configuration in environment variables docs

When enabled, traces are collected for tRPC calls, bookmark creation flow,
and crawler operations, with support for any OTLP-compatible backend (Jaeger, Tempo, etc.)

* refactor: remove tracing from workers for now

Keep tracing infrastructure but remove worker instrumentation:
- Remove tracing initialization from workers entry point
- Remove tracing instrumentation from crawler worker
- Fix formatting in tracing files

The tracing infrastructure remains available for future use.

* add hono and next tracing

* remove extra span logging

* more fixes

* update config

* some fixes

* upgrade packages

* remove unneeded packages

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-29 17:11:16 +00:00
Mohamed Bassem
2dbdf76c75 fix: reject spoofed content types on uploads 2025-12-27 00:36:21 +00:00
Mohamed Bassem
013ca67c15 refactor: move assets to their own model (#2301)
* refactor: move assets to their own model

* move asset privacy checks to the model
2025-12-24 11:58:37 +00:00
Mohamed Bassem
0b65e5a428 fix: move trpc error logging inside the dev check 2025-12-14 14:26:06 +00:00
Mohamed Bassem
1369ad01ce fix!: changing default for includeContent to be false in the API 2025-12-12 09:56:17 +00:00
Mohamed Bassem
3e8cc745dd fix: Add cache control header on asset endpoints 2025-12-10 08:04:15 +00:00
Mohamed Bassem
86a4b39665 feat: Add automated bookmark backup feature (#2182)
* feat: Add automated bookmark backup system

Implements a comprehensive automated backup feature for user bookmarks with the following capabilities:

Database Schema:
- Add backupSettings table to store user backup preferences (enabled, frequency, retention)
- Add backups table to track backup records with status and metadata
- Add BACKUP asset type for storing compressed backup files
- Add migration 0066_add_backup_tables.sql

Background Workers:
- Implement BackupSchedulingWorker cron job (runs daily at midnight UTC)
- Create BackupWorker to process individual backup jobs
- Deterministic scheduling spreads backup jobs across 24 hours based on user ID hash
- Support for daily and weekly backup frequencies
- Automated retention cleanup to delete old backups based on user settings

Export & Compression:
- Reuse existing export functionality for bookmark data
- Compress exports using Node.js built-in zlib (gzip level 9)
- Store compressed backups as assets with proper metadata
- Track backup size and bookmark count for statistics

tRPC API:
- backups.getSettings - Retrieve user backup configuration
- backups.updateSettings - Update backup preferences
- backups.list - List all user backups with metadata
- backups.get - Get specific backup details
- backups.delete - Delete a backup
- backups.download - Download backup file (base64 encoded)
- backups.triggerBackup - Manually trigger backup creation

UI Components:
- BackupSettings component with configuration form
- Enable/disable automatic backups toggle
- Frequency selection (daily/weekly)
- Retention period configuration (1-365 days)
- Backup list table with download and delete actions
- Manual backup trigger button
- Display backup stats (size, bookmark count, status)
- Added backups page to settings navigation

Technical Details:
- Uses Restate queue system for distributed job processing
- Implements idempotency keys to prevent duplicate backups
- Background worker concurrency: 2 jobs at a time
- 10-minute timeout for large backup exports
- Proper error handling and logging throughout
- Type-safe implementation with Zod schemas

* refactor: simplify backup settings and asset handling

- Move backup settings from separate table to user table columns
- Update BackupSettings model to use static methods with users table
- Remove download mutation in favor of direct asset links
- Implement proper quota checks using QuotaService.checkStorageQuota
- Update UI to use new property names and direct asset downloads
- Update shared types to match new schema

Key changes:
- backupSettingsTable removed, settings now in users table
- Backup downloads use direct /api/assets/{id} links
- Quota properly validated before creating backup assets
- Cleaner separation of concerns in tRPC models

* migration

* use zip instead of gzip

* fix drizzle

* fix settings

* streaming json

* remove more dead code

* add e2e tests

* return backup

* poll for backups

* more fixes

* more fixes

* fix test

* fix UI

* fix delete asset

* fix ui

* redirect for backup download

* cleanups

* fix idempotency

* fix tests

* add ratelimit

* add error handling for background backups

* i18n

* model changes

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-29 14:53:31 +00:00
Mohamed Bassem
472adec751 feat: add GET /api/version endpoint (#2167)
Implements a new API endpoint that returns the server version from serverConfig.
This will be used for Home Assistant integration to check for updates.

Fixes #2148

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Mohamed Bassem <MohamedBassem@users.noreply.github.com>
2025-11-23 14:49:15 +00:00
Mohamed Bassem
88c73e212c feat: Add collaborative lists (#2146)
* feat: Add collaborative lists backend implementation

This commit implements the core backend functionality for collaborative
lists, allowing multiple users to share and interact with bookmark lists.

Database changes:
- Add listCollaborators table to track users with access to lists and
  their roles (viewer/editor)
- Add addedBy field to bookmarksInLists to track who added bookmarks
- Add relations for collaborative list functionality

Access control updates:
- Update List model to support role-based access (owner/editor/viewer)
- Add methods to check and enforce permissions for list operations
- Update Bookmark model to allow access through collaborative lists
- Modify bookmark queries to include bookmarks from collaborative lists

List collaboration features:
- Add/remove/update collaborators
- Get list of collaborators
- Get lists shared with current user
- Only manual lists can have collaborators

tRPC procedures:
- addCollaborator: Add a user as a collaborator to a list
- removeCollaborator: Remove a collaborator from a list
- updateCollaboratorRole: Change a collaborator's role
- getCollaborators: Get all collaborators for a list
- getSharedWithMe: Get all lists shared with the current user
- cloneBookmark: Clone a bookmark to the current user's collection

Implementation notes:
- Editors can add/remove bookmarks from the list (must own the bookmark)
- Viewers can only view bookmarks in the list
- Only the list owner can manage collaborators and list metadata
- Smart lists cannot have collaborators (only manual lists)
- Users cannot edit bookmarks they don't own, even in shared lists

* feat: Add collaborative lists frontend UI

This commit implements the frontend user interface for collaborative lists,
allowing users to view shared bookmarks and manage list collaborators.

New pages:
- /dashboard/shared: Shows bookmarks from lists shared with the user
  - Displays bookmarks from all collaborative lists
  - Uses SharedBookmarks component
  - Shows empty state when no lists are shared

Navigation:
- Added "Shared with you" link to sidebar with Users icon
- Positioned after "Home" in main navigation
- Available in both desktop and mobile sidebar

Collaborator management:
- ManageCollaboratorsModal component for managing list collaborators
  - Add collaborators by user ID with viewer/editor role
  - View current collaborators with their roles
  - Update collaborator roles inline
  - Remove collaborators
  - Shows empty state when no collaborators
- Integrated into ListOptions dropdown menu
- Accessible via "Manage Collaborators" menu item

Components created:
- SharedBookmarks.tsx: Server component fetching shared lists/bookmarks
- ManageCollaboratorsModal.tsx: Client component with tRPC mutations
- /dashboard/shared/page.tsx: Route for shared bookmarks page

UI features:
- Role selector for viewer/editor permissions
- Real-time collaborator list updates
- Toast notifications for success/error states
- Loading states for async operations
- Responsive design matching existing UI patterns

Implementation notes:
- Uses existing tRPC endpoints (getSharedWithMe, getCollaborators, etc.)
- Follows established modal patterns from ShareListModal
- Integrates seamlessly with existing list UI
- Currently uses user ID for adding collaborators (email lookup TBD)

* fix typecheck

* add collaborator by email

* add shared list in the sidebar

* fix perm issue

* hide UI components from non list owners

* list leaving

* fix shared bookmarks showing up in homepage

* fix getBookmark access check

* e2e tests

* hide user specific fields from shared lists

* simplify bookmark perm checks

* disable editable fields in bookmark preview

* hide lists if they don't have options

* fix list ownership

* fix highlights

* move tests to trpc

* fix alignment of leave list

* make tag lists unclickable

* allow editors to remove from list

* add a badge for shared lists

* remove bookmarks of user when they're removed from a list

* fix tests

* show owner in the manage collab modal

* fix hasCollab

* drop shared with you

* i18n

* beta badge

* correctly invalidate caches on collab change

* reduce unnecessary changes

* Add ratelimits

* stop manually removing bookmarks on remove

* some fixes

* fixes

* remove unused function

* improve tests

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-17 01:12:41 +00:00
Mohamed Bassem
cc8fee0d28 deps: upgrade hono and playwright 2025-11-16 12:32:44 +00:00
Mohamed Bassem
c34f70dace feat: correct default prom metrics from web and worker containers 2025-11-10 10:55:07 +00:00
Mohamed Bassem
2defc2475f feat: Add source field to track bookmark creation sources (#2037)
* feat: Add source field to track bookmark creation sources

Add a new 'source' field to the bookmarks table to track where bookmarks
were created from. Possible values: api, web, cli, mobile, singlefile, rss.

Changes:
- Add source field to bookmarks table schema
- Update Zod schemas to include source field
- Update tRPC createBookmark procedure to store source
- Update all callsites to pass appropriate source value:
  - api: Default to "api" if not provided
  - singlefile: Set to "singlefile"
  - rss: Set to "rss" in feedWorker
  - cli: Set to "cli"
  - mobile: Set to "mobile" in all mobile app bookmark creation
  - browser-extension: Set to "web"
  - web: Set to "web" in all web app bookmark creation
- Create migration file for database schema change

Fixes #2036

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Mohamed Bassem <MohamedBassem@users.noreply.github.com>

* feat: Add extension source type for browser extension

- Add 'extension' to bookmark source enum
- Update browser extension to use 'extension' instead of 'web'

Co-authored-by: Mohamed Bassem <MohamedBassem@users.noreply.github.com>

* fix CI

* fix CI

* fix the migration file

* add import source

* make source nullish

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Mohamed Bassem <MohamedBassem@users.noreply.github.com>
2025-10-12 22:41:56 +01:00
Mohamed Bassem
f2dec26f30 fix(api): Return 200 when bookmark already exists instead of 200 2025-10-11 18:35:10 +00:00
Mohamed Bassem
62f7d900c5 feat: Add tag search and pagination (#1987)
* feat: Add tag search and use in the homepage

* use paginated query in the all tags view

* wire the load more buttons

* add skeleton to all tags page

* fix attachedby aggregation

* fix loading states

* fix hasNextPage

* use action buttons for load more buttons

* migrate the tags auto complete to the search api

* Migrate the tags editor to the new search API

* Replace tag merging dialog with tag auto completion

* Merge both search and list APIs

* fix tags.list

* add some tests for the endpoint

* add relevance based sorting

* change cursor

* update the REST API

* fix review comments

* more fixes

* fix lockfile

* i18n

* fix visible tags
2025-09-28 11:03:48 +01:00
Mohamed Bassem
3760d23abc refactor: Extract quota logic into its own class 2025-09-06 06:25:15 +00:00
Mohamed Bassem
f1961822fc fix: fix move the admin route to the /v1 prefix 2025-08-27 10:31:12 +00:00
MohamedBassem
a4b2fc7ca8 fix(security): Add CSP policies on asset serving path 2025-08-23 16:03:06 +03:00
MohamedBassem
096af7efff fix: Dont attempt to remove uploaded tmp file if it's already removed 2025-08-22 21:45:49 +03:00
MohamedBassem
39a650f634 fix: Sanitize uploaded file names. #1765 2025-08-22 21:36:44 +03:00
MohamedBassem
a64307e8ac feat: generate a random prometheus token on startup 2025-08-22 21:20:37 +03:00
MohamedBassem
6f699494b1 fix(tests): Load plugins on API package entrypoint 2025-07-27 21:53:20 +01:00
MohamedBassem
8fe4975c1f feat: Support NO_COLOR for logging. Fixes #1778 2025-07-27 21:45:57 +01:00
MohamedBassem
77ae89b222 chore: More turbo fixes 2025-07-27 15:06:22 +01:00
MohamedBassem
57d1e50d27 fix: Fix package boundary violations 2025-07-27 14:22:54 +01:00
Mohamed Bassem
77e3611400 fix: Add karakeep_ prefix to hono's metrics 2025-07-26 23:55:33 +00:00
Mohamed Bassem
a441a67775 deps: Upgrade vite 2025-07-26 21:32:40 +00:00
Mohamed Bassem
d1d5263486 feat: Add stripe based subscriptions 2025-07-13 20:44:00 +00:00
Mohamed Bassem
1105b4a41b feat(api): Expose the update user API in the openapi specs 2025-07-12 23:37:52 +00:00
Mohamed Bassem
93049e864a feat: Add support for email verification 2025-07-10 08:37:44 +00:00
Mohamed Bassem
aae3ef17ec fix(api): Fix handling for CORS after the trpc move to hono. Fixes #1709 2025-07-10 05:54:23 +00:00
Mohamed Bassem
b60ece5783 feat: Add prometheus monitoring. Fixes #758 2025-07-06 18:09:05 +00:00
Mohamed Bassem
384432d31e feat: Add per user storage quota 2025-07-06 16:32:35 +00:00
Mohamed Bassem
d66b3b8619 feat: Add support for S3 as an asset storage layer (#1703)
* feat: Add support for S3 as an asset storage layer. Fixes #305

* some minor fixes

* use bulk deletion api

* stream the file to s3
2025-07-04 23:58:42 +01:00
Mohamed Bassem
f144f1bcc2 refactor: Move the health endpoint to hono as well 2025-07-04 16:27:29 +00:00
Mohamed Bassem
f5e737bf96 refactor: Move the trpc endpoint to hono 2025-07-04 16:27:29 +00:00
Mohamed Bassem
f7b3193815 chore: More oxlint changes 2025-06-22 12:38:24 +00:00
xuatz
d5e2973dce chore: migrate away from eslint to oxlint (#1642)
* chore: migrate away from eslint to oxlint

* revert turbo task name lint

* it seems like we can remove the seemingly default globals
2025-06-22 12:29:30 +01:00
Mohamed Bassem
10d45e8d14 fix: Change public image's signed tokens to be time aligned for better caching 2025-06-21 11:32:42 +00:00
Mohamed Bassem
3a0f5fa0bb feat(ui): Improve the look of the public bookmarks page 2025-06-07 18:19:06 +00:00
Mohamed Bassem
bc65a73872 fix: Use a new public list metadata endpoint for metadata generation 2025-06-07 16:46:36 +00:00
Mohamed Bassem
e59be245d5 feat: Allow specifying the overwrite mode for singlefile archives. Fixes #1125 2025-06-01 20:53:12 +00:00
Mohamed Bassem
ea1d0023bf feat: Add support for public lists (#1511)
* WIP: public lists

* Drop viewing modes

* Add the public endpoint for assets

* regen the openapi spec

* proper handling for different asset types

* Add num bookmarks and a no bookmark banner

* Correctly set page title

* Add a not-found page

* merge the RSS and public list endpoints

* Add e2e tests for the public endpoints

* Redesign the share list modal

* Make NEXTAUTH_SECRET not required

* propery render text bookmarks

* rebase migration

* fix public token tests

* Add more tests
2025-06-01 20:46:41 +01:00
Mohamed Bassem
9695bba2e9 feat: Generate RSS feeds from lists (#1507)
* refactor: Move bookmark utils from shared-react to shared

* Expose RSS feeds for lists

* Add e2e tests

* Slightly improve the look of the share dialog

* allow specifying a limit in the rss endpoint
2025-05-31 18:46:04 +01:00
Mohamed Bassem
a5ae67c241 feat(api): Expose the endpoint to create a new tag 2025-05-18 19:12:27 +00:00
Mohamed Bassem
3505cb7d64 refactor: Migrate from NextJs's API routes to Hono based routes for the API (#1432)
* Setup Hono and migrate the highlights API there

* Implement the tags and lists endpoint

* Implement the bookmarks and users endpoints

* Add the trpc error code adapter

* Remove the old nextjs handlers

* fix api key not found handling

* Fix trpc error handling

* Fix 204 handling

* Fix search ordering

* Implement the singlefile endpoint

* Implement the asset serving endpoints

* Implement webauth

* Add hono as a catch all route under api

* fix tests
2025-05-18 16:58:08 +01:00