( webhookId: string, configUpdates: Record<string, unknown>, logger: Logger )
| 157 | * the `json` column. |
| 158 | */ |
| 159 | export async function updateWebhookProviderConfig( |
| 160 | webhookId: string, |
| 161 | configUpdates: Record<string, unknown>, |
| 162 | logger: Logger |
| 163 | ): Promise<void> { |
| 164 | try { |
| 165 | const defined: Record<string, unknown> = {} |
| 166 | const removedKeys: string[] = [] |
| 167 | for (const [key, value] of Object.entries(configUpdates)) { |
| 168 | if (value === undefined) removedKeys.push(key) |
| 169 | else defined[key] = value |
| 170 | } |
| 171 | |
| 172 | const merged = sql`COALESCE(${webhook.providerConfig}::jsonb, '{}'::jsonb) || ${JSON.stringify(defined)}::jsonb` |
| 173 | const nextConfig = removedKeys.length > 0 ? sql`(${merged}) - ${removedKeys}::text[]` : merged |
| 174 | |
| 175 | await db |
| 176 | .update(webhook) |
| 177 | .set({ |
| 178 | providerConfig: sql`(${nextConfig})::json`, |
| 179 | updatedAt: new Date(), |
| 180 | }) |
| 181 | .where(eq(webhook.id, webhookId)) |
| 182 | } catch (err) { |
| 183 | logger.error(`Failed to update webhook ${webhookId} config:`, err) |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Resolve OAuth credentials for a webhook. Shared by Gmail and Outlook. |
no test coverage detected