mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 16:51:13 -05:00
Migrate remaining edge functions to wrapper
Refactor process-expired-bans, detect-location, detect-anomalies, rate-limit-metrics, and collect-metrics to use createEdgeFunction wrapper with standardized error handling, tracing, and reduced boilerplate. Update signatures to receive { supabase, span, requestId } (and user where applicable), replace manual logging with span events, remove per-function boilerplate, and ensure consistent wrapper configuration (cors, auth, rate limits, and tracing).
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
/**
|
||||
* Rate Limit Metrics API
|
||||
*
|
||||
* Exposes rate limiting metrics for monitoring and analysis.
|
||||
* Requires admin/moderator authentication.
|
||||
*/
|
||||
|
||||
import { createEdgeFunction } from '../_shared/edgeFunctionWrapper.ts';
|
||||
import { serve } from 'https://deno.land/std@0.190.0/http/server.ts';
|
||||
import { createEdgeFunction, type EdgeFunctionContext } from '../_shared/edgeFunctionWrapper.ts';
|
||||
import { corsHeaders } from '../_shared/cors.ts';
|
||||
import {
|
||||
getRecentMetrics,
|
||||
getMetricsStats,
|
||||
@@ -15,18 +10,7 @@ import {
|
||||
clearMetrics,
|
||||
} from '../_shared/rateLimitMetrics.ts';
|
||||
|
||||
interface QueryParams {
|
||||
action?: string;
|
||||
limit?: string;
|
||||
timeWindow?: string;
|
||||
functionName?: string;
|
||||
userId?: string;
|
||||
clientIP?: string;
|
||||
}
|
||||
|
||||
const handler = async (req: Request, context: { supabase: any; user: any; span: any; requestId: string }) => {
|
||||
const { supabase, user } = context;
|
||||
|
||||
const handler = async (req: Request, { supabase, user, span, requestId }: EdgeFunctionContext) => {
|
||||
// Check if user has admin or moderator role
|
||||
const { data: roles } = await supabase
|
||||
.from('user_roles')
|
||||
@@ -116,14 +100,10 @@ const handler = async (req: Request, context: { supabase: any; user: any; span:
|
||||
return responseData;
|
||||
};
|
||||
|
||||
// Create edge function with automatic error handling, CORS, auth, and logging
|
||||
createEdgeFunction(
|
||||
{
|
||||
name: 'rate-limit-metrics',
|
||||
requireAuth: true,
|
||||
corsEnabled: true,
|
||||
enableTracing: false,
|
||||
rateLimitTier: 'lenient'
|
||||
},
|
||||
handler
|
||||
);
|
||||
serve(createEdgeFunction({
|
||||
name: 'rate-limit-metrics',
|
||||
requireAuth: true,
|
||||
corsHeaders,
|
||||
enableTracing: true,
|
||||
rateLimitTier: 'lenient',
|
||||
}, handler));
|
||||
|
||||
Reference in New Issue
Block a user