mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 04:31:13 -05:00
Fix build errors
This commit is contained in:
@@ -1898,6 +1898,69 @@ export type Database = {
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
request_metadata: {
|
||||
Row: {
|
||||
client_version: string | null
|
||||
completed_at: string | null
|
||||
created_at: string
|
||||
duration_ms: number | null
|
||||
endpoint: string
|
||||
error_message: string | null
|
||||
error_type: string | null
|
||||
id: string
|
||||
ip_address_hash: string | null
|
||||
method: string
|
||||
parent_request_id: string | null
|
||||
request_id: string
|
||||
retry_count: number | null
|
||||
started_at: string
|
||||
status_code: number | null
|
||||
trace_id: string | null
|
||||
user_agent: string | null
|
||||
user_id: string | null
|
||||
}
|
||||
Insert: {
|
||||
client_version?: string | null
|
||||
completed_at?: string | null
|
||||
created_at?: string
|
||||
duration_ms?: number | null
|
||||
endpoint: string
|
||||
error_message?: string | null
|
||||
error_type?: string | null
|
||||
id?: string
|
||||
ip_address_hash?: string | null
|
||||
method: string
|
||||
parent_request_id?: string | null
|
||||
request_id: string
|
||||
retry_count?: number | null
|
||||
started_at?: string
|
||||
status_code?: number | null
|
||||
trace_id?: string | null
|
||||
user_agent?: string | null
|
||||
user_id?: string | null
|
||||
}
|
||||
Update: {
|
||||
client_version?: string | null
|
||||
completed_at?: string | null
|
||||
created_at?: string
|
||||
duration_ms?: number | null
|
||||
endpoint?: string
|
||||
error_message?: string | null
|
||||
error_type?: string | null
|
||||
id?: string
|
||||
ip_address_hash?: string | null
|
||||
method?: string
|
||||
parent_request_id?: string | null
|
||||
request_id?: string
|
||||
retry_count?: number | null
|
||||
started_at?: string
|
||||
status_code?: number | null
|
||||
trace_id?: string | null
|
||||
user_agent?: string | null
|
||||
user_id?: string | null
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
review_deletions: {
|
||||
Row: {
|
||||
content: string | null
|
||||
@@ -3734,6 +3797,10 @@ export type Database = {
|
||||
Args: Record<PropertyKey, never>
|
||||
Returns: undefined
|
||||
}
|
||||
cleanup_old_request_metadata: {
|
||||
Args: Record<PropertyKey, never>
|
||||
Returns: undefined
|
||||
}
|
||||
cleanup_old_versions: {
|
||||
Args: { entity_type: string; keep_versions?: number }
|
||||
Returns: number
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
* Manages moderation workflow with type-safe state transitions and lock coordination
|
||||
*/
|
||||
|
||||
import type { SubmissionItemData } from '@/types/photo-submissions';
|
||||
// Generic review data interface for moderation
|
||||
export interface ModerationReviewData {
|
||||
id: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
// State definitions using discriminated unions
|
||||
export type ModerationState =
|
||||
@@ -11,7 +15,7 @@ export type ModerationState =
|
||||
| { status: 'claiming'; itemId: string }
|
||||
| { status: 'locked'; itemId: string; lockExpires: string }
|
||||
| { status: 'loading_data'; itemId: string; lockExpires: string }
|
||||
| { status: 'reviewing'; itemId: string; lockExpires: string; reviewData: SubmissionItemData[] }
|
||||
| { status: 'reviewing'; itemId: string; lockExpires: string; reviewData: ModerationReviewData[] }
|
||||
| { status: 'approving'; itemId: string }
|
||||
| { status: 'rejecting'; itemId: string }
|
||||
| { status: 'complete'; itemId: string; result: 'approved' | 'rejected' }
|
||||
@@ -24,7 +28,7 @@ export type ModerationAction =
|
||||
| { type: 'LOCK_ACQUIRED'; payload: { lockExpires: string } }
|
||||
| { type: 'LOCK_EXPIRED' }
|
||||
| { type: 'LOAD_DATA' }
|
||||
| { type: 'DATA_LOADED'; payload: { reviewData: SubmissionItemData[] } }
|
||||
| { type: 'DATA_LOADED'; payload: { reviewData: ModerationReviewData[] } }
|
||||
| { type: 'START_APPROVAL' }
|
||||
| { type: 'START_REJECTION' }
|
||||
| { type: 'COMPLETE'; payload: { result: 'approved' | 'rejected' } }
|
||||
|
||||
@@ -107,20 +107,25 @@ interface RequestMetadata {
|
||||
}
|
||||
|
||||
async function logRequestMetadata(metadata: RequestMetadata): Promise<void> {
|
||||
await supabase.from('request_metadata').insert({
|
||||
request_id: metadata.requestId,
|
||||
user_id: metadata.userId || null,
|
||||
endpoint: metadata.endpoint,
|
||||
method: metadata.method,
|
||||
status_code: metadata.statusCode,
|
||||
duration_ms: metadata.duration,
|
||||
error_type: metadata.errorType || null,
|
||||
error_message: metadata.errorMessage || null,
|
||||
user_agent: metadata.userAgent || null,
|
||||
client_version: metadata.clientVersion || null,
|
||||
parent_request_id: metadata.parentRequestId || null,
|
||||
trace_id: metadata.traceId || null,
|
||||
// Direct RPC call since types haven't regenerated yet
|
||||
const { error } = await supabase.rpc('log_request_metadata', {
|
||||
p_request_id: metadata.requestId,
|
||||
p_user_id: metadata.userId || null,
|
||||
p_endpoint: metadata.endpoint,
|
||||
p_method: metadata.method,
|
||||
p_status_code: metadata.statusCode,
|
||||
p_duration_ms: metadata.duration,
|
||||
p_error_type: metadata.errorType || null,
|
||||
p_error_message: metadata.errorMessage || null,
|
||||
p_user_agent: metadata.userAgent || null,
|
||||
p_client_version: metadata.clientVersion || null,
|
||||
p_parent_request_id: metadata.parentRequestId || null,
|
||||
p_trace_id: metadata.traceId || null,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error('[RequestTracking] Failed to log metadata:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
-- Request Metadata Table
|
||||
-- Stores detailed context about API requests for monitoring and debugging
|
||||
|
||||
CREATE TABLE IF NOT EXISTS request_metadata (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
request_id uuid UNIQUE NOT NULL,
|
||||
user_id uuid REFERENCES auth.users(id) ON DELETE SET NULL,
|
||||
|
||||
-- Request context
|
||||
endpoint text NOT NULL,
|
||||
method text NOT NULL,
|
||||
status_code integer,
|
||||
|
||||
-- Timing
|
||||
started_at timestamptz NOT NULL DEFAULT now(),
|
||||
completed_at timestamptz,
|
||||
duration_ms integer,
|
||||
|
||||
-- Client info
|
||||
user_agent text,
|
||||
client_version text,
|
||||
ip_address_hash text,
|
||||
|
||||
-- Error tracking
|
||||
error_type text,
|
||||
error_message text,
|
||||
retry_count integer DEFAULT 0,
|
||||
|
||||
-- Correlation for distributed tracing
|
||||
parent_request_id uuid,
|
||||
trace_id uuid,
|
||||
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- Indexes for efficient querying
|
||||
CREATE INDEX IF NOT EXISTS idx_request_metadata_user_id ON request_metadata(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_request_metadata_started_at ON request_metadata(started_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_request_metadata_trace_id ON request_metadata(trace_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_request_metadata_request_id ON request_metadata(request_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_request_metadata_status_code ON request_metadata(status_code);
|
||||
|
||||
-- Enable RLS
|
||||
ALTER TABLE request_metadata ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Policies: Only admins and system can read/write
|
||||
CREATE POLICY "Service role can insert request metadata"
|
||||
ON request_metadata
|
||||
FOR INSERT
|
||||
WITH CHECK (true);
|
||||
|
||||
CREATE POLICY "Service role can read request metadata"
|
||||
ON request_metadata
|
||||
FOR SELECT
|
||||
USING (true);
|
||||
|
||||
-- Function to clean up old request metadata (keep 30 days)
|
||||
CREATE OR REPLACE FUNCTION cleanup_old_request_metadata()
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
AS $$
|
||||
BEGIN
|
||||
DELETE FROM request_metadata
|
||||
WHERE created_at < now() - interval '30 days';
|
||||
END;
|
||||
$$;
|
||||
|
||||
COMMENT ON TABLE request_metadata IS 'Stores request correlation IDs and metadata for monitoring and debugging';
|
||||
COMMENT ON COLUMN request_metadata.request_id IS 'Unique correlation ID for this request';
|
||||
COMMENT ON COLUMN request_metadata.trace_id IS 'Distributed tracing ID for tracking related requests';
|
||||
COMMENT ON COLUMN request_metadata.parent_request_id IS 'Parent request ID for chained operations';
|
||||
Reference in New Issue
Block a user