feat: v3.4.0 — OpenPanel plugin public release (42 tools)
OpenPanel product analytics plugin fully reviewed, tested, and published. Works with both self-hosted and cloud (openpanel.dev) instances. - 42 tools: event tracking, data export, analytics, project/client management - All tools use public REST APIs (Track, Export, Insights, Manage) - Client modes: write (tracking), read (analytics), root (full access) - Service page with description, setup notes, WordPress plugin download - Dynamic URL hints in Add Site form - 62 unit tests - ENABLED_PLUGINS default now includes openpanel Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
"""Clients Handler - OpenPanel API client/key management (6 tools)"""
|
||||
"""Clients Handler - OpenPanel API client management (5 tools).
|
||||
|
||||
Uses Manage API (GET/POST/PATCH/DELETE /manage/clients).
|
||||
Requires 'root' mode client.
|
||||
"""
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
@@ -7,107 +11,82 @@ from plugins.openpanel.client import OpenPanelClient
|
||||
|
||||
|
||||
def get_tool_specifications() -> list[dict[str, Any]]:
|
||||
"""Return tool specifications for ToolGenerator (6 tools)"""
|
||||
"""Return tool specifications for ToolGenerator (5 tools)."""
|
||||
return [
|
||||
{
|
||||
"name": "list_clients",
|
||||
"method_name": "list_clients",
|
||||
"description": "List all API clients for a project.",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {"project_id": {"type": "string", "description": "Project ID"}},
|
||||
"required": ["project_id"],
|
||||
},
|
||||
"scope": "read",
|
||||
"description": "List all API clients via Manage API. Requires 'root' mode client.",
|
||||
"schema": {"type": "object", "properties": {}},
|
||||
"scope": "admin",
|
||||
},
|
||||
{
|
||||
"name": "get_client",
|
||||
"method_name": "get_client",
|
||||
"description": "Get API client details.",
|
||||
"description": "Get API client details via Manage API. Requires 'root' mode client.",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"project_id": {"type": "string", "description": "Project ID"},
|
||||
"client_id": {"type": "string", "description": "API Client ID"},
|
||||
"client_id": {"type": "string", "description": "Client ID"},
|
||||
},
|
||||
"required": ["project_id", "client_id"],
|
||||
"required": ["client_id"],
|
||||
},
|
||||
"scope": "read",
|
||||
"scope": "admin",
|
||||
},
|
||||
{
|
||||
"name": "create_client",
|
||||
"method_name": "create_client",
|
||||
"description": "Create a new API client for tracking or export.",
|
||||
"description": "Create a new API client via Manage API. Modes: 'write' (tracking only), 'read' (export/analytics), 'root' (full access). Requires 'root' mode client.",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"project_id": {"type": "string", "description": "Project ID"},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "Client name (e.g., 'Web Tracker', 'Backend Export')",
|
||||
},
|
||||
"name": {"type": "string", "description": "Client name"},
|
||||
"project_id": {"type": "string", "description": "Project to associate with"},
|
||||
"mode": {
|
||||
"type": "string",
|
||||
"enum": ["write", "read", "root"],
|
||||
"description": "Client mode: write (tracking), read (export), root (full access)",
|
||||
},
|
||||
"cors_domains": {
|
||||
"anyOf": [{"type": "array", "items": {"type": "string"}}, {"type": "null"}],
|
||||
"description": "Allowed domains for CORS (write mode)",
|
||||
"description": "Client mode: write (tracking), read (export/analytics), root (full access)",
|
||||
"default": "write",
|
||||
},
|
||||
},
|
||||
"required": ["project_id", "name", "mode"],
|
||||
"required": ["name", "project_id"],
|
||||
},
|
||||
"scope": "admin",
|
||||
},
|
||||
{
|
||||
"name": "update_client",
|
||||
"method_name": "update_client",
|
||||
"description": "Update an API client via Manage API. Requires 'root' mode client.",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"client_id": {"type": "string", "description": "Client ID to update"},
|
||||
"name": {
|
||||
"anyOf": [{"type": "string"}, {"type": "null"}],
|
||||
"description": "New client name",
|
||||
},
|
||||
"mode": {
|
||||
"anyOf": [
|
||||
{"type": "string", "enum": ["write", "read", "root"]},
|
||||
{"type": "null"},
|
||||
],
|
||||
"description": "New client mode",
|
||||
},
|
||||
},
|
||||
"required": ["client_id"],
|
||||
},
|
||||
"scope": "admin",
|
||||
},
|
||||
{
|
||||
"name": "delete_client",
|
||||
"method_name": "delete_client",
|
||||
"description": "Delete an API client.",
|
||||
"description": "Delete an API client via Manage API. WARNING: Any integrations using this client will stop working. Requires 'root' mode client.",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"project_id": {"type": "string", "description": "Project ID"},
|
||||
"client_id": {"type": "string", "description": "Client ID to delete"},
|
||||
},
|
||||
"required": ["project_id", "client_id"],
|
||||
},
|
||||
"scope": "admin",
|
||||
},
|
||||
{
|
||||
"name": "regenerate_client_secret",
|
||||
"method_name": "regenerate_client_secret",
|
||||
"description": "Regenerate the secret for an API client.",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"project_id": {"type": "string", "description": "Project ID"},
|
||||
"client_id": {"type": "string", "description": "Client ID"},
|
||||
},
|
||||
"required": ["project_id", "client_id"],
|
||||
},
|
||||
"scope": "admin",
|
||||
},
|
||||
{
|
||||
"name": "update_client_mode",
|
||||
"method_name": "update_client_mode",
|
||||
"description": "Update API client permissions/mode.",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"project_id": {"type": "string", "description": "Project ID"},
|
||||
"client_id": {"type": "string", "description": "Client ID"},
|
||||
"mode": {
|
||||
"type": "string",
|
||||
"enum": ["write", "read", "root"],
|
||||
"description": "New mode",
|
||||
},
|
||||
"cors_domains": {
|
||||
"anyOf": [{"type": "array", "items": {"type": "string"}}, {"type": "null"}],
|
||||
"description": "New CORS domains",
|
||||
},
|
||||
},
|
||||
"required": ["project_id", "client_id", "mode"],
|
||||
"required": ["client_id"],
|
||||
},
|
||||
"scope": "admin",
|
||||
},
|
||||
@@ -115,20 +94,21 @@ def get_tool_specifications() -> list[dict[str, Any]]:
|
||||
|
||||
|
||||
# =====================
|
||||
# Client Functions (6)
|
||||
# Client Functions (5)
|
||||
# =====================
|
||||
|
||||
|
||||
async def list_clients(client: OpenPanelClient, project_id: str) -> str:
|
||||
"""List all API clients"""
|
||||
async def list_clients(client: OpenPanelClient) -> str:
|
||||
"""List all API clients via GET /manage/clients."""
|
||||
try:
|
||||
result = await client.list_clients()
|
||||
clients = (
|
||||
result
|
||||
if isinstance(result, list)
|
||||
else result.get("data", []) if isinstance(result, dict) else []
|
||||
)
|
||||
return json.dumps(
|
||||
{
|
||||
"success": True,
|
||||
"project_id": project_id,
|
||||
"note": "Client listing requires dashboard tRPC API. Use OpenPanel dashboard to view clients.",
|
||||
"message": "Client list request processed",
|
||||
},
|
||||
{"success": True, "count": len(clients), "clients": clients},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
@@ -136,117 +116,76 @@ async def list_clients(client: OpenPanelClient, project_id: str) -> str:
|
||||
return json.dumps({"success": False, "error": str(e)}, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
async def get_client(client: OpenPanelClient, project_id: str, client_id: str) -> str:
|
||||
"""Get API client details"""
|
||||
async def get_client(client: OpenPanelClient, client_id: str) -> str:
|
||||
"""Get client details via GET /manage/clients/:id."""
|
||||
try:
|
||||
return json.dumps(
|
||||
{
|
||||
"success": True,
|
||||
"project_id": project_id,
|
||||
"client_id": client_id,
|
||||
"note": "Client details require dashboard tRPC API. Use OpenPanel dashboard for full view.",
|
||||
"message": "Client details request processed",
|
||||
},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
result = await client.get_client(client_id)
|
||||
return json.dumps({"success": True, "client": result}, indent=2, ensure_ascii=False)
|
||||
except Exception as e:
|
||||
return json.dumps({"success": False, "error": str(e)}, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
async def create_client(
|
||||
client: OpenPanelClient,
|
||||
project_id: str,
|
||||
name: str,
|
||||
mode: str,
|
||||
cors_domains: list[str] | None = None,
|
||||
) -> str:
|
||||
"""Create a new API client"""
|
||||
try:
|
||||
client_config = {"name": name, "mode": mode, "cors_domains": cors_domains}
|
||||
|
||||
mode_descriptions = {
|
||||
"write": "Can send events (tracking)",
|
||||
"read": "Can read/export data",
|
||||
"root": "Full access (tracking + export + management)",
|
||||
}
|
||||
|
||||
return json.dumps(
|
||||
{
|
||||
"success": True,
|
||||
"project_id": project_id,
|
||||
"client": client_config,
|
||||
"mode_description": mode_descriptions.get(mode, "Unknown mode"),
|
||||
"note": "Client creation requires dashboard tRPC API. Use OpenPanel dashboard to create clients.",
|
||||
"message": f"Client '{name}' configuration created with {mode} mode",
|
||||
},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
except Exception as e:
|
||||
return json.dumps({"success": False, "error": str(e)}, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
async def delete_client(client: OpenPanelClient, project_id: str, client_id: str) -> str:
|
||||
"""Delete an API client"""
|
||||
try:
|
||||
return json.dumps(
|
||||
{
|
||||
"success": True,
|
||||
"project_id": project_id,
|
||||
"client_id": client_id,
|
||||
"note": "Client deletion requires dashboard tRPC API. Use OpenPanel dashboard to delete clients.",
|
||||
"warning": "Deleting a client will invalidate all requests using its credentials.",
|
||||
"message": "Client deletion request processed",
|
||||
},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
except Exception as e:
|
||||
return json.dumps({"success": False, "error": str(e)}, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
async def regenerate_client_secret(client: OpenPanelClient, project_id: str, client_id: str) -> str:
|
||||
"""Regenerate client secret"""
|
||||
try:
|
||||
return json.dumps(
|
||||
{
|
||||
"success": True,
|
||||
"project_id": project_id,
|
||||
"client_id": client_id,
|
||||
"note": "Secret regeneration requires dashboard tRPC API. Use OpenPanel dashboard to regenerate.",
|
||||
"warning": "Regenerating secret will invalidate the current secret immediately.",
|
||||
"message": "Secret regeneration request processed",
|
||||
},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
except Exception as e:
|
||||
return json.dumps({"success": False, "error": str(e)}, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
async def update_client_mode(
|
||||
client: OpenPanelClient,
|
||||
project_id: str,
|
||||
client_id: str,
|
||||
mode: str,
|
||||
cors_domains: list[str] | None = None,
|
||||
mode: str = "write",
|
||||
) -> str:
|
||||
"""Update client permissions"""
|
||||
"""Create a new API client via POST /manage/clients."""
|
||||
try:
|
||||
updates = {"mode": mode, "cors_domains": cors_domains}
|
||||
|
||||
data: dict[str, Any] = {"name": name, "projectId": project_id, "mode": mode}
|
||||
result = await client.create_client(data)
|
||||
return json.dumps(
|
||||
{
|
||||
"success": True,
|
||||
"project_id": project_id,
|
||||
"client_id": client_id,
|
||||
"updates": updates,
|
||||
"note": "Client mode update requires dashboard tRPC API. Use OpenPanel dashboard to modify.",
|
||||
"message": f"Client mode update to {mode} configuration created",
|
||||
"message": f"Client '{name}' created with {mode} mode",
|
||||
"client": result,
|
||||
"note": "Save the client_secret — it cannot be retrieved later.",
|
||||
},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
except Exception as e:
|
||||
return json.dumps({"success": False, "error": str(e)}, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
async def update_client(
|
||||
client: OpenPanelClient,
|
||||
client_id: str,
|
||||
name: str | None = None,
|
||||
mode: str | None = None,
|
||||
) -> str:
|
||||
"""Update a client via PATCH /manage/clients/:id."""
|
||||
try:
|
||||
data: dict[str, Any] = {}
|
||||
if name:
|
||||
data["name"] = name
|
||||
if mode:
|
||||
data["mode"] = mode
|
||||
if not data:
|
||||
return json.dumps(
|
||||
{"success": False, "error": "No fields to update. Provide name or mode."},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
result = await client.update_client(client_id, data)
|
||||
return json.dumps(
|
||||
{"success": True, "message": f"Client '{client_id}' updated", "client": result},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
except Exception as e:
|
||||
return json.dumps({"success": False, "error": str(e)}, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
async def delete_client(client: OpenPanelClient, client_id: str) -> str:
|
||||
"""Delete a client via DELETE /manage/clients/:id."""
|
||||
try:
|
||||
result = await client.delete_client(client_id)
|
||||
return json.dumps(
|
||||
{"success": True, "message": f"Client '{client_id}' deleted", "result": result},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
except Exception as e:
|
||||
return json.dumps({"success": False, "error": str(e)}, indent=2, ensure_ascii=False)
|
||||
|
||||
Reference in New Issue
Block a user