Commit Graph

636 Commits

Author SHA1 Message Date
gpt-engineer-app[bot]
177eb540a8 Fix security warnings in migration
- Change security settings for views to SECURITY INVOKER
- Add explicit search_path in cleanup_old_spans function
- Ensure safe, non-deferring access to trace views and cleanup routine
2025-11-11 04:24:38 +00:00
gpt-engineer-app[bot]
ca6e95f4f8 Capture backend response metadata
Update edge function wrapper to emit backend metadata headers (X-Request-Id, X-Span-Id, X-Trace-Id, X-Duration-Ms) on responses; adjust logging to include duration and headers. Enhance edgeFunctionTracking to extract and propagate backend metadata from responses and errors; extend errorHandler to capture and log backend metadata for improved observability.
2025-11-11 04:18:20 +00:00
gpt-engineer-app[bot]
08926610b9 Migrate check-transaction-status to wrapper
Migrate the remaining administrative function check-transaction-status to use the wrapEdgeFunction wrapper, aligning with admin-delete-user. Updated to remove manual Deno.serve handling, integrate edge wrapper, standardized logging with edgeLogger, and utilize context for auth and tracing. admin-delete-user already migrated.
2025-11-11 03:56:44 +00:00
gpt-engineer-app[bot]
a1280ddd05 Migrate Novu functions to wrapEdgeFunction
Refactor Phase 3 Batch 2–4 Novu-related functions to use the createEdgeFunction wrapper, replacing explicit HTTP servers with edge wrapper, adding standardized logging, tracing, and error handling across subscriber management, topic/notification, and migration/sync functions.
2025-11-11 03:55:02 +00:00
gpt-engineer-app[bot]
19804ea9bd Migrate Admin Admin Functions to wrapEdgeFunction
Migrate Phase 3 administrative functions to use the wrapEdgeFunction wrapper:
- cancel-account-deletion
- cancel-email-change
- create-novu-subscriber
- update-novu-subscriber
- trigger-notification
- remove-novu-subscriber
- manage-moderator-topic
- migrate-novu-users
- sync-all-moderators-to-topic
- update-novu-preferences
- notify-system-announcement

This update standardizes error handling, tracing, auth, and logging across admin endpoints, removes manual serve/CORS boilerplate, and prepares for consistent monitoring and testing.
2025-11-11 03:49:54 +00:00
gpt-engineer-app[bot]
16a1fa756d Continue Phase 2 Batch 2 and Batch 3
Migrate 6 background jobs to use wrapEdgeFunction: cleanup-old-versions, process-scheduled-deletions, data-retention-cleanup, run-cleanup-jobs, scheduled-maintenance, process-expired-bans. Replace old server routines with edgeFunction wrapper, add centralized logging, tracing, and standardized error handling, and adjust for batch-wise deployment.
2025-11-11 03:36:40 +00:00
gpt-engineer-app[bot]
12d2518eb9 Migrate Phase 2 Batch 1
Migrate 3 Phase 2 monitoring functions (collect-metrics, detect-anomalies, monitor-rate-limits) to use wrapEdgeFunction with smaller batch updates, replacing manual handlers, adding shared logging/tracing, and standardizing error handling.
2025-11-11 03:30:00 +00:00
gpt-engineer-app[bot]
e28dc97d71 Migrate Phase 1 Functions
Migrate 8 high-priority functions (admin-delete-user, mfa-unenroll, confirm-account-deletion, request-account-deletion, send-contact-message, upload-image, validate-email-backend, process-oauth-profile) to wrapEdgeFunction pattern. Replace manual CORS/auth, add shared validations, integrate standardized error handling, and preserve existing rate limiting where applicable. Update implementations to leverage context span, requestId, and improved logging for consistent error reporting and tracing.
2025-11-11 03:03:26 +00:00
gpt-engineer-app[bot]
7181fdbcac Add comprehensive edge-function error handling
Enhance error handling and logging across all edge functions:
- Introduce a shared edgeFunctionWrapper with standardized error handling, request/response logging, tracing, and validation hooks.
- Add runtime type validation utilities (ValidationError, validators, and parse/validate helpers) and integrate into edge flow.
- Implement robust validation for incoming requests and known type mismatches, with detailed logs and structured responses.
- Add post-RPC and post-database error logging to surface type/mismatch issues early.
- Update approval/rejection entry points to leverage new validators and centralized error handling.
2025-11-11 02:54:50 +00:00
gpt-engineer-app[bot]
1a101b4109 Connect to Lovable Cloud
Applied migration to fix process_approval_transaction to support all company types: company, manufacturer, operator, property_owner, designer. This resolves unknown item type errors and enables moderation approvals across all entity types. Migration was executed successfully.
2025-11-11 02:50:04 +00:00
gpt-engineer-app[bot]
60c749c715 Update idempotency key handling in edge functions
Read idempotency key from headers in process-selective-approval and process-selective-rejection, remove it from request bodies, add header validation, and redeploy edge functions to fix idempotency flow.
2025-11-11 02:43:51 +00:00
gpt-engineer-app[bot]
7642ac435b Connect to Lovable Cloud
Improve CORS handling and error logging to fix moderation edge cases:
- Add x-idempotency-key to allowed CORS headers and expose explicit POST methods
- Extend CORS headers to include Access-Control-Allow-Methods
- Update edge function tracing and client error handling to better detect and log CORS/network issues
- Enhance error handling utilities to surface CORS-related failures and provide clearer user messages
2025-11-11 02:39:15 +00:00
gpt-engineer-app[bot]
c632e559d0 Add advanced ML anomaly detection 2025-11-11 02:30:12 +00:00
gpt-engineer-app[bot]
12a6bfdfab Add Advanced ML Anomaly Detection
Enhance detect-anomalies with advanced ML algorithms (Isolation Forest, seasonal decomposition, predictive modeling) and schedule frequent runs via pg_cron. Updates include implementing new detectors, ensemble logic, and plumbing to run and expose results through the anomaly detection UI and data hooks.
2025-11-11 02:28:19 +00:00
gpt-engineer-app[bot]
915a9fe2df Add automated data retention cleanup
Implements edge function, Django tasks, and UI hooks/panels for automatic retention of old metrics, anomalies, alerts, and incidents, plus updates to query keys and monitoring dashboard to reflect data-retention workflows.
2025-11-11 02:21:27 +00:00
gpt-engineer-app[bot]
07fdfe34f3 Fix function search paths
Adjust migrations to set search_path = public for functions to resolve security warnings and ensure proper function execution context.
2025-11-11 02:13:51 +00:00
gpt-engineer-app[bot]
e2b0368a62 Set up auto metric collection
Add Django Celery tasks and utilities to periodically collect system metrics (error rates, response times, queue sizes) and record them into metric_time_series. Include monitoring app scaffolding, metrics collector, Celery beat schedule, middleware for live metrics, and a Supabase edge function for cross-source metrics.
2025-11-11 02:09:55 +00:00
gpt-engineer-app[bot]
be94b4252c Implement ML Anomaly Detection
Introduce statistical anomaly detection for metrics via edge function, hooks, and UI components. Adds detection algorithms (z-score, moving average, rate of change), anomaly storage, auto-alerts, and dashboard rendering of detected anomalies with run-once trigger and scheduling guidance.
2025-11-11 02:07:49 +00:00
gpt-engineer-app[bot]
7fba819fc7 Implement alert correlation UI
- Add hooks and components for correlated alerts and incidents
- Integrate panels into MonitoringOverview
- Extend query keys for correlation and incidents
- Implement incident actions (create, acknowledge, resolve) and wiring
2025-11-11 02:03:20 +00:00
gpt-engineer-app[bot]
5a8caa51b6 Fix search_path on functions
The migration succeeded but security warnings require updating functions to set search_path. Add SET search_path to the three created functions to ensure proper schema resolution and security context.
2025-11-11 01:58:56 +00:00
gpt-engineer-app[bot]
01aba7df90 Connect to Lovable Cloud
Fix security definer view issue by enabling security_invoker on grouped_alerts_view and implement grouped alerts system with new keys, hooks, components, and monitoring overview integration. Added migration to adjust view, updated query keys, created useGroupedAlerts, useAlertGroupActions, GroupedAlertsPanel, and updated MonitoringOverview to include grouped alerts.
2025-11-11 01:51:42 +00:00
gpt-engineer-app[bot]
97f586232f Enable grouped alert view with security considerations
Update: implement grouped_alerts_view migration and address security definer concerns by noting default SECURITY INVOKER behavior for views and ensuring RLS policies on underlying tables apply. This commit covers the view creation and related security clarifications for alert grouping feature.
2025-11-11 01:49:27 +00:00
gpt-engineer-app[bot]
d94062a937 Connect to Lovable Cloud
The migration completed successfully to enable moderation actions:
- Added SELECT, INSERT, and UPDATE RLS policies for system_alerts
- Grants issued to authenticated users
- Enables viewing, creating, and resolving Pipeline Health alerts via UI
- Resolves the previous issue where Resolve did nothing by lacking permissions
2025-11-11 01:26:06 +00:00
gpt-engineer-app[bot]
5d35fdc326 Enable alert resolution policy
Allow moderators to resolve rate limit alerts by adding UPDATE policy on rate_limit_alerts and granting UPDATE to authenticated users. This completes enabling the Resolve action for alerts.
2025-11-11 01:12:56 +00:00
gpt-engineer-app[bot]
28fa2fd0d4 Monitor rate limits progress
Implement monitor-rate-limits edge function to compare metrics against alert configurations, trigger notifications, and record alerts; update config and groundwork for admin UI integration.
2025-11-11 00:19:13 +00:00
gpt-engineer-app[bot]
677d0980dd Connect to Lovable Cloud
Approved Lovable tool use and migration updates to fix security warning and add monitoring edge function. Prepare and apply migrations to ensure search_path is set to public and implement monitoring endpoint for rate limit metrics.
2025-11-11 00:14:48 +00:00
gpt-engineer-app[bot]
f15190351d Create rate-limit-metrics edge function
Add an edge function rate-limit-metrics to expose metrics via API, including authentication guards, CORS headers, and multiple query endpoints for recent metrics, stats, and function/user/IP-specific data. Integrates with new metrics and auth helpers and uses existing rate limiter.
2025-11-11 00:02:55 +00:00
gpt-engineer-app[bot]
fa444091db Integrate metrics and auth
Add Phase 2 updates to rateLimiter.ts:
- Import and hook in rateLimitMetrics and authHelpers
- Track per-request metrics on allowed/blocked outcomes
- Extract userId and clientIP for metrics
- Extend RateLimiter to pass functionName for metrics context
- Update withRateLimit to utilize new metadata and return values
2025-11-11 00:01:13 +00:00
gpt-engineer-app[bot]
bea3031767 Create rateLimitMetrics and authHelpers
Implement Phase 1 by adding:

- supabase/functions/_shared/rateLimitMetrics.ts: in-memory rate limit metrics utilities (record, query, stats, clear, and helpers)
- supabase/functions/_shared/authHelpers.ts: auth helpers for extracting userId, client IP, and rate-limit keys (code scaffolding)
2025-11-10 23:57:35 +00:00
gpt-engineer-app[bot]
6da29e95a4 Add rate limiting to high-risk
Introduce centralized rate limiting by applying defined tiers (STRICT, STANDARD, LENIENT, MODERATE) to high-risk edge functions:
- export-user-data (STRICT, 5 req/min)
- send-contact-message (STANDARD, 20 req/min)
- validate-email-backend (LENIENT, 30 req/min)
- admin-delete-user, resend-deletion-code (MODERATE)
- additional standard targets identified (request-account-deletion, cancel-account-deletion) as per guidance

Implements:
- Wrapped handlers with withRateLimit using centralized rateLimiters
- Imported from shared rate limiter module
- Annotated with comments explaining tier rationale
- Updated three initial functions and extended coverage to admin/account management functions
- Added documentation guide for rate limiting usage

This aligns with the Rate Limiting Guide and centralizes rate limit configuration for consistency.
2025-11-10 21:39:37 +00:00
gpt-engineer-app[bot]
ed6ddbd04b Centralize rate limiting config
Create shared rateLimitConfig.ts with tiers (strict, moderate, lenient, generous, per-user variants) and update edge functions to import centralized rate limiters. Replace inline rate limiter usage with new config, preserving backward compatibility. Add documentation guide for rate limiting usage.
2025-11-10 21:33:08 +00:00
gpt-engineer-app[bot]
bf3da6414a Centralize CORS configuration
Consolidate CORS handling by introducing a shared supabase/functions/_shared/cors.ts and migrate edge functions to import from it. Remove inline cors.ts usage across functions, standardize headers (including traceparent and x-request-id), and prepare for environment-aware origins.
2025-11-10 21:28:46 +00:00
gpt-engineer-app[bot]
7cbd09b2ad Add missing CORS headers
Updated edge functions to include traceparent and x-request-id in Access-Control-Allow-Headers for:
- supabase/functions/process-selective-approval/cors.ts
- supabase/functions/process-selective-rejection/cors.ts

This fixes CORS preflight and allows POST requests to reach edge functions.
2025-11-10 21:22:30 +00:00
gpt-engineer-app[bot]
dc12ccbc0d Enable JWT for rejection function
Update supabase/config.toml to set verify_jwt = true for process-selective-rejection, aligning platform authentication with function usage and allowing POST requests to reach the edge function.
2025-11-10 21:09:37 +00:00
gpt-engineer-app[bot]
1b765a636c Enable JWT verification for process-selective-approval
Update supabase/config.toml to set verify_jwt = true for the process-selective-approval function, aligning platform authentication with the function’s requirements and allowing authenticated POST requests to reach the edge function.
2025-11-10 20:56:18 +00:00
gpt-engineer-app[bot]
f9e6c28d06 Add defensive logging to edge function
Enhance process-selective-approval with startup env var validation, request-level logging, and improved error handling to diagnose edge function failures. Includes checks for SUPABASE_ANON_KEY, startup init log, per-request logs, and robust catch-block logging.
2025-11-10 20:22:25 +00:00
gpt-engineer-app[bot]
95c352af48 Connect to Lovable Cloud
Approve and apply migration to fix RPC for park location data
- Update TypeScript types to remove temp_location_data
- Create migration to fix create_submission_with_items by using relational park_submission_locations
- Ensure _temp_location is extracted and stored properly
2025-11-10 20:13:27 +00:00
gpt-engineer-app[bot]
496ff48e34 Connect to Lovable Cloud
Implemented end-to-end fixes:
- Added INSERT RLS policies for park_submissions, ride_submissions, company_submissions, ride_model_submissions, and photo_submissions (own submissions and moderator access)
- Fixed process_approval_transaction to replace ride_type with category and updated references accordingly
- Enhanced rate limiting in testRunner.ts with a 6s base delay and 12s adaptive delays after submission-heavy suites
2025-11-10 18:34:14 +00:00
gpt-engineer-app[bot]
c5d40d07df Connect to Lovable Cloud
Apply quick wins and pipeline fixes for integration tests:
- Remove is_test_data flag from location inserts
- Increase test delay from 2.5s to 5s and add delays between suites to curb rate limiting
- Replace [object Object] error formatting with formatTestError across 10 test suites (31 edits) and add import
- Refactor unit/conversion tests and performance tests to use the approval pipeline
- Extend edge function handling by ensuring item_ids are included in idempotency key inserts (edge function fix)
- Update auth, data integrity, edgeFunction, moderation, performance, submission, unitConversion, and versioning test files accordingly
2025-11-10 18:20:22 +00:00
gpt-engineer-app[bot]
2d65f13b85 Connect to Lovable Cloud
Add centralized errorFormatter to convert various error types into readable messages, and apply it across edge functions. Replace String(error) usage with formatEdgeError, update relevant imports, fix a throw to use toError, and enhance logger to log formatted errors. Includes new errorFormatter.ts and widespread updates to 18+ edge functions plus logger integration.
2025-11-10 18:09:15 +00:00
pacnpal
095cd412be Restore approval pipeline with tracing functionality
This migration restores the complete approval pipeline functionality by recreating the process_approval_transaction function and ensuring all entity types are handled correctly.
2025-11-10 10:15:24 -05:00
pacnpal
9a1ecb0663 Merge branch 'dev' into main 2025-11-10 10:10:37 -05:00
pacnpal
00de87924c Restore approval pipeline with tracing functionality
This migration restores the complete approval pipeline functionality by recreating the 'process_approval_transaction' function, which handles the approval process for various entity types. It also includes tracing capabilities for monitoring the approval process.
2025-11-10 10:08:07 -05:00
gpt-engineer-app[bot]
236e412d7c Connect to Lovable Cloud 2025-11-10 14:55:58 +00:00
gpt-engineer-app[bot]
89338a06ea Connect to Lovable Cloud
Integrate Lovable Cloud tracing updates by enabling distributed tracing in edge functions, adjusting breadcrumb/trace propagation, and preparing RPC span handling. Files touched include edgeFunctionTracking and related RPC tracing scaffolding.
2025-11-10 14:42:39 +00:00
gpt-engineer-app[bot]
96adb2b15e Connect to Lovable Cloud
Implement distributed tracing across edge functions:
- Introduce span types and utilities (logger.ts enhancements)
- Replace request tracking with span-based tracing in approval and rejection flows
- Propagate and manage W3C trace context in edge tracking
- Add span visualization scaffolding (spanVisualizer.ts) and admin TraceViewer UI (TraceViewer.tsx)
- Create tracing-related type definitions and support files
- Prepare RPC call logging with span context and retries
2025-11-10 14:40:44 +00:00
gpt-engineer-app[bot]
1551a2f08d Add structured moderation logging
Enhance edge functions process-selective-approval and process-selective-rejection with edgeLogger-based, structured logging. Introduce request tracking (startRequest/endRequest), replace all console logs, add comprehensive logging points (auth, payload validation, idempotency, RPC calls, deadlocks, errors, locks), and register process-selective-rejection in config.toml. Also sanitize sensitive data in logs and ensure duration metrics are captured.
2025-11-10 14:32:37 +00:00
gpt-engineer-app[bot]
c7bdff313a Move photo logic to RPC path
Refactor: remove duplicate photo handling from useModerationActions.ts and ensure all photo approvals flow through the atomic process_approval_transaction path. This includes deleting the direct DB update block for photos and relying on the unified approval flow through the edge function. Also note required npm install for package-lock.json.
2025-11-10 14:01:34 +00:00
gpt-engineer-app[bot]
d5974440a5 Remove temp_location_data reference from create_submission_with_items
Fix critical migration bug by dropping and recreating create_submission_with_items to stop referencing deleted temp_location_data; ensure location data uses park_submission_locations table. Notify manually update package-lock.json.
2025-11-10 13:54:30 +00:00
gpt-engineer-app[bot]
6c03a5b0e7 Implement rejection bulletproofing
Created atomic rejection edge function process-selective-rejection and RPC, updated moderation client to use it, and ensured resilience; added CORS wrapper. Reminder: generate package-lock.json by running npm install.
2025-11-10 13:26:13 +00:00