link,[object Object]
Skip to content

Edge Functions Quick Sheet ​

Purpose: Quick reference for common Supabase Edge Functions used by the app. Audience: Developer, AI Agent Prerequisites: Supabase CLI, linked project, Vite proxy configured.

Conventions

  • Invoke from frontend: await supabase.functions.invoke('<name>', { body })
  • Local dev: /functions/v1/<name> is proxied to Supabase (vite.config.ts:12-17)

Notifications & Email

  • send-email
    • Input (body): to, subject, html, text?, emailType, templateName?, metadata?
      • Code: src/lib/emailService.ts:14-21
    • Output: JSON status; check { error } for failures
  • send-admin-listing-notification
    • Input (body):
      • Code: src/hooks/useAdminPollingNotifications.ts:67-69
    • Output: none (fire-and-forget pattern)
  • send-admin-contact-notification
    • Input: { to, subject, html/text } (confirm in function index.ts)
    • Output: status (TODO confirm)
  • send-notification
    • Purpose: enqueue in-app notifications
    • Input:
    • Output:
    • Code: src/components/admin/templates/TimelineMessageEditor.tsx (test functionality)
  • send-payment-email
    • Purpose: payment confirmations
    • Input/Output: TODO confirm in function index.ts
  • send-auth-email
    • Purpose: auth magic/reset/confirm flows
    • Input: { to, type, token, redirectTo } (typical); confirm in function index.ts
  • send-listing-approval-notification, send-listing-notifications, send-new-user-notification, send-sponsored-notifications
    • Purpose: specialized template sends
    • Input/Output: see function body; often

AI & Analysis

  • analyze-project
    • Purpose: AI-powered project analysis using Mistral AI
    • Input:
    • Output: Structured project analysis JSON
    • Features:
      • JWT authentication required
      • Mistral AI integration (small/large models)
      • Robust JSON parsing with 5-strategy recovery
      • Financial defaults generation
      • Rate limit handling (429 errors)
      • 60-second timeout with AbortController
    • Code: src/components/create-listing/N8NAIProjectAnalyzer.tsx
    • Backend: supabase/functions/analyze-project/index.ts

Timeline Event Management (NEW)

  • dispatch-timeline-event
    • Purpose: Generic dispatcher for deal timeline events
    • Input:
    • Output:
    • Features: Role-based notifications, multilingual support, toggle validation
  • seller-deliver-assets
    • Purpose: Replaces old RPC for asset delivery
    • Input:
    • Output:
    • Features: Triggers timeline event, sends notifications

Daily tasks & schedulers

  • run-daily-tasks
    • Purpose: orchestrates scheduled jobs (invokes sub-functions)
    • Input: may accept { force, slot } from pg_cron; confirm in index.ts
  • run-price-alerts
    • Purpose: process price_alerts, produce price_alert_events
    • Input: none; scheduled; may accept slot
    • Output: summary stats (typical)
  • update-views-count
    • Purpose: increment listing views
    • Input: likely { listingId } (confirm in index.ts)
  • cleanup-duplicates
    • Purpose: maintenance
    • Input/Output: N/A, confirm in index.ts
  • process-sponsored-activations
    • Purpose: activate sponsored listings and notify
    • Input/Output: confirm in index.ts

Stripe Connect & KYC

  • connect-onboarding-link
    • Purpose: create onboarding link
    • Output:
    • Code: src/pages/SellerVerification.tsx:59-63
  • connect-dashboard-link
    • Purpose: link to Stripe dashboard
    • Output:
    • Code: src/pages/SellerVerification.tsx:88-91
  • refresh-kyc-status
    • Purpose: fetch latest KYC/requirements
    • Output: { summary: { currently_due_count, past_due_count, disabled_reason?, payouts_enabled? } }
    • Code: src/pages/SellerVerification.tsx:105-113

Billing & Subscriptions

  • get-price-id
    • Input:
    • Output:
    • Code: src/hooks/useStripeCheckout.ts:31-46
  • create-checkout
    • Input:
    • Output:
    • Guard (new): if there is an ACTIVE subscription for the customer, no checkout is created; returns a Billing Portal session (reason=already_active).
    • Code: src/hooks/useStripeCheckout.ts:48-67, supabase/functions/create-checkout/index.ts:127-151
  • customer-portal
    • Output:
    • Code: src/hooks/useCustomerPortal.ts:27-40
  • check-subscription, daily-subscription-sync, stripe-sync, sync-invoices, set-starter-subscriptions
    • Purpose: sync current subscription state/invoices and automated fixes
    • sync-invoices (new): sets created_at using priority status_transitions.paid_at, then finalized_at, then created for correct dates in UI
    • Input/Output: see each function

Deal payments

  • create-deal-payment
    • Input:
    • Output:
    • Code: src/components/deal/tabs/FinancingTab.tsx:116-123
  • release-deal-payout
    • Input:
    • Output:
    • Purpose: Release payout to seller and auto-finalize deal
    • Code: src/pages/admin/AdminTransactions.tsx:237-243
    • Features:
      • Idempotency check for existing Stripe transfers
      • Commission calculation (net amount = total - commission)
      • Stripe transfer creation with correct metadata
    • Auto-triggers: finalize-deal function after successful payout
  • get-stripe-transfer-details
    • Input:
    • Output:
    • Purpose: Fetch real-time Stripe transfer information
    • Features:
      • Status determination: "reversed", "paid", or "pending"
      • Correct net amount calculation (amount - commission)
      • Secure server-side Stripe API access
  • finalize-deal

External Escrow (Verified by AcqMarketplace)

  • set-deal-provider
    • Input:
    • Output: success/error status
    • Purpose: Buyer selects payment provider (stripe/escrow)
    • Code: supabase/functions/set-deal-provider/index.ts
  • submit-external-escrow-details
    • Input:
    • Output: success/error status
    • Purpose: Submit external escrow provider details
    • Code: supabase/functions/submit-external-escrow-details/index.ts
  • admin-verify-docs
    • Input:
    • Output: success/error status
    • Purpose: Admin verifies external escrow documents
    • Code: supabase/functions/admin-verify-docs/index.ts
  • mark-external-funded
    • Input:
    • Output: success/error status
    • Purpose: Admin confirms external funds are deposited
    • Code: supabase/functions/mark-external-funded/index.ts
  • buyer-confirm-receipt
    • Input:
    • Output: success/error status
    • Purpose: Buyer confirms receipt of assets
    • Code: supabase/functions/buyer-confirm-receipt/index.ts
  • admin-finalize-external-release
    • Input:
    • Output: success/error status
    • Purpose: Admin finalizes external escrow release
    • Code: supabase/functions/admin-finalize-external-release/index.ts
    • Input:
    • Output:
    • Purpose: Mark deal as completed and send notifications
    • Requirements: Deal must be in payout_released status
    • Actions: Updates status to completed, logs event, sends notifications
  • refund-deal-payment
    • Input:
    • Code: src/pages/admin/AdminTransactions.tsx:255-261
  • payment-status
    • Purpose: verify payment status after redirect
    • Input/Output: see function

Documents & APA

  • deal-create-upload-url
    • Purpose: presigned storage URL for deal docs
    • Input/Output: see function
  • generate-apa-pdf
    • Purpose: generate APA PDF
    • Input/Output: see function

Notes

  • Where inputs/outputs are marked TODO, confirm in the function index.ts before relying on a contract.
  • Enforce role checks (admin-only, seller-only) in functions.

Related

  • See docs/architecture/apis.md for invocation patterns and webhook flows.