| 79 | |
| 80 | // Get function code from database |
| 81 | async function getFunctionCode(slug: string): Promise<string | null> { |
| 82 | const client = new Client(dbConfig); |
| 83 | |
| 84 | try { |
| 85 | await client.connect(); |
| 86 | |
| 87 | const result = await client.queryObject<{ code: string }>` |
| 88 | SELECT code FROM functions.definitions |
| 89 | WHERE slug = ${slug} AND status = 'active' |
| 90 | `; |
| 91 | |
| 92 | if (!result.rows.length) { |
| 93 | return null; |
| 94 | } |
| 95 | |
| 96 | return result.rows[0].code; |
| 97 | } catch (error) { |
| 98 | console.error(`Error fetching function ${slug}:`, error); |
| 99 | return null; |
| 100 | } finally { |
| 101 | await client.end(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | // Get all secrets from main secrets table and decrypt them |
| 106 | async function getFunctionSecrets(): Promise<Record<string, string>> { |