Deploy and manage serverless JavaScript functions on Cloudflare Workers or Supabase Functions.

Commands

kapso functions push <file.js>

Upload or update a function. Creates new functions or updates existing ones based on filename.
# Deploy to Cloudflare Workers (default)
kapso functions push process-webhook.js

# Deploy to Supabase Functions
kapso functions push database-handler.js --platform supabase

# Use custom name
kapso functions push utils/helper.js --name my-helper

# Short form
kapso functions push worker.js -p cloudflare -n webhook-processor

Options

  • --name, -n <name> - Custom function name (defaults to filename)
  • --platform, -p <platform> - Deployment platform: cloudflare or supabase (defaults to cloudflare)

Platform Requirements

  • Cloudflare Workers: No additional setup required
  • Supabase Functions: Requires Supabase integration in your project

kapso functions list

List all functions with their deployment status and platform information.
kapso functions list

Output Format

NAME              PLATFORM     STATUS     UPDATED      INVOKE URL
process-webhook   Cloudflare   deployed   2 min ago    https://app.kapso.ai/api/v1/functions/abc123/invoke
database-handler  Supabase     deployed   1 hour ago   https://app.kapso.ai/api/v1/functions/def456/invoke
my-helper         Cloudflare   draft      3 days ago   -

kapso functions pull <name>

Download function code from Kapso to your local machine.
# Download to functions directory
kapso functions pull process-webhook

# Download to specific location
kapso functions pull database-handler --output my-functions/db.js

# Short form
kapso functions pull my-helper -o helper.js

Options

  • --output, -o <path> - Output file path (defaults to functions/<name>.js)

Authentication

Functions commands require authentication via API key:
# Set API key environment variable
export KAPSO_API_KEY=your-api-key

# Or login with kapso CLI
kapso login

Function Code Format

Cloudflare Workers

async function handler(request, env) {
  // Access secrets via env parameter
  const apiKey = env.API_KEY;
  
  // Parse request body
  const body = await request.json();
  
  // Return JSON response
  return new Response(JSON.stringify({
    message: "Hello from Cloudflare Worker!",
    data: body
  }), {
    headers: { 'Content-Type': 'application/json' }
  });
}

Supabase Functions

Deno.serve(async (req) => {
  // Access secrets via Deno.env.get()
  const apiKey = Deno.env.get('API_KEY');
  
  // Initialize Supabase client
  const supabaseClient = createClient(
    Deno.env.get('SUPABASE_URL'),
    Deno.env.get('SUPABASE_ANON_KEY')
  );
  
  // Parse request body
  const body = await req.json().catch(() => ({}));
  
  // Return JSON response
  return new Response(JSON.stringify({
    message: "Hello from Supabase Function!",
    data: body
  }), {
    headers: { 'Content-Type': 'application/json' }
  });
});

Best Practices

  1. Use descriptive filenames - Function names derive from filenames
  2. Handle errors gracefully - Always wrap logic in try/catch blocks
  3. Validate input - Check request format before processing
  4. Return appropriate status codes - Use 200, 400, 404, 500 as needed
  5. Keep functions focused - One function, one responsibility
  6. Use secrets for sensitive data - Never hardcode API keys or passwords

Examples

Deploy a webhook processor

# Create webhook function
echo 'async function handler(request, env) {
  const webhook = await request.json();
  
  // Process webhook data
  console.log("Received webhook:", webhook);
  
  // Forward to external service
  await fetch(env.CRM_WEBHOOK_URL, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(webhook)
  });
  
  return new Response("OK");
}' > webhook-processor.js

# Deploy to Cloudflare Workers
kapso functions push webhook-processor.js

Deploy a database function

# Create database function
echo 'Deno.serve(async (req) => {
  const supabase = createClient(
    Deno.env.get("SUPABASE_URL"),
    Deno.env.get("SUPABASE_ANON_KEY")
  );
  
  const { data, error } = await supabase
    .from("users")
    .select("*")
    .limit(10);
  
  if (error) throw error;
  
  return new Response(JSON.stringify(data), {
    headers: { "Content-Type": "application/json" }
  });
});' > user-list.js

# Deploy to Supabase Functions
kapso functions push user-list.js --platform supabase

Notes

  • Functions are deployed asynchronously - deployment happens in the background
  • Function names must be unique within a project
  • Both platforms support environment variables via the web dashboard
  • Deployment requires valid API credentials for the chosen platform