[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M71GHAXEWVY5FHT30X0PKMZ3":3,"skill-same:01M71GHAXEWVY5FHT30X0PKMZ3":56},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":30,"linkOnly":31,"markdownContent":32,"markdownBody":33,"frontMatter":34,"refName":35,"commitSha":36,"skillDirectory":37,"forksCount":38,"repositoryHtmlUrl":39,"repositoryHomepageUrl":6,"ownerHtmlUrl":40,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":41,"install":42,"resources":55},"01M71GHAXEWVY5FHT30X0PKMZ3","supabase-edge-functions",null,"Deploy and manage Supabase Edge Functions. Use for invoking serverless functions, deploying new functions, and managing function deployments.","JSGforever\u002Fskillguard","JSGforever","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F85541948?v=4","01M71FQD3E132VMR5F4TAYX3YS","01M71FQD4DYW0XJ4XQ4YQH75Y9",2,"GPL-3.0","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__Nice-Wolf-Studio--supabase-edge-functions\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29],"supabase","edge functions","supabase edge functions","edge","functions","new","for","manage","deployments","use","deploy","serverless","2026-11-10 10:12:30",false,"---\nname: supabase-edge-functions\ndescription: Deploy and manage Supabase Edge Functions. Use for invoking serverless functions, deploying new functions, and managing function deployments.\n---\n\n# Supabase Edge Functions\n\n## Overview\n\nThis skill provides operations for working with Supabase Edge Functions - serverless TypeScript\u002FJavaScript functions that run on Deno Deploy. Use for invoking functions, deploying code, and managing function lifecycles.\n\n## Prerequisites\n\n**Required environment variables:**\n```bash\nexport SUPABASE_URL=\"https:\u002F\u002Fyour-project.supabase.co\"\nexport SUPABASE_KEY=\"your-anon-or-service-role-key\"\n```\n\n**Required tools:**\n- Supabase CLI (`supabase` command)\n- Deno (for local development)\n\n**Install Supabase CLI:**\n```bash\n# macOS\nbrew install supabase\u002Ftap\u002Fsupabase\n\n# Linux\ncurl -fsSL https:\u002F\u002Fgithub.com\u002Fsupabase\u002Fcli\u002Freleases\u002Flatest\u002Fdownload\u002Fsupabase_linux_amd64.tar.gz | tar -xz\nsudo mv supabase \u002Fusr\u002Flocal\u002Fbin\u002F\n\n# Windows (PowerShell)\nscoop bucket add supabase https:\u002F\u002Fgithub.com\u002Fsupabase\u002Fscoop-bucket.git\nscoop install supabase\n```\n\n**Helper script:**\nThis skill uses the shared Supabase API helper for invoking functions:\n```bash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n```\n\n## Invoke Edge Functions\n\n### Basic Invocation\n\n**Invoke a function with POST:**\n```bash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"hello-world\"\n\nsupabase_post \"\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" '{\n  \"name\": \"Alice\"\n}'\n```\n\n**Invoke with GET:**\n```bash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"get-data\"\n\nsupabase_get \"\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}?id=123\"\n```\n\n### Invoke with Headers\n\n**Pass custom headers:**\n```bash\nFUNCTION_NAME=\"authenticated-function\"\nUSER_TOKEN=\"user-access-token\"\n\ncurl -s -X POST \\\n    \"${SUPABASE_URL}\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" \\\n    -H \"apikey: ${SUPABASE_KEY}\" \\\n    -H \"Authorization: Bearer ${USER_TOKEN}\" \\\n    -H \"Content-Type: application\u002Fjson\" \\\n    -d '{\"action\": \"process\"}'\n```\n\n### Invoke with Authentication\n\n**Invoke function as authenticated user:**\n```bash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"user-profile\"\nACCESS_TOKEN=\"user-jwt-token\"\n\ncurl -s -X POST \\\n    \"${SUPABASE_URL}\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" \\\n    -H \"apikey: ${SUPABASE_KEY}\" \\\n    -H \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n    -H \"Content-Type: application\u002Fjson\" \\\n    -d '{}'\n```\n\n## Function Management (CLI)\n\n### Initialize Function\n\n**Create a new edge function:**\n```bash\n# Navigate to your Supabase project directory\ncd \u002Fpath\u002Fto\u002Fproject\n\n# Create new function\nsupabase functions new my-function\n\n# This creates: supabase\u002Ffunctions\u002Fmy-function\u002Findex.ts\n```\n\n### Function Template\n\n**Basic function structure:**\n```typescript\n\u002F\u002F supabase\u002Ffunctions\u002Fmy-function\u002Findex.ts\n\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\n\nserve(async (req) => {\n  const { name } = await req.json()\n\n  const data = {\n    message: `Hello ${name}!`,\n  }\n\n  return new Response(\n    JSON.stringify(data),\n    { headers: { \"Content-Type\": \"application\u002Fjson\" } },\n  )\n})\n```\n\n**Function with authentication:**\n```typescript\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\nimport { createClient } from 'https:\u002F\u002Fesm.sh\u002F@supabase\u002Fsupabase-js@2'\n\nserve(async (req) => {\n  \u002F\u002F Get JWT from Authorization header\n  const authHeader = req.headers.get('Authorization')!\n  const token = authHeader.replace('Bearer ', '')\n\n  \u002F\u002F Create Supabase client with user's token\n  const supabase = createClient(\n    Deno.env.get('SUPABASE_URL') ?? '',\n    Deno.env.get('SUPABASE_ANON_KEY') ?? '',\n    { global: { headers: { Authorization: authHeader } } }\n  )\n\n  \u002F\u002F Get authenticated user\n  const { data: { user }, error } = await supabase.auth.getUser(token)\n\n  if (error || !user) {\n    return new Response('Unauthorized', { status: 401 })\n  }\n\n  return new Response(\n    JSON.stringify({ message: `Hello ${user.email}!` }),\n    { headers: { \"Content-Type\": \"application\u002Fjson\" } },\n  )\n})\n```\n\n### Deploy Function\n\n**Deploy a function to Supabase:**\n```bash\n# Login to Supabase (first time only)\nsupabase login\n\n# Link to your project (first time only)\nsupabase link --project-ref your-project-ref\n\n# Deploy specific function\nsupabase functions deploy my-function\n\n# Deploy with custom environment variables\nsupabase functions deploy my-function \\\n  --env-file .\u002Fsupabase\u002F.env.local\n\n# Deploy all functions\nsupabase functions deploy\n```\n\n### Set Environment Variables\n\n**Set secrets for edge functions:**\n```bash\n# Set individual secret\nsupabase secrets set MY_SECRET_KEY=value123\n\n# Set multiple secrets from file\n# Create .env file:\n# API_KEY=abc123\n# DATABASE_URL=postgres:\u002F\u002F...\n\nsupabase secrets set --env-file .env\n\n# List secrets (names only, not values)\nsupabase secrets list\n\n# Unset secret\nsupabase secrets unset MY_SECRET_KEY\n```\n\n### Local Development\n\n**Run functions locally:**\n```bash\n# Start local Supabase (includes edge functions)\nsupabase start\n\n# Serve functions locally\nsupabase functions serve\n\n# Serve specific function\nsupabase functions serve my-function --env-file .\u002Fsupabase\u002F.env.local\n\n# Invoke local function\ncurl http:\u002F\u002Flocalhost:54321\u002Ffunctions\u002Fv1\u002Fmy-function \\\n  -H \"Authorization: Bearer ${SUPABASE_KEY}\" \\\n  -d '{\"name\": \"test\"}'\n```\n\n### Delete Function\n\n**Remove a deployed function:**\n```bash\n# Delete function from Supabase dashboard or using SQL\n# Note: No direct CLI command to delete, must use dashboard\n\n# Remove local function file\nrm -rf supabase\u002Ffunctions\u002Fmy-function\n```\n\n## Common Patterns\n\n### Invoke and Process Response\n\n```bash\n#!\u002Fbin\u002Fbash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"process-data\"\n\nresponse=$(supabase_post \"\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" '{\n  \"action\": \"calculate\",\n  \"values\": [1, 2, 3, 4, 5]\n}')\n\nif [[ $? -eq 0 ]]; then\n    result=$(echo \"$response\" | jq -r '.result')\n    echo \"Function result: $result\"\nelse\n    echo \"Function invocation failed\"\n    exit 1\nfi\n```\n\n### Batch Function Invocations\n\n```bash\n#!\u002Fbin\u002Fbash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"send-email\"\nRECIPIENTS=(\"alice@example.com\" \"bob@example.com\" \"charlie@example.com\")\n\nfor email in \"${RECIPIENTS[@]}\"; do\n    echo \"Processing $email...\"\n\n    supabase_post \"\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" '{\n      \"to\": \"'\"$email\"'\",\n      \"subject\": \"Hello\",\n      \"body\": \"Test message\"\n    }'\n\n    echo \"✓ Sent to $email\"\ndone\n```\n\n### Function with Retry Logic\n\n```bash\n#!\u002Fbin\u002Fbash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\ninvoke_with_retry() {\n    local function_name=\"$1\"\n    local payload=\"$2\"\n    local max_retries=3\n    local retry_count=0\n\n    while [[ $retry_count -lt $max_retries ]]; do\n        if response=$(supabase_post \"\u002Ffunctions\u002Fv1\u002F${function_name}\" \"$payload\" 2>&1); then\n            echo \"$response\"\n            return 0\n        else\n            retry_count=$((retry_count + 1))\n            echo \"Retry $retry_count\u002F$max_retries...\" >&2\n            sleep 2\n        fi\n    done\n\n    echo \"Function failed after $max_retries retries\" >&2\n    return 1\n}\n\n# Use it\ninvoke_with_retry \"my-function\" '{\"action\": \"process\"}'\n```\n\n### Deploy Function Script\n\n```bash\n#!\u002Fbin\u002Fbash\n# deploy-function.sh\n\nFUNCTION_NAME=\"${1:-my-function}\"\n\necho \"Deploying function: $FUNCTION_NAME\"\n\n# Validate function exists\nif [[ ! -d \"supabase\u002Ffunctions\u002F$FUNCTION_NAME\" ]]; then\n    echo \"Error: Function $FUNCTION_NAME not found\"\n    exit 1\nfi\n\n# Deploy\nif supabase functions deploy \"$FUNCTION_NAME\"; then\n    echo \"✓ Deployed successfully\"\n\n    # Test invocation\n    echo \"Testing function...\"\n    response=$(curl -s -X POST \\\n        \"${SUPABASE_URL}\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" \\\n        -H \"apikey: ${SUPABASE_KEY}\" \\\n        -H \"Content-Type: application\u002Fjson\" \\\n        -d '{}')\n\n    echo \"Test response: $response\"\nelse\n    echo \"✗ Deployment failed\"\n    exit 1\nfi\n```\n\n### Monitor Function Logs\n\n```bash\n# View function logs (requires Supabase CLI)\nsupabase functions logs my-function\n\n# Follow logs in real-time\nsupabase functions logs my-function --follow\n\n# Filter logs by level\nsupabase functions logs my-function --level error\n\n# View logs from specific time\nsupabase functions logs my-function --since 1h\n```\n\n## Advanced Patterns\n\n### Function with Database Access\n\n```typescript\n\u002F\u002F supabase\u002Ffunctions\u002Fget-user-data\u002Findex.ts\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\nimport { createClient } from 'https:\u002F\u002Fesm.sh\u002F@supabase\u002Fsupabase-js@2'\n\nserve(async (req) => {\n  const supabase = createClient(\n    Deno.env.get('SUPABASE_URL') ?? '',\n    Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''\n  )\n\n  const { userId } = await req.json()\n\n  const { data, error } = await supabase\n    .from('users')\n    .select('*')\n    .eq('id', userId)\n    .single()\n\n  if (error) {\n    return new Response(JSON.stringify({ error: error.message }), {\n      status: 400,\n      headers: { 'Content-Type': 'application\u002Fjson' }\n    })\n  }\n\n  return new Response(JSON.stringify(data), {\n    headers: { 'Content-Type': 'application\u002Fjson' }\n  })\n})\n```\n\n### Function with External API Call\n\n```typescript\n\u002F\u002F supabase\u002Ffunctions\u002Ffetch-weather\u002Findex.ts\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\n\nserve(async (req) => {\n  const { city } = await req.json()\n  const apiKey = Deno.env.get('WEATHER_API_KEY')\n\n  const response = await fetch(\n    `https:\u002F\u002Fapi.openweathermap.org\u002Fdata\u002F2.5\u002Fweather?q=${city}&appid=${apiKey}`\n  )\n\n  const data = await response.json()\n\n  return new Response(JSON.stringify(data), {\n    headers: { 'Content-Type': 'application\u002Fjson' }\n  })\n})\n```\n\n### Scheduled Function (Cron)\n\n```typescript\n\u002F\u002F supabase\u002Ffunctions\u002Fdaily-cleanup\u002Findex.ts\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\nimport { createClient } from 'https:\u002F\u002Fesm.sh\u002F@supabase\u002Fsupabase-js@2'\n\nserve(async (req) => {\n  \u002F\u002F Verify request is from Supabase Cron\n  const authHeader = req.headers.get('Authorization')\n  if (authHeader !== `Bearer ${Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')}`) {\n    return new Response('Unauthorized', { status: 401 })\n  }\n\n  const supabase = createClient(\n    Deno.env.get('SUPABASE_URL') ?? '',\n    Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''\n  )\n\n  \u002F\u002F Delete old records\n  const { data, error } = await supabase\n    .from('logs')\n    .delete()\n    .lt('created_at', new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString())\n\n  return new Response(JSON.stringify({ deleted: data?.length ?? 0 }), {\n    headers: { 'Content-Type': 'application\u002Fjson' }\n  })\n})\n```\n\n**Set up cron job in Supabase Dashboard:**\n```sql\n-- In SQL Editor, create pg_cron job:\nselect cron.schedule(\n  'daily-cleanup',\n  '0 2 * * *', -- Run at 2 AM daily\n  $$\n  select\n    net.http_post(\n      url := 'https:\u002F\u002Fyour-project.supabase.co\u002Ffunctions\u002Fv1\u002Fdaily-cleanup',\n      headers := '{\"Content-Type\": \"application\u002Fjson\", \"Authorization\": \"Bearer YOUR_SERVICE_ROLE_KEY\"}'::jsonb,\n      body := '{}'::jsonb\n    ) as request_id;\n  $$\n);\n```\n\n## Testing Functions\n\n### Test Locally\n\n```bash\n# Start local environment\nsupabase start\n\n# Serve function\nsupabase functions serve my-function\n\n# Test with curl\ncurl http:\u002F\u002Flocalhost:54321\u002Ffunctions\u002Fv1\u002Fmy-function \\\n  -H \"Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\" \\\n  -d '{\"test\": \"data\"}'\n```\n\n### Integration Test Script\n\n```bash\n#!\u002Fbin\u002Fbash\n# test-function.sh\n\nFUNCTION_NAME=\"$1\"\nTEST_CASES_FILE=\"$2\"\n\nif [[ ! -f \"$TEST_CASES_FILE\" ]]; then\n    echo \"Test cases file not found\"\n    exit 1\nfi\n\necho \"Testing function: $FUNCTION_NAME\"\n\nwhile IFS= read -r test_case; do\n    echo \"Test case: $test_case\"\n\n    response=$(curl -s -X POST \\\n        \"${SUPABASE_URL}\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" \\\n        -H \"apikey: ${SUPABASE_KEY}\" \\\n        -H \"Content-Type: application\u002Fjson\" \\\n        -d \"$test_case\")\n\n    echo \"Response: $response\"\n    echo \"---\"\ndone \u003C \"$TEST_CASES_FILE\"\n```\n\n## Error Handling\n\n**Function errors return HTTP status codes:**\n\n| Status | Meaning |\n|--------|---------|\n| 200 | Success |\n| 400 | Bad request (invalid input) |\n| 401 | Unauthorized (invalid\u002Fmissing auth) |\n| 403 | Forbidden (insufficient permissions) |\n| 500 | Internal server error (function crashed) |\n| 504 | Gateway timeout (function took too long) |\n\n**Timeout limit:** Edge functions have a 2-second CPU time limit and 150-second wall clock timeout.\n\n## Security Best Practices\n\n1. **Validate input**: Always validate and sanitize request data\n2. **Use service role key carefully**: Only in admin functions, never expose to clients\n3. **Implement authentication**: Check user tokens for protected functions\n4. **Rate limiting**: Implement rate limiting for public functions\n5. **Environment variables**: Store secrets in Supabase secrets, not in code\n6. **CORS**: Configure CORS headers appropriately\n7. **Error messages**: Don't leak sensitive information in error responses\n\n## Performance Tips\n\n1. **Cold starts**: Functions may have cold starts (100-200ms delay)\n2. **Keep functions small**: Faster cold starts and easier debugging\n3. **Cache external data**: Use in-memory caching for repeated API calls\n4. **Parallel execution**: Use `Promise.all()` for concurrent operations\n5. **Stream large responses**: Use streaming for large data transfers\n\n## API Documentation\n\n- Supabase Edge Functions: https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Ffunctions\n- Deno Deploy: https:\u002F\u002Fdeno.com\u002Fdeploy\u002Fdocs\n","# Supabase Edge Functions\n\n## Overview\n\nThis skill provides operations for working with Supabase Edge Functions - serverless TypeScript\u002FJavaScript functions that run on Deno Deploy. Use for invoking functions, deploying code, and managing function lifecycles.\n\n## Prerequisites\n\n**Required environment variables:**\n```bash\nexport SUPABASE_URL=\"https:\u002F\u002Fyour-project.supabase.co\"\nexport SUPABASE_KEY=\"your-anon-or-service-role-key\"\n```\n\n**Required tools:**\n- Supabase CLI (`supabase` command)\n- Deno (for local development)\n\n**Install Supabase CLI:**\n```bash\n# macOS\nbrew install supabase\u002Ftap\u002Fsupabase\n\n# Linux\ncurl -fsSL https:\u002F\u002Fgithub.com\u002Fsupabase\u002Fcli\u002Freleases\u002Flatest\u002Fdownload\u002Fsupabase_linux_amd64.tar.gz | tar -xz\nsudo mv supabase \u002Fusr\u002Flocal\u002Fbin\u002F\n\n# Windows (PowerShell)\nscoop bucket add supabase https:\u002F\u002Fgithub.com\u002Fsupabase\u002Fscoop-bucket.git\nscoop install supabase\n```\n\n**Helper script:**\nThis skill uses the shared Supabase API helper for invoking functions:\n```bash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n```\n\n## Invoke Edge Functions\n\n### Basic Invocation\n\n**Invoke a function with POST:**\n```bash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"hello-world\"\n\nsupabase_post \"\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" '{\n  \"name\": \"Alice\"\n}'\n```\n\n**Invoke with GET:**\n```bash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"get-data\"\n\nsupabase_get \"\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}?id=123\"\n```\n\n### Invoke with Headers\n\n**Pass custom headers:**\n```bash\nFUNCTION_NAME=\"authenticated-function\"\nUSER_TOKEN=\"user-access-token\"\n\ncurl -s -X POST \\\n    \"${SUPABASE_URL}\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" \\\n    -H \"apikey: ${SUPABASE_KEY}\" \\\n    -H \"Authorization: Bearer ${USER_TOKEN}\" \\\n    -H \"Content-Type: application\u002Fjson\" \\\n    -d '{\"action\": \"process\"}'\n```\n\n### Invoke with Authentication\n\n**Invoke function as authenticated user:**\n```bash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"user-profile\"\nACCESS_TOKEN=\"user-jwt-token\"\n\ncurl -s -X POST \\\n    \"${SUPABASE_URL}\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" \\\n    -H \"apikey: ${SUPABASE_KEY}\" \\\n    -H \"Authorization: Bearer ${ACCESS_TOKEN}\" \\\n    -H \"Content-Type: application\u002Fjson\" \\\n    -d '{}'\n```\n\n## Function Management (CLI)\n\n### Initialize Function\n\n**Create a new edge function:**\n```bash\n# Navigate to your Supabase project directory\ncd \u002Fpath\u002Fto\u002Fproject\n\n# Create new function\nsupabase functions new my-function\n\n# This creates: supabase\u002Ffunctions\u002Fmy-function\u002Findex.ts\n```\n\n### Function Template\n\n**Basic function structure:**\n```typescript\n\u002F\u002F supabase\u002Ffunctions\u002Fmy-function\u002Findex.ts\n\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\n\nserve(async (req) => {\n  const { name } = await req.json()\n\n  const data = {\n    message: `Hello ${name}!`,\n  }\n\n  return new Response(\n    JSON.stringify(data),\n    { headers: { \"Content-Type\": \"application\u002Fjson\" } },\n  )\n})\n```\n\n**Function with authentication:**\n```typescript\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\nimport { createClient } from 'https:\u002F\u002Fesm.sh\u002F@supabase\u002Fsupabase-js@2'\n\nserve(async (req) => {\n  \u002F\u002F Get JWT from Authorization header\n  const authHeader = req.headers.get('Authorization')!\n  const token = authHeader.replace('Bearer ', '')\n\n  \u002F\u002F Create Supabase client with user's token\n  const supabase = createClient(\n    Deno.env.get('SUPABASE_URL') ?? '',\n    Deno.env.get('SUPABASE_ANON_KEY') ?? '',\n    { global: { headers: { Authorization: authHeader } } }\n  )\n\n  \u002F\u002F Get authenticated user\n  const { data: { user }, error } = await supabase.auth.getUser(token)\n\n  if (error || !user) {\n    return new Response('Unauthorized', { status: 401 })\n  }\n\n  return new Response(\n    JSON.stringify({ message: `Hello ${user.email}!` }),\n    { headers: { \"Content-Type\": \"application\u002Fjson\" } },\n  )\n})\n```\n\n### Deploy Function\n\n**Deploy a function to Supabase:**\n```bash\n# Login to Supabase (first time only)\nsupabase login\n\n# Link to your project (first time only)\nsupabase link --project-ref your-project-ref\n\n# Deploy specific function\nsupabase functions deploy my-function\n\n# Deploy with custom environment variables\nsupabase functions deploy my-function \\\n  --env-file .\u002Fsupabase\u002F.env.local\n\n# Deploy all functions\nsupabase functions deploy\n```\n\n### Set Environment Variables\n\n**Set secrets for edge functions:**\n```bash\n# Set individual secret\nsupabase secrets set MY_SECRET_KEY=value123\n\n# Set multiple secrets from file\n# Create .env file:\n# API_KEY=abc123\n# DATABASE_URL=postgres:\u002F\u002F...\n\nsupabase secrets set --env-file .env\n\n# List secrets (names only, not values)\nsupabase secrets list\n\n# Unset secret\nsupabase secrets unset MY_SECRET_KEY\n```\n\n### Local Development\n\n**Run functions locally:**\n```bash\n# Start local Supabase (includes edge functions)\nsupabase start\n\n# Serve functions locally\nsupabase functions serve\n\n# Serve specific function\nsupabase functions serve my-function --env-file .\u002Fsupabase\u002F.env.local\n\n# Invoke local function\ncurl http:\u002F\u002Flocalhost:54321\u002Ffunctions\u002Fv1\u002Fmy-function \\\n  -H \"Authorization: Bearer ${SUPABASE_KEY}\" \\\n  -d '{\"name\": \"test\"}'\n```\n\n### Delete Function\n\n**Remove a deployed function:**\n```bash\n# Delete function from Supabase dashboard or using SQL\n# Note: No direct CLI command to delete, must use dashboard\n\n# Remove local function file\nrm -rf supabase\u002Ffunctions\u002Fmy-function\n```\n\n## Common Patterns\n\n### Invoke and Process Response\n\n```bash\n#!\u002Fbin\u002Fbash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"process-data\"\n\nresponse=$(supabase_post \"\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" '{\n  \"action\": \"calculate\",\n  \"values\": [1, 2, 3, 4, 5]\n}')\n\nif [[ $? -eq 0 ]]; then\n    result=$(echo \"$response\" | jq -r '.result')\n    echo \"Function result: $result\"\nelse\n    echo \"Function invocation failed\"\n    exit 1\nfi\n```\n\n### Batch Function Invocations\n\n```bash\n#!\u002Fbin\u002Fbash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\nFUNCTION_NAME=\"send-email\"\nRECIPIENTS=(\"alice@example.com\" \"bob@example.com\" \"charlie@example.com\")\n\nfor email in \"${RECIPIENTS[@]}\"; do\n    echo \"Processing $email...\"\n\n    supabase_post \"\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" '{\n      \"to\": \"'\"$email\"'\",\n      \"subject\": \"Hello\",\n      \"body\": \"Test message\"\n    }'\n\n    echo \"✓ Sent to $email\"\ndone\n```\n\n### Function with Retry Logic\n\n```bash\n#!\u002Fbin\u002Fbash\nsource \"$(dirname \"${BASH_SOURCE[0]}\")\u002F..\u002F..\u002Fscripts\u002Fsupabase-api.sh\"\n\ninvoke_with_retry() {\n    local function_name=\"$1\"\n    local payload=\"$2\"\n    local max_retries=3\n    local retry_count=0\n\n    while [[ $retry_count -lt $max_retries ]]; do\n        if response=$(supabase_post \"\u002Ffunctions\u002Fv1\u002F${function_name}\" \"$payload\" 2>&1); then\n            echo \"$response\"\n            return 0\n        else\n            retry_count=$((retry_count + 1))\n            echo \"Retry $retry_count\u002F$max_retries...\" >&2\n            sleep 2\n        fi\n    done\n\n    echo \"Function failed after $max_retries retries\" >&2\n    return 1\n}\n\n# Use it\ninvoke_with_retry \"my-function\" '{\"action\": \"process\"}'\n```\n\n### Deploy Function Script\n\n```bash\n#!\u002Fbin\u002Fbash\n# deploy-function.sh\n\nFUNCTION_NAME=\"${1:-my-function}\"\n\necho \"Deploying function: $FUNCTION_NAME\"\n\n# Validate function exists\nif [[ ! -d \"supabase\u002Ffunctions\u002F$FUNCTION_NAME\" ]]; then\n    echo \"Error: Function $FUNCTION_NAME not found\"\n    exit 1\nfi\n\n# Deploy\nif supabase functions deploy \"$FUNCTION_NAME\"; then\n    echo \"✓ Deployed successfully\"\n\n    # Test invocation\n    echo \"Testing function...\"\n    response=$(curl -s -X POST \\\n        \"${SUPABASE_URL}\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" \\\n        -H \"apikey: ${SUPABASE_KEY}\" \\\n        -H \"Content-Type: application\u002Fjson\" \\\n        -d '{}')\n\n    echo \"Test response: $response\"\nelse\n    echo \"✗ Deployment failed\"\n    exit 1\nfi\n```\n\n### Monitor Function Logs\n\n```bash\n# View function logs (requires Supabase CLI)\nsupabase functions logs my-function\n\n# Follow logs in real-time\nsupabase functions logs my-function --follow\n\n# Filter logs by level\nsupabase functions logs my-function --level error\n\n# View logs from specific time\nsupabase functions logs my-function --since 1h\n```\n\n## Advanced Patterns\n\n### Function with Database Access\n\n```typescript\n\u002F\u002F supabase\u002Ffunctions\u002Fget-user-data\u002Findex.ts\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\nimport { createClient } from 'https:\u002F\u002Fesm.sh\u002F@supabase\u002Fsupabase-js@2'\n\nserve(async (req) => {\n  const supabase = createClient(\n    Deno.env.get('SUPABASE_URL') ?? '',\n    Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''\n  )\n\n  const { userId } = await req.json()\n\n  const { data, error } = await supabase\n    .from('users')\n    .select('*')\n    .eq('id', userId)\n    .single()\n\n  if (error) {\n    return new Response(JSON.stringify({ error: error.message }), {\n      status: 400,\n      headers: { 'Content-Type': 'application\u002Fjson' }\n    })\n  }\n\n  return new Response(JSON.stringify(data), {\n    headers: { 'Content-Type': 'application\u002Fjson' }\n  })\n})\n```\n\n### Function with External API Call\n\n```typescript\n\u002F\u002F supabase\u002Ffunctions\u002Ffetch-weather\u002Findex.ts\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\n\nserve(async (req) => {\n  const { city } = await req.json()\n  const apiKey = Deno.env.get('WEATHER_API_KEY')\n\n  const response = await fetch(\n    `https:\u002F\u002Fapi.openweathermap.org\u002Fdata\u002F2.5\u002Fweather?q=${city}&appid=${apiKey}`\n  )\n\n  const data = await response.json()\n\n  return new Response(JSON.stringify(data), {\n    headers: { 'Content-Type': 'application\u002Fjson' }\n  })\n})\n```\n\n### Scheduled Function (Cron)\n\n```typescript\n\u002F\u002F supabase\u002Ffunctions\u002Fdaily-cleanup\u002Findex.ts\nimport { serve } from \"https:\u002F\u002Fdeno.land\u002Fstd@0.168.0\u002Fhttp\u002Fserver.ts\"\nimport { createClient } from 'https:\u002F\u002Fesm.sh\u002F@supabase\u002Fsupabase-js@2'\n\nserve(async (req) => {\n  \u002F\u002F Verify request is from Supabase Cron\n  const authHeader = req.headers.get('Authorization')\n  if (authHeader !== `Bearer ${Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')}`) {\n    return new Response('Unauthorized', { status: 401 })\n  }\n\n  const supabase = createClient(\n    Deno.env.get('SUPABASE_URL') ?? '',\n    Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? ''\n  )\n\n  \u002F\u002F Delete old records\n  const { data, error } = await supabase\n    .from('logs')\n    .delete()\n    .lt('created_at', new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString())\n\n  return new Response(JSON.stringify({ deleted: data?.length ?? 0 }), {\n    headers: { 'Content-Type': 'application\u002Fjson' }\n  })\n})\n```\n\n**Set up cron job in Supabase Dashboard:**\n```sql\n-- In SQL Editor, create pg_cron job:\nselect cron.schedule(\n  'daily-cleanup',\n  '0 2 * * *', -- Run at 2 AM daily\n  $$\n  select\n    net.http_post(\n      url := 'https:\u002F\u002Fyour-project.supabase.co\u002Ffunctions\u002Fv1\u002Fdaily-cleanup',\n      headers := '{\"Content-Type\": \"application\u002Fjson\", \"Authorization\": \"Bearer YOUR_SERVICE_ROLE_KEY\"}'::jsonb,\n      body := '{}'::jsonb\n    ) as request_id;\n  $$\n);\n```\n\n## Testing Functions\n\n### Test Locally\n\n```bash\n# Start local environment\nsupabase start\n\n# Serve function\nsupabase functions serve my-function\n\n# Test with curl\ncurl http:\u002F\u002Flocalhost:54321\u002Ffunctions\u002Fv1\u002Fmy-function \\\n  -H \"Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\" \\\n  -d '{\"test\": \"data\"}'\n```\n\n### Integration Test Script\n\n```bash\n#!\u002Fbin\u002Fbash\n# test-function.sh\n\nFUNCTION_NAME=\"$1\"\nTEST_CASES_FILE=\"$2\"\n\nif [[ ! -f \"$TEST_CASES_FILE\" ]]; then\n    echo \"Test cases file not found\"\n    exit 1\nfi\n\necho \"Testing function: $FUNCTION_NAME\"\n\nwhile IFS= read -r test_case; do\n    echo \"Test case: $test_case\"\n\n    response=$(curl -s -X POST \\\n        \"${SUPABASE_URL}\u002Ffunctions\u002Fv1\u002F${FUNCTION_NAME}\" \\\n        -H \"apikey: ${SUPABASE_KEY}\" \\\n        -H \"Content-Type: application\u002Fjson\" \\\n        -d \"$test_case\")\n\n    echo \"Response: $response\"\n    echo \"---\"\ndone \u003C \"$TEST_CASES_FILE\"\n```\n\n## Error Handling\n\n**Function errors return HTTP status codes:**\n\n| Status | Meaning |\n|--------|---------|\n| 200 | Success |\n| 400 | Bad request (invalid input) |\n| 401 | Unauthorized (invalid\u002Fmissing auth) |\n| 403 | Forbidden (insufficient permissions) |\n| 500 | Internal server error (function crashed) |\n| 504 | Gateway timeout (function took too long) |\n\n**Timeout limit:** Edge functions have a 2-second CPU time limit and 150-second wall clock timeout.\n\n## Security Best Practices\n\n1. **Validate input**: Always validate and sanitize request data\n2. **Use service role key carefully**: Only in admin functions, never expose to clients\n3. **Implement authentication**: Check user tokens for protected functions\n4. **Rate limiting**: Implement rate limiting for public functions\n5. **Environment variables**: Store secrets in Supabase secrets, not in code\n6. **CORS**: Configure CORS headers appropriately\n7. **Error messages**: Don't leak sensitive information in error responses\n\n## Performance Tips\n\n1. **Cold starts**: Functions may have cold starts (100-200ms delay)\n2. **Keep functions small**: Faster cold starts and easier debugging\n3. **Cache external data**: Use in-memory caching for repeated API calls\n4. **Parallel execution**: Use `Promise.all()` for concurrent operations\n5. **Stream large responses**: Use streaming for large data transfers\n\n## API Documentation\n\n- Supabase Edge Functions: https:\u002F\u002Fsupabase.com\u002Fdocs\u002Fguides\u002Ffunctions\n- Deno Deploy: https:\u002F\u002Fdeno.com\u002Fdeploy\u002Fdocs\n",{"name":5,"description":7},"main","f2ec4b3b9133d34eeaf9b38e4b0a97e8e5705a7f","benchmarks\u002Ffinal\u002Fskills\u002Fasset1__Nice-Wolf-Studio--supabase-edge-functions",0,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard","https:\u002F\u002Fgithub.com\u002FJSGforever","2026-08-29 18:27:56",{"source":8,"skillName":5,"commands":43,"prompt":53,"zipAvailable":54},[44,47,50],{"tool":45,"command":46},"npx","npx skills add JSGforever\u002Fskillguard --skill supabase-edge-functions",{"tool":48,"command":49},"bunx","bunx skills add JSGforever\u002Fskillguard --skill supabase-edge-functions",{"tool":51,"command":52},"pnpm","pnpm dlx skills add JSGforever\u002Fskillguard --skill supabase-edge-functions","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__Nice-Wolf-Studio--supabase-edge-functions\u002FSKILL.md",true,[],[57,84,95,122,141,161],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":30},"01M71HY2SNXBA9Q00WZDTZQ31Z","skillguard-codex-scanner","Hybrid deterministic+LLM agent-skill security scanner. Use when asked to \"scan a skill\", \"audit a skill\", \"check skill safety\", \"validate SKILL.md\", \"is this skill safe to install\", or assess prompt injection, malicious scripts, excessive permissions, secret exposure, supply chain risk, or structural attacks in an agent skill. Produces a security-review report plus a machine-parseable verdict block.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fsrc\u002Fskillguard\u002Fstatic_scanner\u002Fskillguard-codex-scanner\u002FSKILL.md",[],[64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83],"scanner","skillguard codex scanner","skillguard","codex","chain","skill security","security-review","review report","structural","secret","prompt injection","security scanner","when","review","malicious","permissions","exposure","audit","scripts","safe",{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":88,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":30},"01M71HY0SPKTT3S27BC2HPAC5M","data-exfiltrator","Analyzes data files","MIT","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Fsmoke-one-skill\u002Fasset1__cisco-ai-defense--data-exfiltrator\u002FSKILL.md",[],[92,93,94],"data","data exfiltrator","files",{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":30},"01M71HXVS9EMN44BGDW215FZ72","real-time-collaboration-engine","Build real-time collaborative editing with WebSockets, OT\u002FCRDT conflict resolution, and presence awareness. Implements cursor tracking, optimistic updates, and offline sync. Use for collaborative editors, whiteboards, video editing. Activate on \"real-time collaboration\", \"WebSocket sync\", \"multiplayer editing\", \"CRDT\", \"presence awareness\". NOT for simple chat, request-response APIs, or single-user apps.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--real-time-collaboration-engine\u002FSKILL.md",[],[102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121],"time","real time collaboration engine","real time collaboration","collaboration","engine","real time","Video","reliability","video editing","performance","conflict resolution","presence","access","apps","updates","Bash","activate","optimizer","react","streaming",{"skillNo":123,"name":124,"nameZh":6,"description":125,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":126,"categories":127,"keywords":128,"publishedAt":30},"01M71HXP6CTY4KFN0QVMMN0V7J","react-performance-optimizer","Optimize React apps for 60fps performance. Implements memoization, virtualization, code splitting, bundle optimization. Use for slow renders, large lists, bundle bloat. Activate on \"React performance\", \"slow render\", \"useMemo\", \"bundle size\", \"virtualization\". NOT for backend optimization, non-React frameworks, or premature optimization.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--react-performance-optimizer\u002FSKILL.md",[],[111,129,119,120,130,131,132,133,134,135,102,136,137,115,117,138,118,121,139,140],"react performance optimizer","react performance","performance optimizer","app","nextjs","expert","re","render","2025","code","router","strategies",{"skillNo":142,"name":143,"nameZh":6,"description":144,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":145,"categories":146,"keywords":147,"publishedAt":30},"01M71HXH7QXSQB4QTDZ7SP7YXQ","llm-streaming-response-handler","Build production LLM streaming UIs with Server-Sent Events, real-time token display, cancellation, error recovery. Handles OpenAI\u002FAnthropic\u002FClaude streaming APIs. Use for chatbots, AI assistants, real-time text generation. Activate on \"LLM streaming\", \"SSE\", \"token stream\", \"chat UI\", \"real-time AI\". NOT for batch processing, non-streaming APIs, or WebSocket bidirectional chat.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--llm-streaming-response-handler\u002FSKILL.md",[],[148,121,149,150,151,152,111,102,153,154,155,117,118,119,156,120,157,158,159,160],"llm streaming response handler","handler","error","processing","retry","chat ui","error recovery","critical","batch","display","text","server","read",{"skillNo":162,"name":163,"nameZh":6,"description":164,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":165,"categories":166,"keywords":167,"publishedAt":30},"01M71HXCB0E1YRKYW1Y8T0Y106","github-actions-pipeline-builder","Build production CI\u002FCD pipelines with GitHub Actions. Implements matrix builds, caching, deployments, testing, security scanning. Use for automated testing, deployments, release workflows. Activate on \"GitHub Actions\", \"CI\u002FCD\", \"workflow\", \"deployment pipeline\", \"automated testing\". NOT for Jenkins\u002FCircleCI, manual deployments, or non-GitHub repositories.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--github-actions-pipeline-builder\u002FSKILL.md",[],[168,169,170,171,172,173,174,109,134,175,176,177,118,140,178,160,179,180,181,182],"github actions pipeline builder","actions","github actions","pipeline builder","github","builder","pipeline","testing","ci","workflows","run","release","write","edit","git"]