Skip to content

Conversation

@lewisjared
Copy link
Contributor

Summary

  • Add BookshelfAPIClient HTTP client for the bookshelf-platform backend API with auth, error handling, and typed response schemas
  • Add bookshelf.auth module for token-based authentication (device flow, token storage/refresh)
  • Add CLI (bookshelf-client / bsc) with auth, books, and volumes subcommands using Click + Rich
  • Make auth optional so public dataset access works without credentials

Details

This is a feature branch that will accumulate further PRs. The initial set of changes introduces:

  • API client (bookshelf.api): Synchronous httpx-based client with Pydantic response models for volumes, books, and tokens
  • Auth (bookshelf.auth): Device code flow authentication, secure token storage via platformdirs, automatic token refresh
  • CLI (bookshelf.cli): Click-based CLI with commands for login/logout/status, listing/searching books and volumes
  • Tests: Unit tests for API client, auth module, and CLI commands

Test plan

  • uv run --package bookshelf pytest packages/bookshelf/tests/unit/test_api_client.py
  • uv run --package bookshelf pytest packages/bookshelf/tests/unit/test_auth.py
  • uv run --package bookshelf pytest packages/bookshelf/tests/unit/test_cli.py

Add comprehensive support for the new bookshelf-platform API:

- API client module (bookshelf.api):
  - BookshelfAPIClient for volumes, books, and authentication
  - Pydantic schemas for request/response validation
  - Custom error types (APIError, AuthenticationError, NotFoundError, ServerError)

- Authentication module (bookshelf.auth):
  - Credential storage using platformdirs
  - Token expiry management
  - Environment variable overrides (BOOKSHELF_API_URL, BOOKSHELF_TOKEN)

- CLI tool (bookshelf-client):
  - auth commands: login, logout, status
  - volumes commands: list, show
  - books commands: list, show
  - Rich terminal output with tables and panels

- 76 unit tests covering all new functionality

Dependencies added: httpx, click, rich, respx (dev)
Remove authentication requirement from volumes and books CLI commands
to allow unauthenticated access to public datasets. Auth is still
available and will be used if credentials exist.

Also fix uv deprecation warning by migrating from tool.uv.dev-dependencies
to dependency-groups.dev in all pyproject.toml files.
- Set default API URL to https://api.staging.climateresource.com.au/bookshelf/v1
- Remove /api prefix from endpoint paths (base URL includes full path)
- Update all tests to match new URL structure
Migrate CLI authentication from username/password (POST /auth/token)
to WorkOS OAuth with PKCE and Device Code flows. The old endpoint
no longer exists after the platform migrated to WorkOS.

- Add oauth.py with PKCE, Device Code, and token refresh flows
- Extend Credentials with refresh_token, add auto-refresh on expiry
- Replace login command: --device-code flag for headless environments
- Add on_token_refresh callback to API client with 401 retry
- Add refresh_token to TokenResponse schema
WorkOS requires a connection selector (connection_id, organization_id,
or provider) in the authorize request. Without it, the flow fails with
invalid_connection_selector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant