update-remaining-functions.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # List of functions to update
  3. FUNCTIONS=(
  4. "oauth-shoprenter-callback"
  5. "webhooks-shopify"
  6. "webhook-shoprenter-uninstall"
  7. "shopify-sync"
  8. "woocommerce-sync"
  9. "shoprenter-sync"
  10. "trigger-sync"
  11. "shoprenter-scheduled-sync"
  12. "woocommerce-scheduled-sync"
  13. "shoprenter-products"
  14. "shoprenter-orders"
  15. "shoprenter-customers"
  16. "get-ai-context"
  17. )
  18. cd /home/claude/shopcall/supabase/functions
  19. for func in "${FUNCTIONS[@]}"; do
  20. FILE="$func/index.ts"
  21. if [ -f "$FILE" ]; then
  22. echo "Updating $FILE..."
  23. # Check if already has error-handler import
  24. if grep -q "from '../_shared/error-handler.ts'" "$FILE"; then
  25. echo " - Already has error handler import, skipping"
  26. continue
  27. fi
  28. # Add import at the top (after existing imports)
  29. sed -i '/^import.*from.*supabase-js/a\import { wrapHandler, logError } from '\''../_shared/error-handler.ts'\''' "$FILE"
  30. # Replace serve(async (req) => { with serve(wrapHandler('function-name', async (req) => {
  31. sed -i "s/serve(async (req) => {/serve(wrapHandler('$func', async (req) => {/" "$FILE"
  32. # Remove the outer try-catch block
  33. # This is complex, so we'll do a simple approach: remove lines with ' } catch (error) {' at the end
  34. # and the corresponding closing })
  35. echo " - Updated $FILE"
  36. else
  37. echo "File not found: $FILE"
  38. fi
  39. done
  40. echo "Done!"