| 64 | } |
| 65 | |
| 66 | function normalizeEmailBisonBaseUrl(baseUrl: string): string { |
| 67 | const trimmedBaseUrl = baseUrl.trim() |
| 68 | if (!trimmedBaseUrl) { |
| 69 | throw new Error('Email Bison Instance URL is required') |
| 70 | } |
| 71 | |
| 72 | const rawBaseUrl = /^https?:\/\//i.test(trimmedBaseUrl) |
| 73 | ? trimmedBaseUrl |
| 74 | : `https://${trimmedBaseUrl}` |
| 75 | const parsed = new URL(rawBaseUrl) |
| 76 | |
| 77 | if (parsed.protocol !== 'https:') { |
| 78 | throw new Error('Email Bison Instance URL must use HTTPS') |
| 79 | } |
| 80 | |
| 81 | return parsed.origin |
| 82 | } |
| 83 | |
| 84 | export function jsonBody(fields: Record<string, unknown>): Record<string, unknown> { |
| 85 | return filterUndefined(fields) |