Skip to content

Conversation

@DJJones66
Copy link
Contributor

🧩 Add Demo API Endpoint, Improve Plugin State Handling, and Backend Refactor

🔍 Overview

This PR introduces a range of backend and frontend updates to support better plugin state management, enable future plugin demos, and improve developer experience:

  • New demo.py API endpoint with full CRUD support for demonstration plugins
  • ✅ Improved initialization and reliability of PluginStateService through asynchronous readiness handling
  • ✅ Raw SQL insertion logic added to create_setting_instance to bypass SQLAlchemy relationship issues
  • ✅ Simplified dev setup instructions and clarified ROADMAP.md entry
  • 🧼 Removed unused image assets to reduce repo clutter

📦 Backend Changes

1. demo.py: New Demo Plugin Endpoint

  • Created a FastAPI router for /demo/ routes.

  • Includes endpoints:

    • GET /demo/items: Retrieve user-specific demo items
    • POST /demo/items: Create item
    • PUT /demo/items/{id}: Update item
    • DELETE /demo/items/{id}: Delete item
    • GET /demo/status: API and user stats
    • GET /demo/health: Health check
  • Uses in-memory storage (for non-production use).

2. settings.py: Raw SQL Insertion

  • Switched from ORM instance creation to direct SQL execution for SettingInstance.
  • Bypasses SQLAlchemy relationship resolution issues when saving settings with page and user scope.
  • Adds logic to resolve 'current' user_id to the actual user at runtime.

3. api.py

  • Registered new router: demo.router

🧠 Plugin State Enhancements

PluginStateService.ts

  • Introduced ensureInitialized() method to await PageContextService availability.
  • Prevents intermittent runtime errors where state would be accessed before context was ready.

PluginStateFactory.ts

  • Initialization now runs asynchronously with error logging, improving robustness without blocking startup.

serviceBridge.ts

  • Added safe fallback logic for the pluginState service lookup.

🧪 How to Test

  1. Run the backend and hit /api/v1/demo/health – should return 200 OK
  2. Login and try /api/v1/demo/items to create/view your items
  3. Validate plugin state still persists correctly across page reloads and devices
  4. Verify new setting instances write correctly with user and page scope

📝 Notes

  • This PR introduces non-breaking changes.
  • The new /demo endpoints are scaffold-only and safe for use in examples or testing.

@DJJones66 DJJones66 merged commit b5e1f93 into main Jul 30, 2025
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.

2 participants