feat: add Metabase API integration
All checks were successful
build-and-deploy / build (push) Successful in 45s
build-and-deploy / deploy (push) Successful in 3s

Add complete integration with Metabase API to fetch data from
'facturador supabase' database.

Features:
- Server-side Metabase authentication using session tokens
- Utility functions for Metabase API requests with auto-retry
- API endpoints to proxy Metabase requests
  - GET /api/metabase/databases - List all databases
  - GET /api/metabase/tables/:databaseId - Get tables and metadata
  - POST /api/metabase/query - Execute queries against tables
- useMetabase() composable for frontend consumption
  - getDatabases() - Fetch available databases
  - getDatabaseMetadata() - Get tables and fields info
  - queryTable() - Execute queries with filters and limits
  - resultToObjects() - Helper to convert results to objects

Session tokens are cached and auto-refreshed when expired.
This enables the application to display real data from the
facturador database without using embeds or iframes.
This commit is contained in:
2025-10-13 17:46:48 -06:00
parent f4047e1505
commit 4b25a70b8b
5 changed files with 350 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
/**
* Get tables from a specific Metabase database
*/
export default defineEventHandler(async (event) => {
const databaseId = getRouterParam(event, 'databaseId')
if (!databaseId) {
throw createError({
statusCode: 400,
statusMessage: 'Database ID is required'
})
}
try {
const metadata = await getMetabaseTables(parseInt(databaseId))
return metadata
} catch (error: any) {
console.error(`[API] Failed to get tables for database ${databaseId}:`, error)
throw createError({
statusCode: error.statusCode || 500,
statusMessage: error.statusMessage || 'Failed to fetch tables'
})
}
})