From a1ba5f342b2f5d9e3ee75fb3ca69bf9fa008d1bd Mon Sep 17 00:00:00 2001 From: dwindown Date: Sun, 11 Jan 2026 22:29:17 +0700 Subject: [PATCH] Add Deno script to trigger calendar cleanup without curl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created a Deno script that uses the built-in fetch() API to trigger the cancel-expired-consulting-orders edge function, replacing the need for curl in Coolify scheduled tasks. This script: - Uses Deno.env.get() for environment variables (like Supabase functions) - Uses Deno's native fetch() API (no external dependencies) - Runs with --allow-net and --allow-env permissions - Can be used in Coolify scheduled tasks: deno run scripts/trigger-calendar-cleanup.js Usage in Coolify scheduled task command: deno run --allow-net --allow-env /app/scripts/trigger-calendar-cleanup.js 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- scripts/trigger-calendar-cleanup.js | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/trigger-calendar-cleanup.js diff --git a/scripts/trigger-calendar-cleanup.js b/scripts/trigger-calendar-cleanup.js new file mode 100644 index 0000000..210346d --- /dev/null +++ b/scripts/trigger-calendar-cleanup.js @@ -0,0 +1,40 @@ +#!/usr/bin/env -S deno run --allow-net --allow-env + +/** + * Script to trigger the cancel-expired-consulting-orders edge function + * Usage: deno run --allow-net --allow-env scripts/trigger-calendar-cleanup.js + * This script is designed to be used in Coolify scheduled tasks + * + * This uses Deno's built-in fetch() API, just like the Supabase edge functions. + */ + +const SUPABASE_URL = Deno.env.get("SUPABASE_URL") || "http://supabase-edge-functions:8000"; +const FUNCTION_PATH = "/functions/v1/cancel-expired-consulting-orders"; +const ANON_KEY = Deno.env.get("SUPABASE_ANON_KEY") || ""; + +async function triggerCleanup() { + const url = `${SUPABASE_URL}${FUNCTION_PATH}`; + + try { + const response = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${ANON_KEY}`, + }, + }); + + if (!response.ok) { + throw new Error(`HTTP ${response.status}: ${response.statusText}`); + } + + const result = await response.json(); + console.log(JSON.stringify(result)); + Deno.exit(0); + } catch (error) { + console.error("Error triggering calendar cleanup:", error.message); + Deno.exit(1); + } +} + +await triggerCleanup();